Пример #1
0
    def update_storage_domains(self, disk_id):
        changed = False
        disk_service = self._service.service(disk_id)
        disk = disk_service.get()
        sds_service = self._connection.system_service(
        ).storage_domains_service()

        # Initiate move:
        if self._module.params['storage_domain']:
            new_disk_storage = search_by_name(
                sds_service, self._module.params['storage_domain'])
            changed = self.action(
                action='move',
                entity=disk,
                action_condition=lambda d: new_disk_storage.id != d.
                storage_domains[0].id,
                wait_condition=lambda d: d.status == otypes.DiskStatus.OK,
                storage_domain=otypes.StorageDomain(id=new_disk_storage.id, ),
            )['changed']

        if self._module.params['storage_domains']:
            for sd in self._module.params['storage_domains']:
                new_disk_storage = search_by_name(sds_service, sd)
                changed = changed or self.action(
                    action='copy',
                    entity=disk,
                    wait_condition=lambda disk: disk.status == otypes.
                    DiskStatus.OK,
                    storage_domain=otypes.StorageDomain(
                        id=new_disk_storage.id, ),
                )['changed']

        return changed
Пример #2
0
def add_disks(api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    glance_disk = test_utils.get_disk_service(engine, GLANCE_DISK_NAME)
    nt.assert_true(vm_service and glance_disk)

    vm0_disk_attachments_service = (test_utils.get_disk_attachments_service(
        engine, VM0_NAME))

    vm0_disk_attachments_service.add(
        types.DiskAttachment(
            disk=types.Disk(
                id=glance_disk.get().id,
                storage_domains=[
                    types.StorageDomain(name=SD_ISCSI_NAME, ),
                ],
            ),
            interface=types.DiskInterface.VIRTIO,
            active=True,
            bootable=True,
        ), )

    disk_params = types.Disk(
        provisioned_size=1 * GB,
        format=types.DiskFormat.COW,
        status=None,
        sparse=True,
        active=True,
        bootable=True,
    )

    for vm_name, disk_name, sd_name in ((VM1_NAME, DISK1_NAME,
                                         SD_NFS_NAME), (VM2_NAME, DISK2_NAME,
                                                        SD_SECOND_NFS_NAME),
                                        (BACKUP_VM_NAME, BACKUP_DISK_NAME,
                                         SD_NFS_NAME)):
        disk_params.name = disk_name
        disk_params.storage_domains = [types.StorageDomain(name=sd_name, )]

        disk_attachments_service = (test_utils.get_disk_attachments_service(
            engine, vm_name))
        nt.assert_true(
            disk_attachments_service.add(
                types.DiskAttachment(disk=disk_params,
                                     interface=types.DiskInterface.VIRTIO)))

    for disk_name in (
            GLANCE_DISK_NAME,
            DISK1_NAME,
            DISK2_NAME,
            BACKUP_DISK_NAME,
    ):
        disk_service = test_utils.get_disk_service(engine, disk_name)
        testlib.assert_true_within_short(
            lambda: disk_service.get().status == types.DiskStatus.OK)
Пример #3
0
def test_add_disks(engine_api, cirros_image_glance_disk_name):
    engine = engine_api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM0_NAME)
    glance_disk = test_utils.get_disk_service(
        engine,
        cirros_image_glance_disk_name,
    )
    assert vm_service and glance_disk

    vm0_disk_attachments_service = test_utils.get_disk_attachments_service(
        engine, VM0_NAME)

    vm0_disk_attachments_service.add(
        types.DiskAttachment(
            disk=types.Disk(
                id=glance_disk.get().id,
                storage_domains=[
                    types.StorageDomain(name=SD_ISCSI_NAME, ),
                ],
            ),
            interface=types.DiskInterface.VIRTIO,
            active=True,
            bootable=True,
        ), )

    disk_params = types.Disk(
        provisioned_size=1 * GB,
        format=types.DiskFormat.COW,
        status=None,
        sparse=True,
        active=True,
        bootable=True,
        backup=types.DiskBackup.INCREMENTAL,
    )

    for vm_name, disk_name, sd_name in ((VM1_NAME, DISK1_NAME,
                                         SD_NFS_NAME), (VM2_NAME, DISK2_NAME,
                                                        SD_SECOND_NFS_NAME),
                                        (BACKUP_VM_NAME, BACKUP_DISK_NAME,
                                         SD_NFS_NAME)):
        disk_params.name = disk_name
        disk_params.storage_domains = [types.StorageDomain(name=sd_name, )]

        disk_attachments_service = test_utils.get_disk_attachments_service(
            engine, vm_name)
        assert disk_attachments_service.add(
            types.DiskAttachment(disk=disk_params,
                                 interface=types.DiskInterface.VIRTIO))

    for disk_name in (cirros_image_glance_disk_name, DISK1_NAME, DISK2_NAME,
                      BACKUP_DISK_NAME):
        disk_service = test_utils.get_disk_service(engine, disk_name)
        assertions.assert_true_within_short(
            lambda: disk_service.get().status == types.DiskStatus.OK)
    def update_storage_domains(self, disk_id):
        changed = False
        disk_service = self._service.service(disk_id)
        disk = disk_service.get()
        sds_service = self._connection.system_service(
        ).storage_domains_service()

        # We don't support move&copy for non file based storages:
        if disk.storage_type != otypes.DiskStorageType.IMAGE:
            return changed
        if disk.content_type in [
                otypes.DiskContentType(x) for x in [
                    'hosted_engine', 'hosted_engine_sanlock',
                    'hosted_engine_metadata', 'hosted_engine_configuration'
                ]
        ]:
            return changed
        # Initiate move:
        if self._module.params['storage_domain']:
            new_disk_storage_id = get_id_by_name(
                sds_service, self._module.params['storage_domain'])
            if new_disk_storage_id in [sd.id for sd in disk.storage_domains]:
                return changed
            changed = self.action(
                action='move',
                entity=disk,
                action_condition=lambda d: new_disk_storage_id != d.
                storage_domains[0].id,
                wait_condition=lambda d: d.status == otypes.DiskStatus.OK,
                storage_domain=otypes.StorageDomain(id=new_disk_storage_id, ),
                post_action=lambda _: time.sleep(self._module.params[
                    'poll_interval']),
            )['changed']

        if self._module.params['storage_domains']:
            for sd in self._module.params['storage_domains']:
                new_disk_storage = search_by_name(sds_service, sd)
                changed = changed or self.action(
                    action='copy',
                    entity=disk,
                    action_condition=(lambda disk: new_disk_storage.id not in
                                      [sd.id for sd in disk.storage_domains]),
                    wait_condition=lambda disk: disk.status == otypes.
                    DiskStatus.OK,
                    storage_domain=otypes.StorageDomain(
                        id=new_disk_storage.id, ),
                )['changed']

        return changed
Пример #5
0
 def addVMDisk(self, vmname, storagedomain, disksize, diskname, disk_desc):
     vms_service = self.connection.system_service().vms_service()
     vm = vms_service.list(search='name=%s' %
                           str(vmname))[0]  # 如果search 多个只获取第一个,后面雷同
     disk_attachments_service = vms_service.vm_service(
         vm.id).disk_attachments_service()
     disk_attachment = disk_attachments_service.add(
         types.DiskAttachment(
             disk=types.Disk(
                 name=diskname,  # 新增磁盘名称
                 description=disk_desc,  # 新增磁盘描述
                 format=types.DiskFormat.COW,  # 新增磁盘类型为COW
                 provisioned_size=disksize * 2**30,  # 新增磁盘大小
                 storage_domains=[
                     types.StorageDomain(
                         name=storagedomain,  # 从那个存储域获取资源
                     ),
                 ],
             ),
             interface=types.DiskInterface.VIRTIO,  # 磁盘接口类型
             bootable=False,
             active=True,  # 是否激活
         ), )
     disks_service = self.connection.system_service().disks_service(
     )  # 获取集群 相关磁盘服务
     disk_service = disks_service.disk_service(
         disk_attachment.disk.id)  # 根据 磁盘相关信息获取当前附加磁盘状态
     while True:
         time.sleep(2)
         disk = disk_service.get()  # 获取磁盘相关信息
         if disk.status == types.DiskStatus.OK:  # 判断磁盘状态是否正常
             break
Пример #6
0
def hotplug_disk(api):
    vm_service = test_utils.get_vm_service(api.system_service(), VM0_NAME)
    disk_attachments_service = vm_service.disk_attachments_service()
    disk_attachment = disk_attachments_service.add(
        types.DiskAttachment(disk=types.Disk(
            name=DISK0_NAME,
            provisioned_size=2 * GB,
            format=types.DiskFormat.COW,
            storage_domains=[
                types.StorageDomain(name=SD_NFS_NAME, ),
            ],
            status=None,
            sparse=True,
        ),
                             interface=types.DiskInterface.VIRTIO,
                             bootable=False,
                             active=True))

    disks_service = api.system_service().disks_service()
    disk_service = disks_service.disk_service(disk_attachment.disk.id)
    attachment_service = disk_attachments_service.attachment_service(
        disk_attachment.id)

    testlib.assert_true_within_short(lambda: attachment_service.get(
    ).active and disk_service.get().status == types.DiskStatus.OK)
Пример #7
0
def add_disk(pname, pdiskname, pdisk_description, psd, pbootable, psize,
             wait_for_up):
    print('Adding Disk : ' + pdiskname + ' to VM ' + pname + '...')
    vm = vms_service.list(search='name=' + pname)[0]
    disk_attachments_service = vms_service.vm_service(
        vm.id).disk_attachments_service()
    disk_attachment = disk_attachments_service.add(
        types.DiskAttachment(
            disk=types.Disk(
                name=pdiskname,
                description=pdisk_description,
                format=types.DiskFormat.COW,
                provisioned_size=psize,
                storage_domains=[
                    types.StorageDomain(name=psd, ),
                ],
            ),
            interface=types.DiskInterface.VIRTIO,
            bootable=pbootable,
        ), )
    if wait_for_up:
        # Wait till the disk is OK:
        disks_service = connection.system_service().disks_service()
        disk_service = disks_service.disk_service(disk_attachment.disk.id)
        track_status(disk_service, types.DiskStatus.OK, 1)
Пример #8
0
def export_cloned_vm(export_domain, vm_clone_name, vms_service):
    logger.info("Exporting cloned (%s) VM started ..." % vm_clone_name)

    try:
        vms = vms_service.list(search="name=%s" % str(vm_clone_name))
        if not vms:
            logger.warning(
                "The VM (%s) doesn't exist anymore, skipping backup ...",
                vm_clone_name)
            raise Exception

        vm_service = vms_service.vm_service(vms[0].id)

        vm_service.export(
            exclusive=True,
            discard_snapshots=True,
            storage_domain=types.StorageDomain(name=export_domain))

        while True:
            time.sleep(15)
            vms = vm_service.get()
            if vms.status == types.VmStatus.DOWN:
                break

    except Exception as e:
        logger.info("Can't export cloned (%s) VM", vm_clone_name)
        logger.info("DEBUG: %s", e)

    logger.info("Cloned VM exported successfully")
Пример #9
0
def add_disk(api):
    engine = api.system_service()
    vm0_service = test_utils.get_vm_service(engine, VM0_NAME)
    vm0_disk_attachments_service = test_utils.get_disk_attachments_service(
        engine, VM0_NAME)

    vm0_disk_attachments_service.add(
        types.DiskAttachment(
            disk=types.Disk(
                name=DISK0_NAME,
                format=types.DiskFormat.COW,
                initial_size=10 * GB,
                provisioned_size=1,
                sparse=True,
                storage_domains=[
                    types.StorageDomain(name=MASTER_SD_NAME, ),
                ],
            ),
            interface=types.DiskInterface.VIRTIO,
            active=True,
            bootable=True,
        ), )

    disk0_service = test_utils.get_disk_service(engine, DISK0_NAME)
    disk0_attachment_service = vm0_disk_attachments_service.attachment_service(
        disk0_service.get().id)

    testlib.assert_true_within_long(
        lambda: disk0_attachment_service.get().active == True)
    testlib.assert_true_within_long(
        lambda: disk0_service.get().status == types.DiskStatus.OK)
Пример #10
0
def add_disk_to_instance(api, vm_id, storage_domain, size, name, boot=True):
    """Add disk to VM by id."""
    vms_service = api.system_service().vms_service()
    disk_attachments_service = vms_service.vm_service(
        vm_id).disk_attachments_service()
    try:
        disk_attachment = disk_attachments_service.add(
            types.DiskAttachment(
                disk=types.Disk(
                    name=name,
                    description=name,
                    format=types.DiskFormat.COW,
                    provisioned_size=size * 2**30,
                    sparse=True,
                    storage_domains=[
                        types.StorageDomain(id=storage_domain, ),
                    ],
                ),
                interface=types.DiskInterface.VIRTIO_SCSI,
                bootable=boot,
                active=True,
            ), )
    except Exception as e:
        print "Can't add Disk: %s" % str(e)
        api.close()
        sys.exit(1)
    disks_service = api.system_service().disks_service()
    disk_service = disks_service.disk_service(disk_attachment.disk.id)
    while True:
        time.sleep(5)
        disk = disk_service.get()
        if disk.status == types.DiskStatus.OK:
            break
Пример #11
0
    def build_entity(self):
        storage_type = self._get_storage_type()
        storage = self._get_storage()
        self._login(storage_type, storage)

        return otypes.StorageDomain(
            name=self._module.params['name'],
            description=self._module.params['description'],
            comment=self._module.params['comment'],
            type=otypes.StorageDomainType(
                self._module.params['domain_function']),
            host=otypes.Host(name=self._module.params['host'], ),
            storage=otypes.HostStorage(
                type=otypes.StorageType(storage_type),
                logical_units=[
                    otypes.LogicalUnit(
                        id=storage.get('lun_id'),
                        address=storage.get('address'),
                        port=storage.get('port', 3260),
                        target=storage.get('target'),
                        username=storage.get('username'),
                        password=storage.get('password'),
                    ),
                ] if storage_type in ['iscsi', 'fcp'] else None,
                override_luns=storage.get('override_luns'),
                mount_options=storage.get('mount_options'),
                vfs_type='glusterfs'
                if storage_type in ['glusterfs'] else storage.get('vfs_type'),
                address=storage.get('address'),
                path=storage.get('path'),
                nfs_retrans=storage.get('retrans'),
                nfs_timeo=storage.get('timeout'),
                nfs_version=otypes.NfsVersion(storage.get('version'))
                if storage.get('version') else None,
            ) if storage_type is not None else None)
Пример #12
0
def test_live_storage_migration(api_v4):
    pytest.skip("TODO: el8 fails all the time")

    engine = api_v4.system_service()
    disk_service = test_utils.get_disk_service(engine, DISK0_NAME)
    correlation_id = 'live_storage_migration'
    disk_service.move(async=False,
                      filter=False,
                      storage_domain=types.StorageDomain(name=SD_ISCSI_NAME),
                      query={'correlation_id': correlation_id})

    testlib.assert_true_within_long(
        lambda: test_utils.all_jobs_finished(engine, correlation_id))

    # Assert that the disk is on the correct storage domain,
    # its status is OK and the snapshot created for the migration
    # has been merged
    testlib.assert_true_within_long(lambda: api_v4.follow_link(
        disk_service.get().storage_domains[0]).name == SD_ISCSI_NAME)

    vm0_snapshots_service = test_utils.get_vm_snapshots_service(
        engine, VM0_NAME)
    testlib.assert_true_within_long(
        lambda: len(vm0_snapshots_service.list()) == 1)
    testlib.assert_true_within_long(
        lambda: disk_service.get().status == types.DiskStatus.OK)
Пример #13
0
    def build_entity(self):
        logical_unit = self._module.params.get('logical_unit')
        disk = otypes.Disk(
            id=self._module.params.get('id'),
            name=self._module.params.get('name'),
            description=self._module.params.get('description'),
            format=otypes.DiskFormat(self._module.params.get('format'))
            if self._module.params.get('format') else None,
            sparse=self._module.params.get('format') != 'raw',
            provisioned_size=convert_to_bytes(self._module.params.get('size')),
            storage_domains=[
                otypes.StorageDomain(
                    name=self._module.params.get('storage_domain'), ),
            ],
            shareable=self._module.params.get('shareable'),
            lun_storage=otypes.HostStorage(
                type=otypes.StorageType(
                    logical_unit.get('storage_type', 'iscsi')),
                logical_units=[
                    otypes.LogicalUnit(
                        address=logical_unit.get('address'),
                        port=logical_unit.get('port', 3260),
                        target=logical_unit.get('target'),
                        id=logical_unit.get('id'),
                        username=logical_unit.get('username'),
                        password=logical_unit.get('password'),
                    )
                ],
            ) if logical_unit else None,
        )
        if hasattr(disk, 'initial_size'):
            disk.initial_size = convert_to_bytes(
                self._module.params.get('size'))

        return disk
Пример #14
0
 def build_entity(self):
     return otypes.Event(
         description=self._module.params['description'],
         severity=otypes.LogSeverity(self._module.params['severity']),
         origin=self._module.params['origin'],
         custom_id=self._module.params['custom_id'],
         id=self._module.params['id'],
         cluster=otypes.Cluster(
             id=self._module.params['cluster']
         ) if self._module.params['cluster'] is not None else None,
         data_center=otypes.DataCenter(
             id=self._module.params['data_center']
         ) if self._module.params['data_center'] is not None else None,
         host=otypes.Host(
             id=self._module.params['host']
         ) if self._module.params['host'] is not None else None,
         storage_domain=otypes.StorageDomain(
             id=self._module.params['storage_domain']
         ) if self._module.params['storage_domain'] is not None else None,
         template=otypes.Template(
             id=self._module.params['template']
         ) if self._module.params['template'] is not None else None,
         user=otypes.User(
             id=self._module.params['user']
         ) if self._module.params['user'] is not None else None,
         vm=otypes.Vm(
             id=self._module.params['vm']
         ) if self._module.params['vm'] is not None else None,
     )
Пример #15
0
def create_disk(connection, args, disk_info):
    disks_service = connection.system_service().disks_service()

    disk = disks_service.add(
        types.Disk(
            name=disk_info["name"],
            content_type=types.DiskContentType.DATA,
            description='Uploaded from {} by upload_from_ova.py'.format(
                os.path.basename(args.ova_file)),
            format=disk_info["format"],
            initial_size=disk_info["initial_size"],
            provisioned_size=disk_info["provisioned_size"],
            sparse=args.disk_sparse,
            backup=disk_info["backup"],
            storage_domains=[
                types.StorageDomain(name=args.sd_name)
            ]
        )
    )

    # Wait till the disk is OK, as the transfer can't start if the disk is
    # locked.
    disk_service = disks_service.disk_service(disk.id)
    while True:
        time.sleep(1)
        disk = disk_service.get()
        if disk.status == types.DiskStatus.OK:
            break

    return disk
Пример #16
0
def import_image(system_service,
                 image_name,
                 template_name,
                 disk_name,
                 dest_storage_domain,
                 dest_cluster,
                 sd_name,
                 as_template=False):
    storage_domains_service = system_service.storage_domains_service()
    glance_storage_domain = storage_domains_service.list(
        search='name={}'.format(sd_name))[0]
    images = storage_domains_service.storage_domain_service(
        glance_storage_domain.id).images_service().list()
    image = [x for x in images if x.name == image_name][0]
    image_service = storage_domains_service.storage_domain_service(
        glance_storage_domain.id).images_service().image_service(image.id)
    result = image_service.import_(
        storage_domain=types.StorageDomain(name=dest_storage_domain, ),
        template=types.Template(name=template_name, ),
        cluster=types.Cluster(name=dest_cluster, ),
        import_as_template=as_template,
        disk=types.Disk(name=disk_name),
    )
    disk = system_service.disks_service().list(
        search='name={}'.format(disk_name))[0]
    assert disk
Пример #17
0
    def add_disk(self, storage_domain=None, size=None, interface='VIRTIO', format=None,
                 active=True):
        """
        Add disk to VM

        Args:
            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.api.disk_attachments_service()
        disk_attach = types.DiskAttachment(
            disk=types.Disk(format=types.DiskFormat(format),
                            provisioned_size=size,
                            storage_domains=[types.StorageDomain(name=storage_domain)]),
            interface=getattr(types.DiskInterface, interface),
            active=active
        )
        disk_attachment = disk_attachments_service.add(disk_attach)
        wait_for(self._is_disk_ok, func_args=[disk_attachment.disk.id], delay=5, num_sec=900,
                 message="check if disk is attached")
def create_disk(image_info, disk_id, sd_name, disks_service):
    """
    Creates a new disk with the specified disk_id and image_id
    from image_info (to keep the meta-data identical to
    the uploaded disk).
    """
    initial_size = image_info['actual-size']
    provisioned_size = image_info['virtual-size']
    image_id = os.path.basename(image_info['filename'])

    disk = disks_service.add(
        types.Disk(id=disk_id,
                   image_id=image_id,
                   name=disk_id,
                   format=types.DiskFormat.RAW,
                   provisioned_size=provisioned_size,
                   initial_size=initial_size,
                   storage_domains=[types.StorageDomain(name=sd_name)]))
    disk_service = disks_service.disk_service(disk.id)
    while True:
        time.sleep(5)
        disk = disk_service.get()
        if disk.status == types.DiskStatus.OK:
            break

    return disk
Пример #19
0
def add_disk(api):
    engine = api.system_service()
    vm0_service = test_utils.get_vm_service(engine, VM0_NAME)
    glance_disk = test_utils.get_disk_service(engine, GLANCE_DISK_NAME)

    nt.assert_true(vm0_service and glance_disk)

    vm0_disk_attachments_service = test_utils.get_disk_attachments_service(
        engine, VM0_NAME)

    vm0_disk_attachments_service.add(
        types.DiskAttachment(
            disk=types.Disk(
                id=glance_disk.get().id,
                storage_domains=[
                    types.StorageDomain(name=SD_NFS_NAME, ),
                ],
            ),
            interface=types.DiskInterface.VIRTIO,
            active=True,
            bootable=True,
        ), )

    disk_service = test_utils.get_disk_service(engine, GLANCE_DISK_NAME)

    testlib.assert_true_within_short(
        lambda: disk_service.get().status == types.DiskStatus.OK)
Пример #20
0
    def build_entity(self):
        storage_type = self._get_storage_type()
        storage = self._get_storage()
        self._login(storage_type, storage)

        return otypes.StorageDomain(
            name=self._module.params['name'],
            description=self._module.params['description'],
            comment=self._module.params['comment'],
            type=otypes.StorageDomainType(
                self._module.params['domain_function']
            ),
            host=otypes.Host(
                name=self._module.params['host'],
            ),
            storage=otypes.HostStorage(
                type=otypes.StorageType(storage_type),
                logical_units=[
                    otypes.LogicalUnit(
                        id=storage.get('lun_id'),
                        address=storage.get('address'),
                        port=storage.get('port', 3260),
                        target=storage.get('target'),
                        username=storage.get('username'),
                        password=storage.get('password'),
                    ),
                ] if storage_type in ['iscsi', 'fcp'] else None,
                mount_options=storage.get('mount_options'),
                vfs_type=storage.get('vfs_type'),
                address=storage.get('address'),
                path=storage.get('path'),
            )
        )
Пример #21
0
def test_hotplug_disk(prefix):
    api_v4 = prefix.virt_env.engine_vm().get_api_v4()
    engine = api_v4.system_service()
    disk_attachments_service = test_utils.get_disk_attachments_service(
        engine, VM0_NAME)
    disk_attachment = disk_attachments_service.add(
        types.DiskAttachment(disk=types.Disk(
            name=DISK0_NAME,
            provisioned_size=2 * GB,
            format=types.DiskFormat.COW,
            storage_domains=[
                types.StorageDomain(name=SD_NFS_NAME, ),
            ],
            status=None,
            sparse=True,
        ),
                             interface=types.DiskInterface.VIRTIO,
                             bootable=False,
                             active=True))

    disks_service = engine.disks_service()
    disk_service = disks_service.disk_service(disk_attachment.disk.id)
    attachment_service = disk_attachments_service.attachment_service(
        disk_attachment.id)

    testlib.assert_true_within_short(
        lambda: attachment_service.get().active == True)
    testlib.assert_true_within_short(
        lambda: disk_service.get().status == types.DiskStatus.OK)
    assert_vm0_is_alive(prefix)
Пример #22
0
def add_disk_to_vm(api, options):
    """Add disk to vm."""
    search_name = "name=" + options['vm_name']
    vms_service = api.system_service().vms_service()
    vm = vms_service.list(search=search_name)[0]
    disk_attachments_service = vms_service.vm_service(
        vm.id).disk_attachments_service()
    try:
        disk_attachment = disk_attachments_service.add(
            types.DiskAttachment(
                disk=types.Disk(
                    name='os_disk',
                    description='OS',
                    format=types.DiskFormat.COW,
                    provisioned_size=options['os_disk'] * 2**30,
                    storage_domains=[
                        types.StorageDomain(name=options['storagedomain'], ),
                    ],
                ),
                interface=types.DiskInterface.VIRTIO,
                bootable=True,
                active=True,
            ), )
    except Exception as e:
        print "Can't add Disk: %s" % str(e)
        api.close()
        sys.exit(1)

    disks_service = api.system_service().disks_service()
    disk_service = disks_service.disk_service(disk_attachment.disk.id)
    while True:
        time.sleep(5)
        disk = disk_service.get()
        if disk.status == types.DiskStatus.OK:
            break
Пример #23
0
def add_disk(api):
    engine = api.system_service()
    vms_service = engine.vms_service()
    vm = vms_service.list(search=VM0_NAME)[0]
    vm_service = vms_service.vm_service(vm.id)

    disks_service = engine.disks_service()
    disk = disks_service.list(search=GLANCE_DISK_NAME)[0]
    glance_disk = disks_service.disk_service(disk.id)
    nt.assert_true(vm_service and glance_disk)

    vm_service.disk_attachments_service().add(
        types.DiskAttachment(
            disk=types.Disk(
                id=glance_disk.get().id,
                storage_domain=types.StorageDomain(name=SD_ISCSI_NAME, ),
            ),
            interface=types.DiskInterface.VIRTIO,
            active=True,
            bootable=True,
        ), )

    disk_params = types.Disk(
        provisioned_size=1 * GB,
        format=types.DiskFormat.COW,
        status=None,
        sparse=True,
        active=True,
        bootable=True,
    )

    for vm_name, disk_name, sd_name in ((VM1_NAME, DISK1_NAME, SD_NFS_NAME),
                                        (VM2_NAME, DISK2_NAME,
                                         SD_SECOND_NFS_NAME)):
        disk_params.name = disk_name
        disk_params.storage_domains = [types.StorageDomain(name=sd_name, )]

        vm_service = vms_service.vm_service(
            vms_service.list(search=vm_name)[0].id)
        nt.assert_true(vm_service.disk_attachments_service().add(
            types.DiskAttachment(disk=disk_params,
                                 interface=types.DiskInterface.VIRTIO)))

    for disk_name in (GLANCE_DISK_NAME, DISK1_NAME, DISK2_NAME):
        testlib.assert_true_within_short(lambda: disks_service.disk_service(
            disks_service.list(search=disk_name)[0].id).get().status == types.
                                         DiskStatus.OK)
    def build_entity(self):
        hosts_service = self._connection.system_service().hosts_service()
        logical_unit = self._module.params.get('logical_unit')
        size = convert_to_bytes(self._module.params.get('size'))
        if not size and self._module.params.get('upload_image_path'):
            size = os.path.getsize(self._module.params.get('upload_image_path'))
        disk = otypes.Disk(
            id=self._module.params.get('id'),
            name=self._module.params.get('name'),
            description=self._module.params.get('description'),
            format=otypes.DiskFormat(
                self._module.params.get('format')
            ) if self._module.params.get('format') else None,
            content_type=otypes.DiskContentType(
                self._module.params.get('content_type')
            ) if self._module.params.get('content_type') else None,
            sparse=self._module.params.get(
                'sparse'
            ) if self._module.params.get(
                'sparse'
            ) is not None else self._module.params.get('format') != 'raw',
            openstack_volume_type=otypes.OpenStackVolumeType(
                name=self.param('openstack_volume_type')
            ) if self.param('openstack_volume_type') else None,
            provisioned_size=size,
            storage_domains=[
                otypes.StorageDomain(
                    name=self._module.params.get('storage_domain'),
                ),
            ],
            quota=otypes.Quota(id=self._module.params.get('quota_id')) if self.param('quota_id') else None,
            shareable=self._module.params.get('shareable'),
            sgio=otypes.ScsiGenericIO(self.param('scsi_passthrough')) if self.param('scsi_passthrough') else None,
            propagate_errors=self.param('propagate_errors'),
            backup=otypes.DiskBackup(self.param('backup')) if self.param('backup') else None,
            wipe_after_delete=self.param('wipe_after_delete'),
            lun_storage=otypes.HostStorage(
                host=otypes.Host(
                    id=get_id_by_name(hosts_service, self._module.params.get('host'))
                ) if self.param('host') else None,
                type=otypes.StorageType(
                    logical_unit.get('storage_type', 'iscsi')
                ),
                logical_units=[
                    otypes.LogicalUnit(
                        address=logical_unit.get('address'),
                        port=logical_unit.get('port', 3260),
                        target=logical_unit.get('target'),
                        id=logical_unit.get('id'),
                        username=logical_unit.get('username'),
                        password=logical_unit.get('password'),
                    )
                ],
            ) if logical_unit else None,
        )
        if hasattr(disk, 'initial_size') and self._module.params['upload_image_path']:
            disk.initial_size = size

        return disk
Пример #25
0
def attach_storage(psearch_storage, psearch_dc):
    sd = sds_service.list(search=psearch_storage)[0]
    dc = dcs_service.list(search=psearch_dc)[0]
    dc_service = dcs_service.data_center_service(dc.id)
    attached_sds_service = dc_service.storage_domains_service()
    attached_sds_service.add(types.StorageDomain(id=sd.id, ), )
    attached_sd_service = attached_sds_service.storage_domain_service(sd.id)
    track_status(attached_sd_service.get, types.StorageDomainStatus.ACTIVE, 1)
Пример #26
0
def export_vm(api):
    engine = api.system_service()
    vm_service = test_utils.get_vm_service(engine, VM1_NAME)
    sd = engine.storage_domains_service().list(search=SD_TEMPLATES_NAME)[0]

    vm_service.export(storage_domain=types.StorageDomain(id=sd.id, ),
                      discard_snapshots=True,
                      async=True)
    def build_entity(self):
        storage_type = self._get_storage_type()
        storage = self._get_storage()
        self._login(storage_type, storage)

        return otypes.StorageDomain(
            name=self.param('name'),
            description=self.param('description'),
            comment=self.param('comment'),
            wipe_after_delete=self.param('wipe_after_delete'),
            backup=self.param('backup'),
            critical_space_action_blocker=self.param('critical_space_action_blocker'),
            warning_low_space_indicator=self.param('warning_low_space'),
            import_=True if self.param('state') == 'imported' else None,
            id=self.param('id') if self.param('state') == 'imported' else None,
            type=otypes.StorageDomainType(storage_type if storage_type == 'managed_block_storage' else self.param('domain_function')),
            host=otypes.Host(name=self.param('host')),
            discard_after_delete=self.param('discard_after_delete'),
            storage=otypes.HostStorage(
                driver_options=[
                    otypes.Property(
                        name=do.get('name'),
                        value=do.get('value')
                    ) for do in storage.get('driver_options')
                ] if storage.get('driver_options') else None,
                driver_sensitive_options=[
                    otypes.Property(
                        name=dso.get('name'),
                        value=dso.get('value')
                    ) for dso in storage.get('driver_sensitive_options')
                ] if storage.get('driver_sensitive_options') else None,
                type=otypes.StorageType(storage_type),
                logical_units=[
                    otypes.LogicalUnit(
                        id=lun_id,
                        address=storage.get('address'),
                        port=int(storage.get('port', 3260)),
                        target=target,
                        username=storage.get('username'),
                        password=storage.get('password'),
                    ) for lun_id, target in self.__target_lun_map(storage)
                ] if storage_type in ['iscsi', 'fcp'] else None,
                override_luns=storage.get('override_luns'),
                mount_options=storage.get('mount_options'),
                vfs_type=(
                    'glusterfs'
                    if storage_type in ['glusterfs'] else storage.get('vfs_type')
                ),
                address=storage.get('address'),
                path=storage.get('path'),
                nfs_retrans=storage.get('retrans'),
                nfs_timeo=storage.get('timeout'),
                nfs_version=otypes.NfsVersion(
                    storage.get('version')
                ) if storage.get('version') else None,
            ) if storage_type is not None else None,
            storage_format=self._get_storage_format(),
        )
    def build_entity(self):
        storage_type = self._get_storage_type()
        storage = self._get_storage()
        self._login(storage_type, storage)

        return otypes.StorageDomain(
            name=self._module.params['name'],
            description=self._module.params['description'],
            comment=self._module.params['comment'],
            import_=(
                True
                if self._module.params['state'] == 'imported' else None
            ),
            id=(
                self._module.params['id']
                if self._module.params['state'] == 'imported' else None
            ),
            type=otypes.StorageDomainType(
                self._module.params['domain_function']
            ),
            host=otypes.Host(
                name=self._module.params['host'],
            ),
            discard_after_delete=self._module.params['discard_after_delete']
            if storage_type in ['iscsi', 'fcp'] else False,
            storage=otypes.HostStorage(
                type=otypes.StorageType(storage_type),
                logical_units=[
                    otypes.LogicalUnit(
                        id=lun_id,
                        address=storage.get('address'),
                        port=int(storage.get('port', 3260)),
                        target=storage.get('target'),
                        username=storage.get('username'),
                        password=storage.get('password'),
                    ) for lun_id in (
                        storage.get('lun_id')
                        if isinstance(storage.get('lun_id'), list)
                        else [storage.get('lun_id')]
                    )
                ] if storage_type in ['iscsi', 'fcp'] else None,
                override_luns=storage.get('override_luns'),
                mount_options=storage.get('mount_options'),
                vfs_type=(
                    'glusterfs'
                    if storage_type in ['glusterfs'] else storage.get('vfs_type')
                ),
                address=storage.get('address'),
                path=storage.get('path'),
                nfs_retrans=storage.get('retrans'),
                nfs_timeo=storage.get('timeout'),
                nfs_version=otypes.NfsVersion(
                    storage.get('version')
                ) if storage.get('version') else None,
            ) if storage_type is not None else None
        )
Пример #29
0
def test_export_vm1(api_v4):
    engine = api_v4.system_service()
    vm_service = test_utils.get_vm_service(engine, VM1_NAME)
    sd = engine.storage_domains_service().list(
        search='name={}'.format(SD_TEMPLATES_NAME))[0]

    with test_utils.TestEvent(engine,
                              1162):  # IMPORTEXPORT_STARTING_EXPORT_VM event
        vm_service.export(storage_domain=types.StorageDomain(id=sd.id, ),
                          discard_snapshots=True,
                          async=True)
Пример #30
0
 def import_template(self, edomain, sdomain, cluster, temp_template):
     export_sd_service = self._get_storage_domain_service(edomain)
     export_template = self.get_template_from_storage_domain(
         temp_template, edomain)
     target_storage_domain = self._get_storage_domain(sdomain)
     cluster_id = self._get_cluster(cluster).id
     sd_template_service = export_sd_service.templates_service(
     ).template_service(export_template.id)
     sd_template_service.import_(
         storage_domain=types.StorageDomain(id=target_storage_domain.id),
         cluster=types.Cluster(id=cluster_id),
         template=types.Template(id=export_template.id))