1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# Copyright (c) 2017 VMware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
import logging
from vio.pub.vim.drivers import base
from vio.pub.vim.drivers.vimsdk import sdk
from openstack.image.v2 import image as _image
LOG = logging.getLogger(__name__)
class GlanceClient(base.DriverBase):
def __init__(self, params):
super(GlanceClient, self).__init__(params)
LOG.info("%s", str(params))
self.conn = sdk.create_connection(params)
self.session = self.conn.session
self._proxy = self.conn.image
@sdk.translate_exception
def list_images(self, **query):
images = self._proxy.images(**query)
return images
@sdk.translate_exception
def get_image(self, imageid):
image = self._proxy.get_image(imageid)
return image
@sdk.translate_exception
def delete_image(self, imageid):
self._proxy.delete_image(imageid)
@sdk.translate_exception
def create_image(self, **data):
disk_format = data.pop('disk_format')
container_format = data.pop('container_format')
if not all([container_format, disk_format]):
LOG.error( "Both container_format and disk_format are required")
try:
img = self._proxy._create(_image.Image, disk_format=disk_format,
container_format=container_format, **data)
except Exception as ex:
pass
return img
@sdk.translate_exception
def upload_image(self, data, image):
image.data = data
image.upload(self.session)
|