コード例 #1
0
def hotplug_disk(api):
    disk2_params = params.Disk(
        name=DISK1_NAME,
        size=9 * GB,
        provisioned_size=2,
        interface='virtio',
        format='cow',
        storage_domains=params.StorageDomains(
            storage_domain=[
                params.StorageDomain(
                    name='iscsi',
                ),
            ],
        ),
        status=None,
        sparse=True,
        bootable=False,
        active=True,
    )
    api.vms.get(VM0_NAME).disks.add(disk2_params)

    testlib.assert_true_within_short(
        lambda:
        api.vms.get(VM0_NAME).disks.get(DISK1_NAME).status.state == 'ok'
    )
    nt.assert_true(api.vms.get(VM0_NAME).disks.get(DISK1_NAME).active)
コード例 #2
0
 def on_ok(self):
     self.warn.hidden = False
     self.display()
     api = self.parentApp.api
     param = params.StorageDomain(
         name=self.storageName.value,
         type_='data',
         host=api.hosts.get(name=self.hosts.get_selected_objects()[0]),
         storage=params.StorageConnection(
             type_=self.storageTypes.get_selected_objects()[0],
             address=self.url.value.split(':')[0],
             path=self.url.value.split(':')[1]))
     try:
         sd = api.storagedomains.add(param)
         api.datacenters.get(self.datacenters.get_selected_objects()
                             [0]).storagedomains.add(sd)
         self.warn.hidden = True
         self.display()
         self.onImportPopup(
             'Success',
             'The storage domain has been imported successfully!', None)
     except Exception as e:
         if hasattr(e, 'detail'):
             error = 'Error: ' + e.detail
         else:
             error = 'Error: %s' % e
         self.onImportPopup('Error', None, error)
コード例 #3
0
def addStorageDomain():
    global controller
    logging.debug("Adding local storage domain")

    # strip last '/' from path if it's given. Otherwise, adding storage will
    # fail.
    try:
        logging.info("Creating local storage")
        stParams = params.Storage(
            path=controller.CONF["STORAGE_PATH"].rstrip('/'))
        stParams.set_type('localfs')

        logging.info("Creating local storage domain")
        sdParams = params.StorageDomain(
            name=LOCAL_STORAGE,
            data_center=controller.CONF["API_OBJECT"].datacenters.get(
                LOCAL_DATA_CENTER),
            storage_format='v1',
            host=controller.CONF["API_OBJECT"].hosts.get(LOCAL_HOST),
            storage=stParams)
        sdParams.set_type('data')

        logging.info("Adding local storage domain")
        controller.CONF["API_OBJECT"].storagedomains.add(sdParams)
    except:
        logging.error(traceback.format_exc())
        raise Exception(ERROR_ADD_LOCAL_DOMAIN)
コード例 #4
0
def generic_import_from_glance(api, image_name=CIRROS_IMAGE_NAME, as_template=False, image_ext='_glance_disk', template_ext='_glance_template', dest_storage_domain=MASTER_SD_TYPE, dest_cluster=CLUSTER_NAME):
    glance_provider = api.storagedomains.get(SD_GLANCE_NAME)
    target_image = glance_provider.images.get(name=image_name)
    disk_name = image_name.replace(" ", "_") + image_ext
    template_name = image_name.replace(" ", "_") + template_ext
    import_action = params.Action(
        storage_domain=params.StorageDomain(
            name=dest_storage_domain,
        ),
        cluster=params.Cluster(
            name=dest_cluster,
        ),
        import_as_template=as_template,
        disk=params.Disk(
            name=disk_name,
        ),
        template=params.Template(
            name=template_name,
        ),
    )

    nt.assert_true(
        target_image.import_image(import_action)
    )

    testlib.assert_true_within_long(
        lambda: api.disks.get(disk_name).status.state == 'ok',
    )
コード例 #5
0
def add_iscsi_storage_domain_3(prefix, lun_guids):
    api = prefix.virt_env.engine_vm().get_api()

    ips = _get_host_all_ips(prefix, SD_ISCSI_HOST_NAME)
    luns = []
    for lun_id in lun_guids:
        for ip in ips:
            lun = params.LogicalUnit(
                id=lun_id,
                address=ip,
                port=SD_ISCSI_PORT,
                target=SD_ISCSI_TARGET,
                username='******',
                password='******',
            )
            luns.append(lun)

    p = params.StorageDomain(
        name=SD_ISCSI_NAME,
        data_center=params.DataCenter(name=DC_NAME, ),
        type_='data',
        storage_format=SD_FORMAT,
        host=_random_host_from_dc(api, DC_NAME),
        storage=params.Storage(
            type_='iscsi',
            volume_group=params.VolumeGroup(logical_unit=luns),
        ),
    )
    _add_storage_domain_3(api, p)
コード例 #6
0
def import_template_from_glance(api, sdomain, cluster, temp_template_name,
                                glance_server, provider, template_name):
    try:
        if api.templates.get(temp_template_name) is not None:
            logger.info(
                "RHEVM:%r Warning: found another template with this name.",
                provider)
            logger.info(
                "RHEVM:%r Skipping this step, attempting to continue...",
                provider)
            return

        # Find the storage domain:
        sd = api.storagedomains.get(name=glance_server)

        # Find the image:
        image = sd.images.get(name=template_name)

        # Import the image:
        image.import_image(
            params.Action(async=True,
                          import_as_template=True,
                          template=params.Template(name=temp_template_name),
                          cluster=params.Cluster(name=cluster),
                          storage_domain=params.StorageDomain(name=sdomain)))
コード例 #7
0
def add_iscsi_storage_domain(prefix):
    api = prefix.virt_env.engine_vm().get_api()

    # Find LUN GUIDs
    ret = prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ssh(
        ['cat', '/root/multipath.txt'])
    nt.assert_equals(ret.code, 0)

    lun_guids = ret.out.splitlines()[:SD_ISCSI_NR_LUNS]

    p = params.StorageDomain(
        name=SD_ISCSI_NAME,
        data_center=params.DataCenter(name=DC_NAME, ),
        type_='data',
        storage_format=SD_FORMAT,
        host=_random_host_from_dc(api, DC_NAME),
        storage=params.Storage(
            type_='iscsi',
            volume_group=params.VolumeGroup(logical_unit=[
                params.LogicalUnit(
                    id=lun_id,
                    address=_get_host_ip(
                        prefix,
                        SD_ISCSI_HOST_NAME,
                    ),
                    port=SD_ISCSI_PORT,
                    target=SD_ISCSI_TARGET,
                    username='******',
                    password='******',
                ) for lun_id in lun_guids
            ]),
        ),
    )
    _add_storage_domain(api, p)
コード例 #8
0
def add_iscsi_storage_domain(prefix):
    api = prefix.virt_env.engine_vm().get_api()

    # Find LUN GUIDs
    ret = prefix.virt_env.get_vm('storage-iscsi').ssh(['multipath', '-ll'], )
    nt.assert_equals(ret.code, 0)

    lun_guids = [
        line.split()[0] for line in ret.out.split('\n')
        if line.find('LIO-ORG') != -1
    ]

    lun_guids = lun_guids[:SD_ISCSI_NR_LUNS]

    p = params.StorageDomain(
        name=SD_ISCSI_NAME,
        data_center=params.DataCenter(name=DC_NAME, ),
        type_='data',
        storage_format='v3',
        host=params.Host(name=api.hosts.list().pop().name, ),
        storage=params.Storage(
            type_='iscsi',
            volume_group=params.VolumeGroup(logical_unit=[
                params.LogicalUnit(
                    id=lun_id,
                    address=SD_ISCSI_ADDRESS,
                    port=SD_ISCSI_PORT,
                    target=SD_ISCSI_TARGET,
                ) for lun_id in lun_guids
            ]),
        ),
    )
    _add_storage_domain(api, p)
コード例 #9
0
def add_iscsi_storage_domain(prefix):
    api = prefix.virt_env.engine_vm().get_api()

    # Find LUN GUIDs
    ret = prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ssh(
        ['multipath', '-ll', '-v1', '|sort'])
    nt.assert_equals(ret.code, 0)

    lun_guids = ret.out.splitlines()[:SD_ISCSI_NR_LUNS]

    p = params.StorageDomain(
        name=SD_ISCSI_NAME,
        data_center=params.DataCenter(name=DC_NAME, ),
        type_='data',
        storage_format='v3',
        host=params.Host(name=api.hosts.list().pop().name, ),
        storage=params.Storage(
            type_='iscsi',
            volume_group=params.VolumeGroup(logical_unit=[
                params.LogicalUnit(
                    id=lun_id,
                    address=_get_host_ip(
                        prefix,
                        SD_ISCSI_HOST_NAME,
                    ),
                    port=SD_ISCSI_PORT,
                    target=SD_ISCSI_TARGET,
                ) for lun_id in lun_guids
            ]),
        ),
    )
    _add_storage_domain(api, p)
コード例 #10
0
    def execute(self, args):
        # Access newly created storage domain
        local_sd = self._api.storagedomains.get(args.name)

        # Find datacenter object
        local_dc = self._api.datacenters.get(args.datacenter)

        # Find host object
        local_host = self._api.hosts.get(args.host)

        # Build storage parameter
        stParams = params.Storage(path=args.path,
                                  address=args.server,
                                  type_=args.type)

        # Build storage domain parameter
        sdParams = params.StorageDomain(
            name=args.name,  #'local_export',
            data_center=local_dc,
            host=local_host,
            type_='export',
            storage=stParams,
            storage_format='v1')

        if self._api.storagedomains.add(sdParams):
            print 'Export Domain was created/imported successfully'

        # Access newly created storage domain
        local_sd = self._api.storagedomains.get(args.name)
コード例 #11
0
def add_disk(api):
    glance_disk = api.disks.get(GLANCE_DISK_NAME)
    if glance_disk:
        nt.assert_true(
            api.vms.get(VM0_NAME).disks.add(
                params.Disk(
                    id=glance_disk.get_id(),
                    active=True,
                    bootable=True,
                )))

    disk_params = params.Disk(
        name=DISK1_NAME,
        size=10 * GB,
        provisioned_size=1,
        interface='virtio',
        format='cow',
        storage_domains=params.StorageDomains(storage_domain=[
            params.StorageDomain(name='nfs', ),
        ], ),
        status=None,
        sparse=True,
        active=True,
        bootable=True,
    )
    nt.assert_true(api.vms.get(VM1_NAME).disks.add(disk_params))

    if glance_disk:
        testlib.assert_true_within_short(lambda: api.vms.get(
            VM0_NAME).disks.get(GLANCE_DISK_NAME).status.state == 'ok')
    testlib.assert_true_within_short(lambda: api.vms.get(VM1_NAME).disks.get(
        DISK1_NAME).status.state == 'ok')
コード例 #12
0
def add_disk_to_vm(api, sdomain, disk_size, disk_format, disk_interface, temp_vm_name,
                   provider):
    """Adds second disk to a temporary VM.

    Args:
        api: API to chosen RHEVM provider.
        sdomain: Storage domain to save new disk onto.
        disk_size: Size of the new disk (in B).
        disk_format: Format of the new disk.
        disk_interface: Interface of the new disk.
    """
    try:
        if len(api.vms.get(temp_vm_name).disks.list()) > 1:
            logger.info("RHEVM:%r Warning: found more than one disk in existing VM (%r).",
                    provider, temp_vm_name)
            logger.info("RHEVM:%r Skipping this step, attempting to continue...", provider)
            return
        actual_sdomain = api.storagedomains.get(sdomain)
        temp_vm = api.vms.get(temp_vm_name)
        storage_id = params.StorageDomains(storage_domain=[params.StorageDomain
            (id=actual_sdomain.get_id())])
        params_disk = params.Disk(storage_domains=storage_id, size=disk_size,
                                  interface=disk_interface, format=disk_format)
        temp_vm.disks.add(params_disk)

        wait_for(check_disks, [api, temp_vm_name], fail_condition=False, delay=5, num_sec=900)

        # check, if there are two disks
        if len(api.vms.get(temp_vm_name).disks.list()) < 2:
            logger.error("RHEVM:%r Disk failed to add", provider)
            sys.exit(127)
        logger.info("RHEVM:%r Successfully added disk", provider)
    except Exception:
        logger.exception("RHEVM:%r add_disk_to_temp_vm failed:", provider)
コード例 #13
0
    def clone_snapshot(api, config, vm_from_list):
        """
        Clone snapshot into a new vm
        :param api: ovirtsdk api
        :param config: Configuration
	:vm: VM to clone
        """
        vm_clone_name = vm_from_list + config.get_vm_middle() + config.get_vm_suffix()
        vm = api.vms.get(vm_from_list)
        snapshots = vm.snapshots.list(description=config.get_snapshot_description())
        if not snapshots:
            logger.error("!!! No snapshot found !!!")
            has_errors = True
        snapshot=snapshots[0]

        # Find the storage domain where the disks should be created:
        sd = api.storagedomains.get(name=config.get_destination_domain())

        # Find the image identifiers of the disks of the snapshot, as
        # we need them in order to explicitly indicate that we want
        # them created in a different storage domain:
        disk_ids = []
        for current in snapshot.disks.list():
            disk_ids.append(current.get_id())
        # Prepare the list of disks for the operation to create the
        # snapshot,explicitly indicating for each of them the storage
        # domain where it should be created:
        disk_list = []
        for disk_id in disk_ids:
            disk = params.Disk(
                image_id=disk_id,
                storage_domains=params.StorageDomains(
                  storage_domain=[
                    params.StorageDomain(
                      id=sd.get_id(),
                    ),
                  ],
                ),
            )
            disk_list.append(disk)

        snapshot_param = params.Snapshot(id=snapshot.id)
        snapshots_param = params.Snapshots(snapshot=[snapshot_param])
        logger.info("Clone into VM (%s) started ..." % vm_clone_name)
        if not config.get_dry_run():
            api.vms.add(params.VM(
                            name=vm_clone_name,
                            memory=vm.get_memory(),
                            cluster=api.clusters.get(config.get_cluster_name()),
                            snapshots=snapshots_param,
                            disks=params.Disks(
                               disk=disk_list,
                            )
                        )
            )
            VMTools.wait_for_vm_operation(api, config, "Cloning", vm_from_list)
        logger.info("Cloning finished")
コード例 #14
0
def add_iso_storage_domain(api):
    p = params.StorageDomain(
        name=SD_ISO_NAME,
        data_center=params.DataCenter(name=DC_NAME, ),
        type_='iso',
        host=params.Host(name=api.hosts.list().pop().name, ),
        storage=params.Storage(
            type_='nfs',
            address=SD_ISO_ADDRESS,
            path=SD_ISO_PATH,
        ),
    )
    _add_storage_domain(api, p)
コード例 #15
0
    def attach_iso_export_domain_into_datacenter(self,
                                                 address,
                                                 path,
                                                 dc_name,
                                                 host_name,
                                                 domain_type,
                                                 storage_type='nfs',
                                                 name='my_iso'):
        """
        Attach ISO/export domain into data center.

        :param name: ISO or Export name.
        :param host_name: host name.
        :param dc_name: data center name.
        :param path: ISO/export domain path.
        :param address: ISO/export domain address.
        :param domain_type: storage domain type, it may be 'iso' or 'export'.
        :param storage_type: storage type, it may be 'nfs', 'iscsi', or 'fc'.
        """
        dc = self.api.datacenters.get(dc_name)
        host = self.api.hosts.get(host_name)
        storage_params = param.Storage(type_=storage_type,
                                       address=address,
                                       path=path)

        storage_domain__params = param.StorageDomain(name=name,
                                                     data_center=dc,
                                                     type_=domain_type,
                                                     host=host,
                                                     storage=storage_params)

        try:
            logging.info('Create/import ISO storage domain %s' % name)
            if self.api.storagedomains.add(storage_domain__params):
                logging.info('%s domain was created/imported successfully' %
                             domain_type)

            logging.info('Attach ISO storage domain %s' % name)
            if self.api.datacenters.get(dc_name).storagedomains.add(
                    self.api.storagedomains.get(name)):
                logging.info('%s domain was attached successfully' %
                             domain_type)

            logging.info('Activate ISO storage domain %s' % name)
            if self.api.datacenters.get(dc_name).storagedomains.get(
                    name).activate():
                logging.info('%s domain was activated successfully' %
                             domain_type)
        except Exception as e:
            logging.error('Failed to add %s domain:\n%s' %
                          (domain_type, str(e)))
コード例 #16
0
def add_iso_storage_domain(prefix):
    api = prefix.virt_env.engine_vm().get_api()
    p = params.StorageDomain(
        name=SD_ISO_NAME,
        data_center=params.DataCenter(name=DC_NAME, ),
        type_='iso',
        host=params.Host(name=api.hosts.list().pop().name, ),
        storage=params.Storage(
            type_='nfs',
            address=_get_host_ip(prefix, SD_ISO_HOST_NAME),
            path=SD_ISO_PATH,
        ),
    )
    _add_storage_domain(api, p)
コード例 #17
0
def add_templates_storage_domain(api):
    p = params.StorageDomain(
        name=SD_TEMPLATES_NAME,
        data_center=params.DataCenter(name=DC_NAME, ),
        type_='data',
        storage_format='v3',
        host=params.Host(name=api.hosts.list().pop().name),
        storage=params.Storage(
            type_='nfs',
            address=SD_TEMPLATES_ADDRESS,
            path=SD_TEMPLATES_PATH,
        ),
    )
    _add_storage_domain(api, p)
コード例 #18
0
def ovirt_create_storage(module):

    name = module.params['name']
    datacenter = module.params['datacenter']
    host = module.params['host']
    path = module.params['path']
    type = module.params['type']
    storage_type = module.params['storage_type']
    storage_url = module.params['storage_url']
    username = module.params['username']
    password = module.params['password']
    url = module.params['url']

    try:
        api = API(url=url,
                  username=username,
                  password=password,
                  insecure=True,
                  session_timeout=60)
    except Exception as ex:
        module.fail_json(msg='could not connect to ovirt api')

    isoParams = params.StorageDomain(
        name=name,
        data_center=api.datacenters.get(datacenter),
        type_=storage_type,
        host=api.hosts.get(host),
        storage=params.Storage(
            type_=type,
            address=storage_url,
            path=path,
        ))

    if api.datacenters.get(datacenter).storagedomains.get(name):
        module.exit_json(changed=False)

    if module.check_mode:
        module.exit_json(changed=True)

    try:
        sd = api.storagedomains.add(isoParams)
        api.datacenters.get(datacenter).storagedomains.add(
            api.storagedomains.get(name))
    except Exception as ex:
        module.fail_json(msg='Adding storage domain failed' + str(ex))

    module.exit_json(changed=True)
コード例 #19
0
def createStorageDomain(api, host, name, path):
    print 'Creating storage domain'
    storageDomain = api.storagedomains.get(name)
    if storageDomain is None:
        storageDomain = api.storagedomains.add(
            params.StorageDomain(name=name,
                                 host=host,
                                 type_='data',
                                 storage=params.HostStorage(
                                     type_='nfs',
                                     address='192.168.122.1',
                                     path=path,
                                     nfs_version="V4")))
        print 'Storage domain created'
    else:
        print 'Storage domain already exists'
    return storageDomain
コード例 #20
0
def add_disk(api):
    disk_params = params.Disk(
        name=DISK0_NAME,
        size=10 * GB,
        provisioned_size=1,
        interface='virtio',
        format='cow',
        storage_domains=params.StorageDomains(storage_domain=[
            params.StorageDomain(name=MASTER_SD_NAME, ),
        ], ),
        status=None,
        sparse=True,
        bootable=True,
    )
    api.vms.get(VM0_NAME).disks.add(disk_params)
    testlib.assert_true_within_short(lambda: api.vms.get(VM0_NAME).disks.get(
        DISK0_NAME).status.state == 'ok')
コード例 #21
0
def add_generic_nfs_storage_domain_3(prefix, sd_nfs_name, nfs_host_name, mount_path, sd_format=SD_FORMAT, sd_type='data', nfs_version='v4_1'):
    api = prefix.virt_env.engine_vm().get_api()
    p = params.StorageDomain(
        name=sd_nfs_name,
        data_center=params.DataCenter(
            name=DC_NAME,
        ),
        type_=sd_type,
        storage_format=sd_format,
        host=_random_host_from_dc(api, DC_NAME),
        storage=params.Storage(
            type_='nfs',
            address=_get_host_ip(prefix, nfs_host_name),
            path=mount_path,
            nfs_version=nfs_version,
        ),
    )
    _add_storage_domain_3(api, p)
コード例 #22
0
def create_nfs_storage(api, spm, storage_type):
    # TODO : make a better function with dynamic storage selection
    # for making it simple the type and the name are the same
    storage_formats = {'data': 'V3', 'export': 'V1'}

    storage_params = params.StorageDomain(name=storage_type,
                                          data_center=api.datacenters.get(
                                              "Default"),
                                          storage_format=storage_formats[
                                              storage_type],
                                          type_=storage_type,
                                          host=spm,
                                          storage=params.Storage(type_="NFS",
                                                                 address="192.168.100.100",
                                                                 path='/' + storage_type))
    api.storagedomains.add(storage_params)
    api.datacenters.get(name="Default").storagedomains.add(
        api.storagedomains.get(name=storage_type))
コード例 #23
0
def add_generic_nfs_storage_domain(prefix, sd_nfs_name, nfs_host_name, mount_path, sd_format='v3', sd_type='data'):
    api = prefix.virt_env.engine_vm().get_api()
    p = params.StorageDomain(
        name=sd_nfs_name,
        data_center=params.DataCenter(
            name=DC_NAME,
        ),
        type_=sd_type,
        storage_format=sd_format,
        host=params.Host(
            name=api.hosts.list().pop().name,
        ),
        storage=params.Storage(
            type_='nfs',
            address=_get_host_ip(prefix, nfs_host_name),
            path=mount_path,
        ),
    )
    _add_storage_domain(api, p)
コード例 #24
0
def generic_import_from_glance(glance_provider,
                               image_name=CIRROS_IMAGE_NAME,
                               as_template=False,
                               image_ext='_glance_disk',
                               template_ext='_glance_template',
                               dest_storage_domain=MASTER_SD_TYPE,
                               dest_cluster=CLUSTER_NAME):
    target_image = glance_provider.images.get(name=image_name)
    disk_name = image_name.replace(" ", "_") + image_ext
    template_name = image_name.replace(" ", "_") + template_ext
    import_action = params.Action(
        storage_domain=params.StorageDomain(name=dest_storage_domain, ),
        cluster=params.Cluster(name=dest_cluster, ),
        import_as_template=as_template,
        disk=params.Disk(name=disk_name, ),
        template=params.Template(name=template_name, ),
    )

    nt.assert_true(target_image.import_image(import_action))
コード例 #25
0
def add_glusterfs_storage_domain(prefix, sdname, volname):
    api = prefix.virt_env.engine_vm().get_api()
    hosts = sorted([vm.name() for vm in prefix.virt_env.host_vms()])
    mount_path = "{0}://{1}".format(hosts[0], volname)
    mount_options = "backup-volfile-servers={0}".format(':'.join(hosts[1:]))

    p = params.StorageDomain(
        name=sdname,
        data_center=params.DataCenter(name=DC_NAME, ),
        type_='data',
        storage_format='v3',
        host=_random_host_from_dc(api, DC_NAME),
        storage=params.Storage(
            type_='glusterfs',
            path=mount_path,
            vfs_type='glusterfs',
            mount_options=mount_options,
        ),
    )
    _add_storage_domain(api, p)
コード例 #26
0
def hotplug_disk(api):
    disk2_params = params.Disk(
        name=DISK1_NAME,
        size=10 * GB,
        provisioned_size=1,
        interface='virtio',
        format='cow',
        storage_domains=params.StorageDomains(storage_domain=[
            params.StorageDomain(name='nfs', ),
        ], ),
        status=None,
        sparse=True,
        bootable=False,
    )
    api.vms.get(VM1_NAME).disks.add(disk2_params)
    testlib.assert_true_within(
        func=(lambda: api.vms.get(VM1_NAME, ).disks.get(DISK1_NAME).status.
              state == 'ok'),
        timeout=SHORT_TIMEOUT,
    )
コード例 #27
0
def add_glusterfs_storage_domain(prefix, sdname, volname):
    api = prefix.virt_env.engine_vm().get_api()
    mount_path = "{0}://{1}".format(_get_host_ip(prefix, GLUSTER_HOST0),
                                    volname)
    mount_options = "backup-volfile-servers={0}:{1}".format(
        _get_host_ip(prefix, GLUSTER_HOST1),
        _get_host_ip(prefix, GLUSTER_HOST2))
    p = params.StorageDomain(
        name=sdname,
        data_center=params.DataCenter(name=DC_NAME, ),
        type_='data',
        storage_format='v3',
        host=_random_host_from_dc(api, DC_NAME),
        storage=params.Storage(
            type_='glusterfs',
            path=mount_path,
            vfs_type='glusterfs',
            mount_options=mount_options,
        ),
    )
    _add_storage_domain(api, p)
コード例 #28
0
def add_disk(api):
    glance_disk = api.disks.get(GLANCE_DISK_NAME)
    if glance_disk:
        nt.assert_true(
            api.vms.get(VM0_NAME).disks.add(
                params.Disk(
                    id=glance_disk.get_id(),
                    active=True,
                    bootable=True,
                )))

    disk_params = params.Disk(
        size=10 * GB,
        provisioned_size=1,
        interface='virtio',
        format='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 = params.StorageDomains(storage_domain=[
            params.StorageDomain(name=sd_name, ),
        ])
        nt.assert_true(api.vms.get(vm_name).disks.add(disk_params))

    if glance_disk:
        testlib.assert_true_within_short(lambda: api.vms.get(
            VM0_NAME).disks.get(GLANCE_DISK_NAME).status.state == 'ok')
    for vm_name, disk_name in ((VM1_NAME, DISK1_NAME), (VM2_NAME, DISK2_NAME)):
        testlib.assert_true_within_short(lambda: api.vms.get(vm_name).disks.
                                         get(disk_name).status.state == 'ok')
コード例 #29
0
    def makeTemplate(self, name, comments, machineId, clusterId, storageId,
                     displayType):
        '''
        Publish the machine (makes a template from it so we can create COWs) and returns the template id of
        the creating machine

        Args:
            name: Name of the machine (care, only ascii characters and no spaces!!!)
            machineId: id of the machine to be published
            clusterId: id of the cluster that will hold the machine
            storageId: id of the storage tuat will contain the publication AND linked clones
            displayType: type of display (for oVirt admin interface only)

        Returns
            Raises an exception if operation could not be acomplished, or returns the id of the template being created.
        '''
        logger.debug(
            "n: {0}, c: {1}, vm: {2}, cl: {3}, st: {4}, dt: {5}".format(
                name, comments, machineId, clusterId, storageId, displayType))

        try:
            lock.acquire(True)

            api = self.__getApi()

            cluster = api.clusters.get(id=clusterId)
            vm = api.vms.get(id=machineId)

            if vm is None:
                raise Exception('Machine not found')

            if cluster is None:
                raise Exception('Cluster not found')

            if vm.get_status().get_state() != 'down':
                raise Exception('Machine must be in down state to publish it')

            print(vm.disks.list())

            # Create disks description to be created in specified storage domain, one for each disk
            sd = params.StorageDomains(
                storage_domain=[params.StorageDomain(id=storageId)])

            fix = not self._isFullyFunctionalVersion(api)[
                0]  # If we need a fix for "publish"

            dsks = []
            for dsk in vm.disks.list():
                dsks.append(
                    params.Disk(id=dsk.get_id(),
                                storage_domains=sd,
                                alias=dsk.get_alias()))
                # dsks.append(dsk)

            disks = params.Disks(disk=dsks)

            # Create display description
            # display = params.Display(type_=displayType)

            # TODO: Restore proper template creation mechanism
            if fix is True:
                vm = params.VM(id=vm.get_id())
            else:
                vm = params.VM(id=vm.get_id(), disks=disks)

            template = params.Template(
                name=name,
                vm=vm,
                cluster=params.Cluster(id=cluster.get_id()),
                description=comments)

            # display=display)

            return api.templates.add(template).get_id()
        finally:
            lock.release()
コード例 #30
0
    output.write(CERT.read())
    output.close()

api = API(url=URL, username=USERNAME, password=PASSWORD, ca_file=CA)

try:

    dc = api.datacenters.get(name="Default")
    h = api.hosts.get(name=HOST_NAME)

    s = params.Storage(address="192.168.103.1",
                       path="/srv/rhev-sd1",
                       type_="nfs")
    sd_params = params.StorageDomain(name=STORAGE_NAME,
                                     data_center=dc,
                                     host=h,
                                     type_="data",
                                     storage_format="v3",
                                     storage=s)

    try:
        for sd in api.storagedomains.list():
            print sd.name
    except Exception as ex:
        print "Problem listing storage domains %s." % ex
        sys.exit(2)

#    api.disconnect()

except Exception as ex:
    print "Unexpected error: %s" % ex