From 0c69043be9d046999319a7aa69434efdf360fa81 Mon Sep 17 00:00:00 2001 From: Ethan Lynn Date: Wed, 5 Sep 2018 16:54:17 +0800 Subject: Add heat driver This patch adds heat driver to interact with OpenStack Heat API. Change-Id: I77bc283c51d7d85bf72436938d63a6e98d53d72e Issue-ID: MULTICLOUD-353 Signed-off-by: Ethan Lynn --- vio/vio/pub/vim/drivers/vimdriver.py | 2 + vio/vio/pub/vim/drivers/vimsdk/heat.py | 74 +++++++++++++++++++++++++++++ vio/vio/pub/vim/vimapi/baseclient.py | 6 +++ vio/vio/pub/vim/vimapi/heat/OperateStack.py | 51 ++++++++++++++++++++ vio/vio/pub/vim/vimapi/heat/__init__.py | 0 5 files changed, 133 insertions(+) create mode 100644 vio/vio/pub/vim/drivers/vimsdk/heat.py create mode 100644 vio/vio/pub/vim/vimapi/heat/OperateStack.py create mode 100644 vio/vio/pub/vim/vimapi/heat/__init__.py (limited to 'vio') diff --git a/vio/vio/pub/vim/drivers/vimdriver.py b/vio/vio/pub/vim/drivers/vimdriver.py index 5b9f783..ced6259 100644 --- a/vio/vio/pub/vim/drivers/vimdriver.py +++ b/vio/vio/pub/vim/drivers/vimdriver.py @@ -17,6 +17,7 @@ from vio.pub.vim.drivers.vimsdk import image_v2 from vio.pub.vim.drivers.vimsdk import keystone_v3 from vio.pub.vim.drivers.vimsdk import cinder_v2 from vio.pub.vim.drivers.vimsdk import compute +from vio.pub.vim.drivers.vimsdk import heat class VimDriver(object): @@ -27,3 +28,4 @@ class VimDriver(object): self.glance = image_v2.GlanceClient self.cinder = cinder_v2.CinderClient self.compute = compute.ComputeClient + self.heat = heat.HeatClient diff --git a/vio/vio/pub/vim/drivers/vimsdk/heat.py b/vio/vio/pub/vim/drivers/vimsdk/heat.py new file mode 100644 index 0000000..0dad830 --- /dev/null +++ b/vio/vio/pub/vim/drivers/vimsdk/heat.py @@ -0,0 +1,74 @@ +# Copyright (c) 2018 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 + +LOG = logging.getLogger(__name__) + + +class HeatClient(base.DriverBase): + '''Heat driver.''' + + def __init__(self, params): + super(HeatClient, self).__init__(params) + self.conn = sdk.create_connection(params) + self.session = self.conn.session + + @sdk.translate_exception + def stack_create(self, **params): + return self.conn.orchestration.create_stack(**params) + + @sdk.translate_exception + def stack_get(self, stack_id): + return self.conn.orchestration.get_stack(stack_id) + + @sdk.translate_exception + def stack_find(self, name_or_id): + return self.conn.orchestration.find_stack(name_or_id) + + @sdk.translate_exception + def stack_list(self): + return self.conn.orchestration.stacks() + + @sdk.translate_exception + def stack_delete(self, stack_id, ignore_missing=True): + return self.conn.orchestration.delete_stack(stack_id, + ignore_missing) + + @sdk.translate_exception + def wait_for_stack(self, stack_id, status, failures=None, interval=2, + timeout=None): + if failures is None: + failures = [] + + if timeout is None: + timeout = 600 + + stack_obj = self.conn.orchestration.find_stack(stack_id, False) + if stack_obj: + self.conn.orchestration.wait_for_status( + stack_obj, status, failures, interval, timeout) + + @sdk.translate_exception + def wait_for_stack_delete(self, stack_id, timeout=None): + """Wait for stack deleting complete""" + if timeout is None: + timeout = 600 + + server_obj = self.conn.orchestration.find_stack(stack_id, True) + if server_obj: + self.conn.orchestration.wait_for_delete(server_obj, wait=timeout) + + return diff --git a/vio/vio/pub/vim/vimapi/baseclient.py b/vio/vio/pub/vim/vimapi/baseclient.py index 2511426..ca34f4c 100644 --- a/vio/vio/pub/vim/vimapi/baseclient.py +++ b/vio/vio/pub/vim/vimapi/baseclient.py @@ -25,6 +25,7 @@ class baseclient(object): self._glanceclient = None self._computeClient = None self._cinderclient = None + self._heatclient = None def identity(self, data): '''Construct compute client based on object. @@ -58,3 +59,8 @@ class baseclient(object): self._cinderclient = driver_base.VimDriver().cinder(data) return self._cinderclient + + def heat(self, data): + if self._heatclient is None: + self._heatclient = driver_base.VimDriver().heat(data) + return self._heatclient diff --git a/vio/vio/pub/vim/vimapi/heat/OperateStack.py b/vio/vio/pub/vim/vimapi/heat/OperateStack.py new file mode 100644 index 0000000..f6eb80e --- /dev/null +++ b/vio/vio/pub/vim/vimapi/heat/OperateStack.py @@ -0,0 +1,51 @@ +# Copyright (c) 2018 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.vimapi.baseclient import baseclient + +logger = logging.getLogger(__name__) + + +def sdk_param_formatter(data): + param = {} + param['username'] = data.get('userName') + param['password'] = data.get('password') + param['auth_url'] = data.get('url') + param['project_id'] = data.get('tenant') + param['user_domain_name'] = 'default' + param['project_domain_name'] = 'default' + return param + + +class OperateStack(baseclient): + + def __init__(self, params): + super(OperateStack, self).__init__() + self.param = sdk_param_formatter(params) + + def get_vim_stacks(self, **query): + stacks = self.heat(self.param).stack_list(**query) + return stacks + + def create_vim_stack(self, **body): + stack = self.heat(self.param).stack_create(**body) + return stack + + def get_vim_stack(self, stack_id): + stack = self.heat(self.param).stack_find(stack_id) + return stack + + def delete_vim_stack(self, stack_id): + stack = self.heat(self.param).stack_delete(stack_id) + return stack diff --git a/vio/vio/pub/vim/vimapi/heat/__init__.py b/vio/vio/pub/vim/vimapi/heat/__init__.py new file mode 100644 index 0000000..e69de29 -- cgit 1.2.3-korg