示例#1
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 = types.Storage(type_=storage_type,
                                       address=address,
                                       path=path)

        storage_domain__params = types.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)))
def add_iscsi_storage_domain(prefix):
    # FIXME
    # if API_V4:
    #    return add_iscsi_storage_domain_4(prefix)

    api = prefix.virt_env.engine_vm().get_api_v4()

    # 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 = types.StorageDomain(
        name=SD_ISCSI_NAME,
        data_center=types.DataCenter(name=DC_NAME, ),
        type_='data',
        storage_format=SD_FORMAT,
        host=_random_host_from_dc_4(api, DC_NAME),
        storage=types.Storage(
            type_='iscsi',
            volume_group=types.VolumeGroup(logical_unit=[
                types.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)