def create_attach_volumes(name, kwargs, call=None, wait_to_finish=True):
 if (call != 'action'):
  raise SaltCloudSystemExit('The create_attach_volumes action must be called with -a or --action.')
 if (kwargs is None):
  kwargs = {}
 if isinstance(kwargs['volumes'], str):
  volumes = yaml.safe_load(kwargs['volumes'])
 else:
  volumes = kwargs['volumes']
 conn = get_conn()
 ret = []
 for volume in volumes:
  if ('disk_name' in volume):
   log.error('You cannot specify a disk_name. Only new volumes are allowed')
   return False
  volume.setdefault('logical_disk_size_in_gb', volume.get('size', 100))
  volume.setdefault('host_caching', 'ReadOnly')
  volume.setdefault('lun', 0)
  volume.setdefault('media_link', (kwargs['media_link'][:(-4)] + '-disk-{0}.vhd'.format(volume['lun'])))
  volume.setdefault('disk_label', (kwargs['role_name'] + '-disk-{0}'.format(volume['lun'])))
  volume_dict = {'volume_name': volume['lun'], 'disk_label': volume['disk_label']}
  kwargs_add_data_disk = ['lun', 'host_caching', 'media_link', 'disk_label', 'disk_name', 'logical_disk_size_in_gb', 'source_media_link']
  for key in (set(volume.keys()) - set(kwargs_add_data_disk)):
   del volume[key]
  attach = conn.add_data_disk(kwargs['service_name'], kwargs['deployment_name'], kwargs['role_name'], **volume)
  log.debug(attach)
  if attach:
   msg = '{0} attached to {1} (aka {2})'.format(volume_dict['volume_name'], kwargs['role_name'], name)
   log.info(msg)
   ret.append(msg)
  else:
   log.error('Error attaching {0} on Azure'.format(volume_dict))
 return ret

def create_attach_volumes ( name , kwargs , call = None , wait_to_finish = True ) : if ( call != 'action' ) : raise SaltCloudSystemExit ( 'The create_attach_volumes action must be called with -a or --action.' ) if ( kwargs is None ) : kwargs = { } if isinstance ( kwargs [ 'volumes' ] , str ) : volumes = yaml . safe_load ( kwargs [ 'volumes' ] ) else : volumes = kwargs [ 'volumes' ] conn = get_conn ( ) ret = [ ] for volume in volumes : if ( 'disk_name' in volume ) : log . error ( 'You cannot specify a disk_name. Only new volumes are allowed' ) return False volume . setdefault ( 'logical_disk_size_in_gb' , volume . get ( 'size' , 100 ) ) volume . setdefault ( 'host_caching' , 'ReadOnly' ) volume . setdefault ( 'lun' , 0 ) volume . setdefault ( 'media_link' , ( kwargs [ 'media_link' ] [ : ( - 4 ) ] + '-disk-{0}.vhd' . format ( volume [ 'lun' ] ) ) ) volume . setdefault ( 'disk_label' , ( kwargs [ 'role_name' ] + '-disk-{0}' . format ( volume [ 'lun' ] ) ) ) volume_dict = { 'volume_name' : volume [ 'lun' ] , 'disk_label' : volume [ 'disk_label' ] } kwargs_add_data_disk = [ 'lun' , 'host_caching' , 'media_link' , 'disk_label' , 'disk_name' , 'logical_disk_size_in_gb' , 'source_media_link' ] for key in ( set ( volume . keys ( ) ) - set ( kwargs_add_data_disk ) ) : del volume [ key ] attach = conn . add_data_disk ( kwargs [ 'service_name' ] , kwargs [ 'deployment_name' ] , kwargs [ 'role_name' ] , ** volume ) log . debug ( attach ) if attach : msg = '{0} attached to {1} (aka {2})' . format ( volume_dict [ 'volume_name' ] , kwargs [ 'role_name' ] , name ) log . info ( msg ) ret . append ( msg ) else : log . error ( 'Error attaching {0} on Azure' . format ( volume_dict ) ) return ret
create and attach multiple volumes to a node .