Merge branch 'develop' into boto_apigateway

This commit is contained in:
Kris Raney 2016-01-29 11:08:32 -06:00
commit e433f15875
5 changed files with 43 additions and 26 deletions

View File

@ -107,6 +107,8 @@ VALID_RESPONSE_CODES = [
http_client.NO_CONTENT
]
DEFAULT_NETWORKS = ['Joyent-SDC-Public']
# Only load in this module if the Joyent configurations are in place
def __virtual__():
@ -281,6 +283,7 @@ def create(vm_):
salt.utils.cloud.check_name(vm_['name'], 'a-zA-Z0-9-.')
kwargs = {
'name': vm_['name'],
'networks': vm_.get('networks', DEFAULT_NETWORKS),
'image': get_image(vm_),
'size': get_size(vm_),
'location': vm_.get('location', DEFAULT_LOCATION)
@ -340,11 +343,13 @@ def create_node(**kwargs):
size = kwargs['size']
image = kwargs['image']
location = kwargs['location']
networks = kwargs['networks']
data = json.dumps({
'name': name,
'package': size['name'],
'image': image['name']
'image': image['name'],
'networks': networks
})
try:

View File

@ -428,7 +428,9 @@ def add_tags(Name,
if str(k).startswith('__'):
continue
tagslist.append({'Key': str(k), 'Value': str(v)})
conn.add_tags(ResourceId=_get_trail_arn(Name), TagsList=tagslist)
conn.add_tags(ResourceId=_get_trail_arn(Name,
region=region, key=key, keyid=keyid,
profile=profile), TagsList=tagslist)
return {'tagged': True}
except ClientError as e:
return {'tagged': False, 'error': salt.utils.boto3.get_error(e)}
@ -457,7 +459,9 @@ def remove_tags(Name,
if str(k).startswith('__'):
continue
tagslist.append({'Key': str(k), 'Value': str(v)})
conn.remove_tags(ResourceId=_get_trail_arn(Name), TagsList=tagslist)
conn.remove_tags(ResourceId=_get_trail_arn(Name,
region=region, key=key, keyid=keyid,
profile=profile), TagsList=tagslist)
return {'tagged': True}
except ClientError as e:
return {'tagged': False, 'error': salt.utils.boto3.get_error(e)}
@ -483,7 +487,9 @@ def list_tags(Name,
try:
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
rid = _get_trail_arn(Name)
rid = _get_trail_arn(Name,
region=region, key=key, keyid=keyid,
profile=profile)
ret = conn.list_tags(ResourceIdList=[rid])
tlist = ret.get('ResourceTagList', []).pop().get('TagsList')
tagdict = {}

View File

@ -122,30 +122,20 @@ def _validate_enabled(enabled):
'''
Helper function to validate the enabled parameter. Boolean values are
converted to "on" and "off". String values are checked to make sure they are
either "on" or "off". All other values return an error.
either "on" or "off". Int 1+ and 0 are converted to "on" and "off"
Returns: "on" or "off" or errors
'''
if isinstance(enabled, bool):
if enabled:
return 'on'
else:
return 'off'
elif isinstance(enabled, int):
if enabled in [1, 0]:
if enabled == 1:
return 'on'
else:
return 'off'
else:
msg = '\nMac Power: Invalid Integer Value for Enabled.\n' \
'Integer values must be 1 or 0.\n' \
if isinstance(enabled, str):
if enabled.lower() not in ['on', 'off']:
msg = '\nMac Power: Invalid String Value for Enabled.\n' \
'String values must be \'on\' or \'off\'.\n' \
'Passed: {0}'.format(enabled)
raise SaltInvocationError(msg)
else:
msg = '\nMac Power: Unknown Variable Type Passed for Enabled.\n' \
'Passed: {0}'.format(enabled)
raise SaltInvocationError(msg)
return enabled.lower()
return 'on' if bool(enabled) else 'off'
def get_sleep():

View File

@ -289,7 +289,7 @@ def reboot(vm, force=False, key='uuid'):
return True
def list_vms(search=None, sort=None, order='uuid,type,ram,state,alias', keyed=False):
def list_vms(search=None, sort=None, order='uuid,type,ram,state,alias', keyed=True):
'''
Return a list of VMs

View File

@ -185,6 +185,11 @@ def present(name, Name,
if LoggingEnabled:
r = __salt__['boto_cloudtrail.start_logging'](Name=Name,
region=region, key=key, keyid=keyid, profile=profile)
if 'error' in r:
ret['result'] = False
ret['comment'] = 'Failed to create trail: {0}.'.format(r['error']['message'])
ret['changes'] = {}
return ret
ret['changes']['new']['trail']['LoggingEnabled'] = True
else:
ret['changes']['new']['trail']['LoggingEnabled'] = False
@ -192,6 +197,11 @@ def present(name, Name,
if bool(Tags):
r = __salt__['boto_cloudtrail.add_tags'](Name=Name,
region=region, key=key, keyid=keyid, profile=profile, **Tags)
if not r.get('tagged'):
ret['result'] = False
ret['comment'] = 'Failed to create trail: {0}.'.format(r['error']['message'])
ret['changes'] = {}
return ret
ret['changes']['new']['trail']['Tags'] = Tags
return ret
@ -199,7 +209,13 @@ def present(name, Name,
ret['changes'] = {}
# trail exists, ensure config matches
_describe = __salt__['boto_cloudtrail.describe'](Name=Name,
region=region, key=key, keyid=keyid, profile=profile)['trail']
region=region, key=key, keyid=keyid, profile=profile)
if 'error' in _describe:
ret['result'] = False
ret['comment'] = 'Failed to update trail: {0}.'.format(r['error']['message'])
ret['changes'] = {}
return ret
_describe = _describe.get('trail')
r = __salt__['boto_cloudtrail.status'](Name=Name,
region=region, key=key, keyid=keyid, profile=profile)
@ -280,7 +296,7 @@ def present(name, Name,
# there's an update for this key
adds[k] = Tags[k]
elif diff.get('old', '') != '':
removes[k] = _describe[k]
removes[k] = _describe['Tags'][k]
if bool(adds):
r = __salt__['boto_cloudtrail.add_tags'](Name=Name,
region=region, key=key, keyid=keyid, profile=profile, **adds)