X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fv1%2Fvim.py;h=f9f8369ddd9f26396670e5ae5499a79c1be1f297;hb=fa7254bef0747908c66df7d2e25a79894fbd213f;hp=f51f19283313b70b7abb8d482445b423fc0e23dd;hpb=b516c050a55379ff425a1369252a50fedf2a5d3a;p=osm%2Fosmclient.git diff --git a/osmclient/v1/vim.py b/osmclient/v1/vim.py index f51f192..f9f8369 100644 --- a/osmclient/v1/vim.py +++ b/osmclient/v1/vim.py @@ -81,6 +81,27 @@ class Vim(object): raise ClientException("failed to create vim") else: self._attach(name, vim_account) + self._update_ro_accounts() + + + def _update_ro_accounts(self): + get_ro_accounts = self._http.get_cmd('api/operational/{}ro-account' + .format(self._client.so_rbac_project_path)) + if not get_ro_accounts or 'rw-ro-account:ro-account' not in get_ro_accounts: + return + for account in get_ro_accounts['rw-ro-account:ro-account']['account']: + if account['ro-account-type'] == 'openmano': + # Refresh the Account Status + refresh_body = {"input": { + "ro-account": account['name'], + "project-name": self._client._so_project + } + } + refresh_status = self._http.post_cmd('api/operations/update-ro-account-status', + refresh_body) + if refresh_status and 'error' in refresh_status: + raise ClientException("Failed to refersh RO Account Status") + def update_vim_account_dict(self, vim_account, vim_access, vim_config): if vim_access['vim-type'] == 'vmware': @@ -124,34 +145,56 @@ class Vim(object): self._detach(vim_name) # detach. continue if error, # it could be the datacenter is left without attachment - - if 'result' not in self._ro_http.delete_cmd('openmano/datacenters/{}' - .format(vim_name)): - raise ClientException("failed to delete vim {}".format(vim_name)) + resp = self._ro_http.delete_cmd('openmano/datacenters/{}' + .format(vim_name)) + if 'result' not in resp: + raise ClientException("failed to delete vim {} - {}".format(vim_name, resp)) + self._update_ro_accounts() def list(self): - resp = self._http.get_cmd('v1/api/operational/datacenters') - if not resp or 'rw-launchpad:datacenters' not in resp: - return list() - - datacenters = resp['rw-launchpad:datacenters'] - - vim_accounts = list() - if 'ro-accounts' not in datacenters: + if self._client._so_version == 'v3': + resp = self._http.get_cmd('v1/api/operational/{}ro-account-state' + .format(self._client.so_rbac_project_path)) + datacenters = [] + if not resp or 'rw-ro-account:ro-account-state' not in resp: + return list() + + ro_accounts = resp['rw-ro-account:ro-account-state'] + for ro_account in ro_accounts['account']: + if 'datacenters' not in ro_account: + continue + if 'datacenters' not in ro_account['datacenters']: + continue + for datacenter in ro_account['datacenters']['datacenters']: + datacenters.append({"name": datacenter['name'], "uuid": datacenter['uuid'] + if 'uuid' in datacenter else None}) + + vim_accounts = datacenters return vim_accounts - - tenant = self._get_ro_tenant() - if tenant is None: + else: + # Backwards Compatibility + resp = self._http.get_cmd('v1/api/operational/datacenters') + if not resp or 'rw-launchpad:datacenters' not in resp: + return list() + + datacenters = resp['rw-launchpad:datacenters'] + + vim_accounts = list() + if 'ro-accounts' not in datacenters: + return vim_accounts + + tenant = self._get_ro_tenant() + if tenant is None: + return vim_accounts + + for roaccount in datacenters['ro-accounts']: + if 'datacenters' not in roaccount: + continue + for datacenter in roaccount['datacenters']: + vim_accounts.append(self._get_ro_datacenter(datacenter['name'], + tenant['uuid'])) return vim_accounts - for roaccount in datacenters['ro-accounts']: - if 'datacenters' not in roaccount: - continue - for datacenter in roaccount['datacenters']: - vim_accounts.append(self._get_ro_datacenter(datacenter['name'], - tenant['uuid'])) - return vim_accounts - def _get_ro_tenant(self, name='osm'): resp = self._ro_http.get_cmd('openmano/tenants/{}'.format(name)) @@ -182,24 +225,47 @@ class Vim(object): return self._get_ro_datacenter(name, tenant['uuid']) def get_datacenter(self, name): - resp = self._http.get_cmd('v1/api/operational/datacenters') - if not resp: - return None - - if not resp or 'rw-launchpad:datacenters' not in resp: - return None - if 'ro-accounts' not in resp['rw-launchpad:datacenters']: + if self._client._so_version == 'v3': + resp = self._http.get_cmd('v1/api/operational/{}ro-account-state' + .format(self._client.so_rbac_project_path)) + if not resp: + return None, None + + if not resp or 'rw-ro-account:ro-account-state' not in resp: + return None, None + + ro_accounts = resp['rw-ro-account:ro-account-state'] + for ro_account in ro_accounts['account']: + if 'datacenters' not in ro_account: + continue + if 'datacenters' not in ro_account['datacenters']: + continue + for datacenter in ro_account['datacenters']['datacenters']: + if datacenter['name'] == name: + return datacenter, ro_account['name'] + return None, None + else: + # Backwards Compatibility + resp = self._http.get_cmd('v1/api/operational/datacenters') + if not resp: + return None + + if not resp or 'rw-launchpad:datacenters' not in resp: + return None + if 'ro-accounts' not in resp['rw-launchpad:datacenters']: + return None + for roaccount in resp['rw-launchpad:datacenters']['ro-accounts']: + if 'datacenters' not in roaccount: + continue + for datacenter in roaccount['datacenters']: + if datacenter['name'] == name: + return datacenter return None - for roaccount in resp['rw-launchpad:datacenters']['ro-accounts']: - if 'datacenters' not in roaccount: - continue - for datacenter in roaccount['datacenters']: - if datacenter['name'] == name: - return datacenter - return None def get_resource_orchestrator(self): - resp = self._http.get_cmd('v1/api/operational/resource-orchestrator') + resp = self._http.get_cmd('v1/api/operational/{}resource-orchestrator' + .format(self._client.so_rbac_project_path)) + if not resp or 'rw-launchpad:resource-orchestrator' not in resp: return None return resp['rw-launchpad:resource-orchestrator']