Merge pull request #37756 from wise0wl/develop

Added all input variables for Joyent CreateMachine API call, fixed an…
This commit is contained in:
Mike Place 2017-01-06 11:09:56 -07:00 committed by GitHub
commit 3f55af9dba

View File

@ -336,6 +336,10 @@ def create_node(**kwargs):
image = kwargs['image']
location = kwargs['location']
networks = kwargs.get('networks')
tag = kwargs.get('tag')
locality = kwargs.get('locality')
metadata = kwargs.get('metadata')
firewall_enabled = kwargs.get('firewall_enabled')
create_data = {
'name': name,
@ -344,6 +348,21 @@ def create_node(**kwargs):
}
if networks is not None:
create_data['networks'] = networks
if locality is not None:
create_data['locality'] = locality
if metadata is not None:
for key, value in metadata.iteritems():
create_data['metadata.{0}'.format(key)] = value
if tag is not None:
for key, value in tag.iteritems():
create_data['tag.{0}'.format(key)] = value
if firewall_enabled is not None:
create_data['firewall_enabled'] = firewall_enabled
data = json.dumps(create_data)
ret = query(command='/my/machines', data=data, method='POST',
@ -726,11 +745,14 @@ def list_nodes(full=False, call=None):
for location in JOYENT_LOCATIONS:
result = query(command='my/machines', location=location,
method='GET')
nodes = result[1]
for node in nodes:
if 'name' in node:
node['location'] = location
ret[node['name']] = reformat_node(item=node, full=full)
if result[0] in VALID_RESPONSE_CODES:
nodes = result[1]
for node in nodes:
if 'name' in node:
node['location'] = location
ret[node['name']] = reformat_node(item=node, full=full)
else:
log.error('Invalid response when listing Joyent nodes: {0}'.format(result[1]))
else:
result = query(command='my/machines', location=DEFAULT_LOCATION,
@ -1002,6 +1024,9 @@ def query(action=None,
'user', get_configured_provider(), __opts__, search_global=False
)
if not user:
log.error('username is required for Joyent API requests. Please set one in your provider configuration')
password = config.get_cloud_config_value(
'password', get_configured_provider(), __opts__,
search_global=False
@ -1017,11 +1042,17 @@ def query(action=None,
search_global=False, default=True
)
if not ssh_keyfile:
log.error('ssh_keyfile is required for Joyent API requests. Please set one in your provider configuration')
ssh_keyname = config.get_cloud_config_value(
'keyname', get_configured_provider(), __opts__,
search_global=False, default=True
)
if not ssh_keyname:
log.error('ssh_keyname is required for Joyent API requests. Please set one in your provider configuration')
if not location:
location = get_location()
@ -1040,6 +1071,9 @@ def query(action=None,
log.debug('User: \'{0}\' on PATH: {1}'.format(user, path))
if (not user) or (not ssh_keyfile) or (not ssh_keyname) or (not location):
return None
timenow = datetime.datetime.utcnow()
timestamp = timenow.strftime('%a, %d %b %Y %H:%M:%S %Z').strip()
with salt.utils.fopen(ssh_keyfile, 'r') as kh_:
@ -1048,7 +1082,7 @@ def query(action=None,
hash_ = SHA256.new()
hash_.update(timestamp)
signed = base64.b64encode(rsa_.sign(hash_))
keyid = '/{0}/keys/{1}'.format(user, ssh_keyname)
keyid = '/{0}/keys/{1}'.format(user.split('/')[0], ssh_keyname)
headers = {
'Content-Type': 'application/json',