diff options
author | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-03-14 16:48:22 +0800 |
---|---|---|
committer | SerenaFeng <feng.xiaowei@zte.com.cn> | 2017-03-16 09:14:25 +0800 |
commit | 128fc2d19087351b5ef50c837b41587550ae1277 (patch) | |
tree | 1cf04e4e14aa8fb458c60997c09e83f6ff0201fd /deploy/post/glance.py | |
parent | d355d53f3cd33fb7ea0790c8b6deba0d70fa2ce4 (diff) |
create default TestVM for Functest
Change-Id: I505a0819d5f1a4350e82ceaa9e5cbee285c8fba0
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'deploy/post/glance.py')
-rw-r--r-- | deploy/post/glance.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/deploy/post/glance.py b/deploy/post/glance.py new file mode 100644 index 00000000..2422c7a4 --- /dev/null +++ b/deploy/post/glance.py @@ -0,0 +1,37 @@ +import os + +import glanceclient + +import keystoneauth + + +class Glance(keystoneauth.Keystoneauth): + def __init__(self, version='2', openrc=None): + super(Glance, self).__init__(openrc) + self.client = glanceclient.Client(version, session=self.session) + self.controller = self.client.images + + def create(self, name, path, + disk_format="qcow2", + container_format="bare", + visibility="public"): + if not os.path.isfile(path): + raise Exception('Error: file {} not exist'.format(path)) + image = self.controller.create(name=name, + visibility=visibility, + disk_format=disk_format, + container_format=container_format) + id = image.id + with open(path) as data: + self.controller.upload(id, data) + return id + + def get_by_name(self, name): + for image in self.list(): + if image.name == name: + return image.id + + return None + + def list(self): + return self.controller.list() |