コード例 #1
0
    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
コード例 #2
0
 def build_entity(self):
     return otypes.Quota(
         description=self._module.params['description'],
         name=self._module.params['name'],
         storage_hard_limit_pct=self._module.params.get('storage_grace'),
         storage_soft_limit_pct=self._module.params.get('storage_threshold'),
         cluster_hard_limit_pct=self._module.params.get('cluster_grace'),
         cluster_soft_limit_pct=self._module.params.get('cluster_threshold'),
     )
コード例 #3
0
def test_add_dc_quota(engine_api, ost_dc_name):
    datacenters_service = engine_api.system_service().data_centers_service()
    datacenter = datacenters_service.list(search='name=%s' % ost_dc_name)[0]
    datacenter_service = datacenters_service.data_center_service(datacenter.id)
    quotas_service = datacenter_service.quotas_service()
    assert quotas_service.add(
        types.Quota(name=DC_QUOTA_NAME,
                    description='DC-QUOTA-DESCRIPTION',
                    data_center=datacenter,
                    cluster_soft_limit_pct=99))
コード例 #4
0
def add_dc_quota(api):
    datacenters_service = api.system_service().data_centers_service()
    datacenter = datacenters_service.list(search='name=%s' % DC_NAME)[0]
    datacenter_service = datacenters_service.data_center_service(datacenter.id)
    quotas_service = datacenter_service.quotas_service()
    nt.assert_true(
        quotas_service.add(
            types.Quota(name=DC_QUOTA_NAME,
                        description='DC-QUOTA-DESCRIPTION',
                        data_center=datacenter,
                        cluster_soft_limit_pct=99)))
コード例 #5
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,
            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=convert_to_bytes(
                self._module.params.get('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'),
            wipe_after_delete=self.param('wipe_after_delete'),
            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') and self._module.params['upload_image_path']:
            disk.initial_size = convert_to_bytes(
                self._module.params.get('size')
            )

        return disk
コード例 #6
0
def add_quota_storage_limits(api):

    # Find the data center and the service that manages it:
    dcs_service = api.system_service().data_centers_service()
    dc = dcs_service.list(search='name=%s' % DC_NAME)[0]
    dc_service = dcs_service.data_center_service(dc.id)

    # Find the storage domain and the service that manages it:
    sds_service = api.system_service().storage_domains_service()
    sd = sds_service.list()[0]

    # Find the quota and the service that manages it.
    # If the quota doesn't exist,create it.
    quotas_service = dc_service.quotas_service()
    quotas = quotas_service.list()

    quota = next((q for q in quotas if q.name == DC_QUOTA_NAME), None)
    if quota is None:
        quota = quotas_service.add(
            quota=types.Quota(name=DC_QUOTA_NAME,
                              description='DC-QUOTA-DESCRIPTION',
                              cluster_hard_limit_pct=20,
                              cluster_soft_limit_pct=80,
                              storage_hard_limit_pct=20,
                              storage_soft_limit_pct=80))
    quota_service = quotas_service.quota_service(quota.id)

    # Find the quota limit for the storage domain that we are interested on:
    limits_service = quota_service.quota_storage_limits_service()
    limits = limits_service.list()
    limit = next((l for l in limits if l.id == sd.id), None)

    # If that limit exists we will delete it:
    if limit is not None:
        limit_service = limits_service.limit_service(limit.id)
        limit_service.remove()

    # Create the limit again, with the desired value
    nt.assert_true(
        limits_service.add(limit=types.QuotaStorageLimit(limit=500, )))
コード例 #7
0
    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'):
            out = subprocess.check_output(
                ["qemu-img", "info", "--output", "json", self._module.params.get('upload_image_path')])
            image_info = json.loads(out)
            size = image_info["virtual-size"]
        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']:
            out = subprocess.check_output([
                'qemu-img',
                'measure',
                '-O', 'qcow2' if self._module.params.get('format') == 'cow' else 'raw',
                '--output', 'json',
                self._module.params['upload_image_path']
            ])
            measure = json.loads(out)
            disk.initial_size = measure["required"]

        return disk
コード例 #8
0
# Find the storage domain and the service that manages it:
sds_service = system_service.storage_domains_service()
sd = sds_service.list(search='name=mydata')[0]
sd_service = sds_service.storage_domain_service(sd.id)

# Find the quota and the service that manages it. Note that the service
# that manages the quota doesn't support search, so we need to retrieve
# all the quotas and filter explicitly. If the quota doesn't exist,
# create it.
quotas_service = dc_service.quotas_service()
quotas = quotas_service.list()
quota = next((q for q in quotas if q.name == 'myquota'), None)
if quota is None:
    quota = quotas_service.add(quota=types.Quota(name='myquota',
                                                 description='My quota',
                                                 cluster_hard_limit_pct=20,
                                                 cluster_soft_limit_pct=80,
                                                 storage_hard_limit_pct=20,
                                                 storage_soft_limit_pct=80))
quota_service = quotas_service.quota_service(quota.id)

# Find the quota limit for the storage domain that we are interested on:
limits_service = quota_service.quota_storage_limits_service()
limits = limits_service.list()
limit = next((l for l in limits if l.id == sd.id), None)

# If that limit exists we will delete it:
if limit is not None:
    limit_service = limits_service.limit_service(limit.id)
    limit_service.remove()

# Create the limit again, with the desired value, in this example it will