'Creates a key, ssh or password, for server or console
The group for the key (key_group) is 1 for Server and 4 for Console
Returns the id of the created key'

def ex_create_keypair(self, name, public_key=None, password=None, key_group=None):

    if public_key:
        if (not key_group):
            key_group = 1
        data = {'name': name, 'public_key': public_key, 'key_group': key_group}
        params = urlencode(data)
        result = self.connection.request('/key/sshrsa/', data=params, method='POST').object
    else:
        if (not key_group):
            key_group = 4
        if (not password):
            password = self.random_password()
            data = {'name': name, 'password': password, 'key_group': key_group}
        params = urlencode(data)
        result = self.connection.request('/key/password/', data=params, method='POST').object
    return result.get('data', {}).get('id', '')
