예제 #1
0
 def build_entity(self):
     return otypes.DiskAttachment(
         disk=super(DiskAttachmentsModule, self).build_entity(),
         interface=otypes.DiskInterface(
             self._module.params.get('interface'))
         if self._module.params.get('interface') else None,
         bootable=self._module.params.get('bootable'),
         active=True,
     )
 def build_entity(self):
     return otypes.DiskAttachment(
         disk=super(DiskAttachmentsModule, self).build_entity(),
         interface=otypes.DiskInterface(
             self._module.params.get('interface')
         ) if self._module.params.get('interface') else None,
         bootable=self._module.params.get('bootable'),
         active=self.param('activate'),
         uses_scsi_reservation=self.param('uses_scsi_reservation'),
         pass_discard=self.param('pass_discard'),
     )
예제 #3
0
파일: rhevm.py 프로젝트: tkhamis/wrapanapi
    def connect_direct_lun(self,
                           lun_name=None,
                           lun_ip_addr=None,
                           lun_port=None,
                           lun_iscsi_target=None,
                           interface=None):
        """
        Connects a direct lun disk to the VM.

        Args:
            lun_name: name of LUN
            lun_ip_addr: LUN ip address
            lun_port: LUN port
            lun_iscsi_target: iscsi target
        """
        disk_attachments_service = self.api.disk_attachments_service()
        if not self.system.does_disk_exist(lun_name):
            disk_attachment = types.DiskAttachment(
                disk=types.Disk(name=lun_name,
                                shareable=True,
                                format='raw',
                                lun_storage=types.HostStorage(
                                    type=types.StorageType.ISCSI,
                                    logical_units=[
                                        types.LogicalUnit(
                                            address=lun_ip_addr,
                                            port=lun_port,
                                            target=lun_iscsi_target,
                                        )
                                    ])),
                interface=types.DiskInterface(
                    getattr(types.DiskInterface, interface or 'VIRTIO')),
                active=True)
        else:
            disk_attachment = self._get_disk_attachment_service(lun_name).get()
        disk_attachments_service.add(disk_attachment)
        wait_for(self._is_disk_ok,
                 func_args=[disk_attachment.disk.id],
                 delay=5,
                 num_sec=900,
                 message="check if disk is attached")
        return True
예제 #4
0
파일: rhevm.py 프로젝트: sasoc/wrapanapi
    def add_disk_to_vm(self,
                       vm_name,
                       storage_domain=None,
                       size=None,
                       interface=None,
                       format=None,
                       active=True):
        """

        Args:
            vm_name: string name
            storage_domain: string name of the storage domain (datastore)
            size: integer size of disk in bytes, ex 8GB: 8*1024*1024
            interface: string disk interface type
            format: string disk format type
            active: boolean whether the disk is active

        Returns: None

        Notes:
            Disk format and interface type definitions, and their valid values,
            can be found in ovirtsdk documentation:
            http://ovirt.github.io/ovirt-engine-sdk/4.1/types.m.html#ovirtsdk4.types.DiskInterface
            http://ovirt.github.io/ovirt-engine-sdk/4.1/types.m.html#ovirtsdk4.types.DiskFormat
        """
        disk_attachments_service = self._get_disk_attachments_service(vm_name)
        disk_attachment = disk_attachments_service.add(
            types.DiskAttachment(disk=types.Disk(
                format=types.DiskFormat(format),
                provisioned_size=size,
                storage_domains=[types.StorageDomain(name=storage_domain, )]),
                                 interface=types.DiskInterface(interface),
                                 active=active))
        wait_for(self._check_disk,
                 func_args=[disk_attachment.disk.id],
                 delay=5,
                 num_sec=900,
                 message="check if disk is attached")
예제 #5
0
def attach_disk(params, vm_name):

    vms_service = connection.system_service().vms_service()
    name_of_VM = 'name=' + str(vm_name)
    vm = vms_service.list(search=str(name_of_VM))[0]
    disk_attachments_service = vms_service.vm_service(
        vm.id).disk_attachments_service()

    if params["format"].lower() == "raw":
        disk_format = types.DiskFormat.RAW
    elif params["format"].lower() == "cow":
        disk_format = types.DiskFormat.COW
    else:
        return ("Cant determinate format of disk. Supported only RAW and COW")
        raise SaltCloudExecutionFailure

    if params["interface"].lower() == "virtio":
        disk_interface = types.DiskInterface.VIRTIO
    else:
        return ("Cant interface of disk. Supported only RAW and COW")
        raise SaltCloudExecutionFailure

    if "existing_disk" not in params:
        disk_attachment = disk_attachments_service.add(
            types.DiskAttachment(
                disk=types.Disk(
                    name=params["name"],
                    description=params["description"]
                    if "description" in params else "Not provided",
                    format=disk_format,
                    provisioned_size=int(params["provisioned_size"]) * 2**30,
                    storage_domains=[
                        types.StorageDomain(name=params["storage_domains"], ),
                    ],
                ),
                interface=disk_interface,
                bootable=params["bootable"],
                active=params["active"],
            ), )
    else:
        if params["existing_disk"] == True:
            disk_attachments_service.add(
                types.DiskAttachment(
                    disk=types.Disk(id=params["id"], ),
                    active=params["active"],
                    interface=types.DiskInterface(disk_interface),
                    bootable=params["bootable"],
                ))
        else:
            disk_attachment = disk_attachments_service.add(
                types.DiskAttachment(
                    disk=types.Disk(
                        name=params["name"],
                        description=params["description"]
                        if "description" in params else "Not provided",
                        format=disk_format,
                        provisioned_size=int(params["provisioned_size"]) *
                        2**30,
                        storage_domains=[
                            types.StorageDomain(
                                name=params["storage_domains"], ),
                        ],
                    ),
                    interface=disk_interface,
                    bootable=params["bootable"],
                    active=params["active"],
                ), )