Return all EC2 Volume objects attached to ``arg`` instance name or ID.

        May specify ``device`` to limit to the (single) volume attached as that
        device.
327802
def get_volumes_for_instance(self, arg, device=None):
        
        instance = self.get(arg)
        filters = {'attachment.instance-id': instance.id}
        if device is not None:
            filters['attachment.device'] = device
        return self.get_all_volumes(filters=filters)
900219
def volume_attached(name, server_name, provider=None, **kwargs):
    '''
    
    '''
    ret = _check_name(name)
    if not ret['result']:
        return ret

    ret = _check_name(server_name)
    if not ret['result']:
        return ret

    volumes = __salt__['cloud.volume_list'](provider=provider)
    instance = __salt__['cloud.action'](
        fun='show_instance',
        names=server_name
    )

    if name in volumes and volumes[name]['attachments']:
        volume = volumes[name]
        ret['comment'] = (
            'Volume {name} is already attached: {attachments}'.format(
                **volumes[name]
            )
        )
        ret['result'] = True
        return ret
    elif name not in volumes:
        ret['comment'] = 'Volume {0} does not exist'.format(name)
        ret['result'] = False
        return ret
    elif not instance:
        ret['comment'] = 'Server {0} does not exist'.format(server_name)
        ret['result'] = False
        return ret
    elif __opts__['test']:
        ret['comment'] = 'Volume {0} will be will be attached.'.format(
            name
        )
        ret['result'] = None
        return ret

    response = __salt__['cloud.volume_attach'](
        provider=provider,
        names=name,
        server_name=server_name,
        **kwargs
    )
    if response:
        ret['result'] = True
        ret['comment'] = 'Volume {0} was created'.format(name)
        ret['changes'] = {'old': volumes[name], 'new': response}
    else:
        ret['result'] = False
        ret['comment'] = 'Volume {0} failed to attach.'.format(name)
    return ret
1360842
def get_volumes_for_sdc(self, sdcObj):
        
        self.conn.connection._check_login()
        all_volumes = []
        response = self.conn.connection._do_get("{}/{}{}/{}".format(self.conn.connection._api_url, 'instances/Sdc::', sdcObj.id, 'relationships/Volume')).json()
        for sdc_volume in response:
            all_volumes.append(
                Volume.from_dict(sdc_volume)
            )
        return all_volumes
382304
def get_volumes_for_container(self, container_id, skip_empty_source=True):
        
        logger.info("listing volumes for container '%s'", container_id)
        inspect_output = self.d.inspect_container(container_id)
        volumes = inspect_output['Mounts'] or []
        volume_names = [x['Name'] for x in volumes]

        if skip_empty_source:
            # Don't show volumes which are not on the filesystem
            volume_names = [x['Name'] for x in volumes if x['Source'] != ""]

        logger.debug("volumes = %s", volume_names)
        return volume_names
1100895
public Map<String, List<CloudVolumeStorage>> getCloudVolumes(Map<String, String> instanceToAccountMap) {
        Map<String, List<CloudVolumeStorage>> returnMap = new HashMap<>();
        DescribeVolumesResult volumeResult = ec2Client.describeVolumes();
        for (Volume v : volumeResult.getVolumes()) {
            CloudVolumeStorage object = new CloudVolumeStorage();
            for (VolumeAttachment va : v.getAttachments()) {
                object.getAttachInstances().add(va.getInstanceId());
            }
            String account = NO_ACCOUNT;
            //Get any instance id if any and get corresponding account number
            if (!CollectionUtils.isEmpty(object.getAttachInstances()) &&
                    !StringUtils.isEmpty(instanceToAccountMap.get(object.getAttachInstances().get(0)))) {
                account = instanceToAccountMap.get(object.getAttachInstances().get(0));
            }
            object.setAccountNumber(account);
            object.setZone(v.getAvailabilityZone());
            object.setAccountNumber(account);
            object.setCreationDate(v.getCreateTime().getTime());
            object.setEncrypted(v.isEncrypted());
            object.setSize(v.getSize());
            object.setStatus(v.getState());
            object.setType(v.getVolumeType());
            object.setVolumeId(v.getVolumeId());
            List<Tag> tags = v.getTags();
            if (!CollectionUtils.isEmpty(tags)) {
                for (Tag tag : tags) {
                    NameValue nv = new NameValue(tag.getKey(), tag.getValue());
                    object.getTags().add(nv);
                }
            }
            if (CollectionUtils.isEmpty(returnMap.get(object.getAccountNumber()))) {
                List<CloudVolumeStorage> temp = new ArrayList<>();
                temp.add(object);
                returnMap.put(account, temp);
            } else {
                returnMap.get(account).add(object);
            }
        }
        return returnMap;
    }
1068125
def volume_create_attach(name, call=None, **kwargs):
    '''
    
    '''
    if call == 'function':
        raise SaltCloudSystemExit(
            'The create_attach_volumes action must be called with '
            '-a or --action.'
        )

    if type(kwargs['volumes']) is str:
        volumes = salt.utils.yaml.safe_load(kwargs['volumes'])
    else:
        volumes = kwargs['volumes']

    ret = []
    for volume in volumes:
        created = False

        volume_dict = {
            'name': volume['name'],
        }
        if 'volume_id' in volume:
            volume_dict['volume_id'] = volume['volume_id']
        elif 'snapshot' in volume:
            volume_dict['snapshot'] = volume['snapshot']
        else:
            volume_dict['size'] = volume['size']

            if 'type' in volume:
                volume_dict['type'] = volume['type']
            if 'iops' in volume:
                volume_dict['iops'] = volume['iops']

        if 'id' not in volume_dict:
            created_volume = create_volume(**volume_dict)
            created = True
            volume_dict.update(created_volume)

        attach = attach_volume(
            name=volume['name'],
            server_name=name,
            device=volume.get('device', None),
            call='action'
        )

        if attach:
            msg = (
                '{0} attached to {1} (aka {2})'.format(
                    volume_dict['id'],
                    name,
                    volume_dict['name'],
                )
            )
            log.info(msg)
            ret.append(msg)
    return ret
941953
def volume_attach(provider, names, **kwargs):
    '''
    

    '''
    client = _get_client()
    info = client.extra_action(provider=provider, names=names, action='volume_attach', **kwargs)
    return info
1102078
def get_volumes(self):
        """"""

        volumes = []
        for disk in self.disks:
            volumes.extend(disk.get_volumes())
        return volumes
1299010
def list_ebs(region, filter_by_kwargs):
    """"""
    conn = boto.ec2.connect_to_region(region)
    instances = conn.get_all_volumes()
    return lookup(instances, filter_by=filter_by_kwargs)
1187885
def get_volume_list(self) -> list:
        
        # Initialising empty list
        volumes = []

        # Raise an exception if we are not a manager
        if not self._manager:
            raise RuntimeError('Only the Swarm manager node can retrieve'
                               ' all the services.')

        volume_list = self._client.volumes.list()
        for v_list in volume_list:
            volumes.append(v_list.name)
        return volumes
62522
def volume_list(search_opts=None, profile=None, **kwargs):
    '''
    

    '''
    conn = _auth(profile, **kwargs)
    return conn.volume_list(search_opts=search_opts)
636232
def get_volume(self, id):
        
        # If the id is actually a path
        if exists(id):
            with open(id) as file:
                size = os.lseek(file.fileno(), 0, os.SEEK_END)
            return {'path': id, 'size': size}
        return self.volume.get(id)
381002
def device_id(self):
        
        if self.is_block:
            for filename in self._P.Block.Symlinks:
                parts = decode_ay(filename).split('/')
                if parts[-2] == 'by-id':
                    return parts[-1]
        elif self.is_drive:
            return self._assocdrive._P.Drive.Id
        return ''
949382
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 'instance_id' not in kwargs:
        kwargs['instance_id'] = _get_node(name)['instanceId']

    if isinstance(kwargs['volumes'], six.string_types):
        volumes = salt.utils.yaml.safe_load(kwargs['volumes'])
    else:
        volumes = kwargs['volumes']

    ret = []
    for volume in volumes:
        created = False
        volume_name = '{0} on {1}'.format(volume['device'], name)

        volume_dict = {
            'volume_name': volume_name,
            'zone': kwargs['zone']
        }
        if 'volume_id' in volume:
            volume_dict['volume_id'] = volume['volume_id']
        elif 'snapshot' in volume:
            volume_dict['snapshot'] = volume['snapshot']
        elif 'size' in volume:
            volume_dict['size'] = volume['size']
        else:
            raise SaltCloudConfigError(
                'Cannot create volume.  Please define one of \'volume_id\', '
                '\'snapshot\', or \'size\''
            )

        if 'tags' in volume:
            volume_dict['tags'] = volume['tags']
        if 'type' in volume:
            volume_dict['type'] = volume['type']
        if 'iops' in volume:
            volume_dict['iops'] = volume['iops']
        if 'encrypted' in volume:
            volume_dict['encrypted'] = volume['encrypted']
        if 'kmskeyid' in volume:
            volume_dict['kmskeyid'] = volume['kmskeyid']

        if 'volume_id' not in volume_dict:
            created_volume = create_volume(volume_dict, call='function', wait_to_finish=wait_to_finish)
            created = True
            if 'volumeId' in created_volume:
                volume_dict['volume_id'] = created_volume['volumeId']

        attach = attach_volume(
            name,
            {'volume_id': volume_dict['volume_id'],
             'device': volume['device']},
            instance_id=kwargs['instance_id'],
            call='action'
        )

        # Update the delvol parameter for this volume
        delvols_on_destroy = kwargs.get('del_all_vols_on_destroy', None)

        if attach and created and delvols_on_destroy is not None:
            _toggle_delvol(instance_id=kwargs['instance_id'],
                           device=volume['device'],
                           value=delvols_on_destroy)

        if attach:
            msg = (
                '{0} attached to {1} (aka {2}) as device {3}'.format(
                    volume_dict['volume_id'],
                    kwargs['instance_id'],
                    name,
                    volume['device']
                )
            )
            log.info(msg)
            ret.append(msg)
    return ret
752774
def instances(self):
        
        # It would be more efficient to do this with filters now
        # but not all services that implement EC2 API support filters.
        instances = []
        rs = self.connection.get_all_instances()
        for reservation in rs:
            uses_group = [g.name for g in reservation.groups if g.name == self.name]
            if uses_group:
                instances.extend(reservation.instances)
        return instances
49318
def devices(self):
        
        eax = self.attributes.get('devices')
        if eax is None:
            eax = self._all_devices
        if not isinstance(eax, list):
            eax = [eax]
        return [str(dev) for dev in eax]
625753
def GetVolumeIdentifiers(self, volume_system):
    
    volume_identifiers = []
    for volume in volume_system.volumes:
      volume_identifier = getattr(volume, 'identifier', None)
      if volume_identifier:
        volume_identifiers.append(volume_identifier)

    return sorted(volume_identifiers)