def serialize_cinder_volume(volume): """volume can be an id or a 'volume' object from cinderclient""" if isinstance(volume, six.string_types): cinder_client = openstack_clients.get_cinderclient() volume = cinder_client.volumes.get(volume) LOG.debug("Serializing volume %s for project %s", volume.id, volume.user_id) serialized = {k: v for k, v in six.iteritems(volume.to_dict()) if k not in BLACKLISTED_FIELDS} project_id = serialized.get('os-vol-tenant-attr:tenant_id') if 'tenant_id' not in serialized: serialized['tenant_id'] = project_id if 'project_id' not in serialized: serialized['project_id'] = project_id return serialized
def serialize_cinder_snapshot(snapshot): """snapshot can be an id or a 'Snapshot' object from cinderclient""" if isinstance(snapshot, six.string_types): cinder_client = openstack_clients.get_cinderclient() snapshot = cinder_client.volume_snapshots.get(snapshot) project_id = getattr(snapshot, 'os-extended-snapshot-attributes:project_id') LOG.debug("Serializing snapshot %s for project %s", snapshot.id, project_id) serialized = {k: v for k, v in six.iteritems(snapshot.to_dict()) if k not in BLACKLISTED_FIELDS} if 'tenant_id' not in serialized: serialized['tenant_id'] = project_id if 'project_id' not in serialized: serialized['project_id'] = project_id return serialized
def get_objects(self): """Generator that lists all cinder volumes owned by all tenants.""" LOG.debug("Cinder volumes get_objects started") has_more = True marker = None while has_more: volumes = openstack_clients.get_cinderclient().volumes.list( limit=LIST_LIMIT, search_opts={'all_tenants': True}, marker=marker) if not volumes: # Definitely no more; break straight away break # volumes.list always returns a list so we can grab the last id has_more = len(volumes) == LIST_LIMIT marker = volumes[-1].id for volume in volumes: yield volume
def serialize_cinder_volume(volume): """volume can be an id or a 'volume' object from cinderclient""" if isinstance(volume, six.string_types): cinder_client = openstack_clients.get_cinderclient() volume = cinder_client.volumes.get(volume) LOG.debug("Serializing volume %s for project %s", volume.id, volume.user_id) serialized = { k: v for k, v in volume.to_dict().items() if k not in BLACKLISTED_FIELDS } project_id = serialized.get('os-vol-tenant-attr:tenant_id') if 'tenant_id' not in serialized: serialized['tenant_id'] = project_id if 'project_id' not in serialized: serialized['project_id'] = project_id return serialized
def serialize_cinder_snapshot(snapshot): """snapshot can be an id or a 'Snapshot' object from cinderclient""" if isinstance(snapshot, six.string_types): cinder_client = openstack_clients.get_cinderclient() snapshot = cinder_client.volume_snapshots.get(snapshot) project_id = getattr(snapshot, 'os-extended-snapshot-attributes:project_id') LOG.debug("Serializing snapshot %s for project %s", snapshot.id, project_id) serialized = { k: v for k, v in snapshot.to_dict().items() if k not in BLACKLISTED_FIELDS } if 'tenant_id' not in serialized: serialized['tenant_id'] = project_id if 'project_id' not in serialized: serialized['project_id'] = project_id return serialized
def get_objects(self): """Generator that lists all cinder volumes owned by all tenants.""" LOG.debug("Cinder volumes get_objects started") has_more = True marker = None while has_more: volumes = openstack_clients.get_cinderclient().volumes.list( limit=LIST_LIMIT, search_opts={'all_tenants': True}, marker=marker ) if not volumes: # Definitely no more; break straight away break # volumes.list always returns a list so we can grab the last id has_more = len(volumes) == LIST_LIMIT marker = volumes[-1].id for volume in volumes: yield volume
def get_objects(self): """Generator that lists all cinder snapshots owned by all tenants.""" LOG.debug("Cinder snapshots get_objects started") has_more = True marker = None cc = openstack_clients.get_cinderclient() while has_more: snapshots = cc.volume_snapshots.list( limit=LIST_LIMIT, search_opts={'all_tenants': True}, marker=marker) if not snapshots: # Definitely no more; break straight away break # snapshots.list always returns a list so we can grab the last id has_more = len(snapshots) == LIST_LIMIT marker = snapshots[-1].id for snapshot in snapshots: yield snapshot
def get_objects(self): """Generator that lists all cinder snapshots owned by all tenants.""" LOG.debug("Cinder snapshots get_objects started") has_more = True marker = None cc = openstack_clients.get_cinderclient() while has_more: snapshots = cc.volume_snapshots.list( limit=LIST_LIMIT, search_opts={'all_tenants': True}, marker=marker ) if not snapshots: # Definitely no more; break straight away break # snapshots.list always returns a list so we can grab the last id has_more = len(snapshots) == LIST_LIMIT marker = snapshots[-1].id for snapshot in snapshots: yield snapshot