X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fsol005%2Fvim.py;h=bd95d6611256905c7925757afe5e3b9cb84bcc89;hb=3b9e2c9599832958c8b8bf7c85433a76f65bd043;hp=6e15e5bbea602e2e49a3a1608bd270883ede1259;hpb=061856b26ecc63183378489fa7eb6ed5a6f0250f;p=osm%2Fosmclient.git diff --git a/osmclient/sol005/vim.py b/osmclient/sol005/vim.py index 6e15e5b..bd95d66 100644 --- a/osmclient/sol005/vim.py +++ b/osmclient/sol005/vim.py @@ -19,6 +19,7 @@ OSM vim API handling """ from osmclient.common import utils +from osmclient.common import wait as WaitForStatus from osmclient.common.exceptions import ClientException from osmclient.common.exceptions import NotFound import yaml @@ -34,7 +35,20 @@ class Vim(object): self._apiResource = '/vim_accounts' self._apiBase = '{}{}{}'.format(self._apiName, self._apiVersion, self._apiResource) - def create(self, name, vim_access, sdn_controller=None, sdn_port_mapping=None): + # VIM '--wait' option + def _wait(self, id, deleteFlag=False): + # Endpoint to get operation status + apiUrlStatus = '{}{}{}'.format(self._apiName, self._apiVersion, '/vim_accounts') + # Wait for status for VIM instance creation/deletion + WaitForStatus.wait_for_status( + 'VIM', + str(id), + WaitForStatus.TIMEOUT_VIM_OPERATION, + apiUrlStatus, + self._http.get2_cmd, + deleteFlag=deleteFlag) + + def create(self, name, vim_access, sdn_controller=None, sdn_port_mapping=None, wait=False): if 'vim-type' not in vim_access: #'openstack' not in vim_access['vim-type']): raise Exception("vim type not provided") @@ -66,7 +80,10 @@ class Vim(object): if not resp or 'id' not in resp: raise ClientException('unexpected response from server - {}'.format( resp)) - print resp['id'] + if wait: + # Wait for status for VIM instance creation + self._wait(resp.get('id')) + print(resp['id']) else: msg = "" if resp: @@ -76,14 +93,14 @@ class Vim(object): msg = resp raise ClientException("failed to create vim {} - {}".format(name, msg)) - def update(self, vim_name, vim_account, sdn_controller, sdn_port_mapping): + def update(self, vim_name, vim_account, sdn_controller, sdn_port_mapping, wait=False): vim = self.get(vim_name) vim_config = {} if 'config' in vim_account: - if config=="" and (sdncontroller or sdn_port_mapping): + if vim_account.get('config')=="" and (sdn_controller or sdn_port_mapping): raise ClientException("clearing config is incompatible with updating SDN info") - if config=="": + if vim_account.get('config')=="": vim_config = None else: vim_config = yaml.safe_load(vim_account['config']) @@ -105,7 +122,10 @@ class Vim(object): if not resp or 'id' not in resp: raise ClientException('unexpected response from server - {}'.format( resp)) - print resp['id'] + if wait: + # Wait for status for VIM instance update + self._wait(resp.get('id')) + print(resp['id']) else: msg = "" if resp: @@ -132,7 +152,7 @@ class Vim(object): return vim['uuid'] raise NotFound("vim {} not found".format(name)) - def delete(self, vim_name, force=False): + def delete(self, vim_name, force=False, wait=False): vim_id = vim_name if not utils.validate_uuid4(vim_name): vim_id = self.get_id(vim_name) @@ -144,9 +164,19 @@ class Vim(object): #print 'HTTP CODE: {}'.format(http_code) #print 'RESP: {}'.format(resp) if http_code == 202: - print 'Deletion in progress' + if wait: + # When deleting an account, 'resp' may be None. + # In such a case, the 'id' from 'resp' cannot be used, so use 'vim_id' instead + wait_id = vim_id + if resp: + resp = json.loads(resp) + wait_id = resp.get('id') + # Wait for status for VIM account deletion + self._wait(wait_id, deleteFlag=True) + else: + print('Deletion in progress') elif http_code == 204: - print 'Deleted' + print('Deleted') else: msg = "" if resp: