コード例 #1
0
ファイル: volumes.py プロジェクト: 1026237416/Python
 def execute(self):
     try:
         tenant_id = self._message.get('tenant_id')
         volume_os_used = yield volume_real_used(tenant_id)
         yield update_quota_used(tenant_id, QUOTA_NAMES.disks,
                                 volume_os_used.get('count'))
         yield update_quota_used(tenant_id, QUOTA_NAMES.disk_capacity,
                                 volume_os_used.get('used_size'))
     except Exception, e:
         LOG.error("delele disk error %s" % e)
コード例 #2
0
def update_tenant_vm_quotas(tenant_id, used_cores, used_memory):
    """ update tenant 's quotas of vm
    :param tenant_id: id of tenant
    :param used_cores: current cores usage
    :param used_memory; current memory usage
    """
    if used_cores is not None:
        yield update_quota_used(tenant_id=tenant_id,
                                name=QUOTA_NAMES.cores,
                                used=used_cores)
    if used_memory is not None:
        yield update_quota_used(tenant_id=tenant_id,
                                name=QUOTA_NAMES.memory,
                                used=used_memory)
コード例 #3
0
ファイル: volumes.py プロジェクト: 1026237416/Python
def create_volume(**volume):
    """ create volume
    :param volume: A dict of volume
    :return:
    """
    if is_none_or_empty(volume['volume_type']):
        volume['volume_type'] = CONF.storage.default_type
    volume_project = volume['tenant_id']
    volume_size = calc_size(volume['size'])
    volume_num = volume['num']
    if volume['volume_type'] == "lvm":
        volume_num = 1

    disk_capacity = yield get_quota(volume_project, QUOTA_NAMES.disk_capacity)
    disks = yield get_quota(volume_project, QUOTA_NAMES.disks)

    used_disks = disks.get("quota_used")
    used_disk_capacity = disk_capacity.get("quota_used")

    used_disks += volume_num
    used_disk_capacity += volume_size * volume_num

    yield check_quota(volume_project,
                      QUOTA_NAMES.disks,
                      used_disks)
    yield check_quota(volume_project,
                      QUOTA_NAMES.disk_capacity,
                      used_disk_capacity)

    yield update_quota_used(volume_project, QUOTA_NAMES.disks,
                            used_disks)
    yield update_quota_used(volume_project, QUOTA_NAMES.disk_capacity,
                            used_disk_capacity)

    try:
        volume_name = yield number_seq("volume-sequence", "vd-")
        names = []
        for i in range(1, volume_num + 1):
            if volume_num > 1:
                name = str(volume_name) + "-" + str(i)
            else:
                name = volume_name
            names.append(name)
            metadata = {"des": "" if is_none_or_empty(volume['des']) else volume['des'],
                        "user": "" if is_none_or_empty(volume['user_id']) else volume['user_id'],
                        "displayname": "" if is_none_or_empty(volume['displayname']) else volume['displayname']}

            yield volume_create(size=volume_size,
                                tenant_id=volume_project,
                                snapshot_id=None,
                                source_volid=volume['source_volid'],
                                name=name,
                                description=str(0),
                                volume_type=volume['volume_type'],
                                source_replica=None,
                                metadata=metadata,
                                project_id=volume['tenant_id'],
                                image_ref=volume['image_ref'],
                                availability_zone=volume["host"])
    except Exception, e:
        LOG.error("create volume error: %s" % e)
        raise VolumeOperationFailed()
コード例 #4
0
ファイル: volumes.py プロジェクト: 1026237416/Python
                                snapshot_id=None,
                                source_volid=volume['source_volid'],
                                name=name,
                                description=str(0),
                                volume_type=volume['volume_type'],
                                source_replica=None,
                                metadata=metadata,
                                project_id=volume['tenant_id'],
                                image_ref=volume['image_ref'],
                                availability_zone=volume["host"])
    except Exception, e:
        LOG.error("create volume error: %s" % e)
        raise VolumeOperationFailed()
    finally:
        volume_os_used = yield volume_real_used(volume_project)
        yield update_quota_used(volume_project, QUOTA_NAMES.disks,
                                volume_os_used.get('count'))
        yield update_quota_used(volume_project, QUOTA_NAMES.disk_capacity,
                                volume_os_used.get('used_size'))
    raise gen.Return({"batch_name": volume_name, "names": names})


@gen.coroutine
@required("volume_id")
def update_volume(volume_id, **params):
    """ update volume's displayname or description
    :param volume_id: The :id: Volume
    :param params: Update volume info:A Dict={"displayname": "vm-1",
    "des": "desc volume"}
    :return:
    """
    try:
コード例 #5
0
ファイル: snapshot.py プロジェクト: 1026237416/Python
def update_tenant_snapshot_quotas(tenant_id, used_size=None, used_count=None):
    if used_size is not None:
        yield update_quota_used(tenant_id, QUOTA_NAMES.snapshot_capacity,
                                used_size)
    if used_count is not None:
        yield update_quota_used(tenant_id, QUOTA_NAMES.snapshots, used_count)