def delete_tenant_images(also_shared=False, tenant_id=None): if not tenant_id: tenant_id = osclients.get_session().get_project_id() tenant = osclients.get_session().get_project_id() glance = osclients.get_glanceclient() for image in glance.images.findall(owner=tenant): if image.owner != tenant_id: continue if image.is_public and not also_shared: continue else: glance.images.delete(image.id)
def get_all_images(): public_images = dict() private_images = dict() glance = osclients.get_glanceclient() for image in glance.images.findall(): if image.is_public: if image.owner not in public_images: public_images[image.owner] = list() public_images[image.owner].append(image.id) else: if image.owner not in private_images: private_images[image.owner] = list() private_images[image.owner].append(image.id) return (private_images, public_images)
def get_tenant_images(tenant_id=None): if not tenant_id: tenant_id = osclients.get_session().get_project_id() tenant = osclients.get_session().get_project_id() public_images = list() private_images = list() glance = osclients.get_glanceclient() for image in glance.images.findall(owner=tenant): if image.owner != tenant_id: continue if image.is_public: public_images.append(image.id) else: private_images.append(image.id) return (private_images, public_images)
def delete_image_list(images): glance = osclients.get_glanceclient() for image in images: glance.images.delete(image.id)
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. # # For those usages not covered by the Apache version 2.0 License please # contact with [email protected] # author = 'chema' import osclients neutron = osclients.get_neutronclient() cinder = osclients.get_cinderclient() glance = osclients.get_glanceclient() nova = osclients.get_novaclient() volume = cinder.volumes.create(name='cindervolume', size=1) external_net = None for net in neutron.list_networks()['networks']: if net['router:external']: external_net = net['id'] break image = glance.images.create(container_format='bare', name='testimage1', disk_format='qcow2', data='aaaaa')
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. # # For those usages not covered by the Apache version 2.0 License please # contact with [email protected] # author = 'chema' import osclients neutron = osclients.get_neutronclient() cinder = osclients.get_cinderclient() glance = osclients.get_glanceclient() nova = osclients.get_novaclient() volume = cinder.volumes.create(name='cindervolume', size=1) external_net=None for net in neutron.list_networks()['networks']: if net['router:external']: external_net = net['id'] break image = glance.images.create( container_format='bare', name='testimage1', disk_format='qcow2', data='aaaaa') keypair = nova.keypairs.create(name='testpublickey')