X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osmclient%2Fv1%2Fvim.py;h=8c73269582ee2a72c92bc5fd83e073b019a723fd;hb=ac6a77b372379e29d811dedac1e19cab27f489c1;hp=79701f858cb908c4c5706612085a3a46d4ff80b4;hpb=e84eb31aded0cb62a5523422ddc4524f6e615209;p=osm%2Fosmclient.git diff --git a/osmclient/v1/vim.py b/osmclient/v1/vim.py index 79701f8..8c73269 100644 --- a/osmclient/v1/vim.py +++ b/osmclient/v1/vim.py @@ -23,38 +23,41 @@ from osmclient.common.exceptions import NotFound class Vim(object): - - def __init__(self,http=None,ro_http=None,client=None): - self._client=client - self._ro_http=ro_http - self._http=http - - def _attach(self,vim_name,username,secret,vim_tenant_name): - tenant_name='osm' - tenant=self._get_ro_tenant() + def __init__(self, http=None, ro_http=None, client=None): + self._client = client + self._ro_http = ro_http + self._http = http + + def _attach(self, vim_name, username, secret, vim_tenant_name): + tenant_name = 'osm' + tenant = self._get_ro_tenant() if tenant is None: raise ClientException("tenant {} not found".format(tenant_name)) - datacenter= self._get_ro_datacenter(vim_name) + datacenter = self._get_ro_datacenter(vim_name) if datacenter is None: raise Exception('datacenter {} not found'.format(vim_name)) - vim_account={} - vim_account['datacenter']={} + vim_account = {} + vim_account['datacenter'] = {} - vim_account['datacenter']['vim_username'] = username - vim_account['datacenter']['vim_password'] = secret + vim_account['datacenter']['vim_username'] = username + vim_account['datacenter']['vim_password'] = secret vim_account['datacenter']['vim_tenant_name'] = vim_tenant_name - return self._ro_http.post_cmd('openmano/{}/datacenters/{}'.format(tenant['uuid'],datacenter['uuid']),vim_account) + return self._ro_http.post_cmd('openmano/{}/datacenters/{}' + .format(tenant['uuid'], + datacenter['uuid']), vim_account) - def _detach(self,vim_name): - return self._ro_http.delete_cmd('openmano/{}/datacenters/{}'.format('osm',vim_name)) + def _detach(self, vim_name): + return self._ro_http.delete_cmd('openmano/{}/datacenters/{}' + .format('osm', vim_name)) def create(self, name, vim_access): - vim_account={} - vim_account['datacenter']={} + vim_account = {} + vim_account['datacenter'] = {} # currently assumes vim_acc - if 'vim-type' not in vim_access or 'openstack' not in vim_access['vim-type']: + if ('vim-type' not in vim_access or + 'openstack' not in vim_access['vim-type']): raise Exception("only vim type openstack support") vim_account['datacenter']['name'] = name @@ -66,7 +69,8 @@ class Vim(object): vim_config = {} vim_config['use_floating_ip'] = False - if 'floating_ip_pool' in vim_access and vim_access['floating_ip_pool'] is not None: + if ('floating_ip_pool' in vim_access and + vim_access['floating_ip_pool'] is not None): vim_config['use_floating_ip'] = True if 'keypair' in vim_access and vim_access['keypair'] is not None: @@ -74,32 +78,37 @@ class Vim(object): vim_account['datacenter']['config'] = vim_config - resp = self._ro_http.post_cmd('openmano/datacenters',vim_account) + resp = self._ro_http.post_cmd('openmano/datacenters', vim_account) if resp and 'error' in resp: raise ClientException("failed to create vim") else: - self._attach(name,vim_access['os-username'],vim_access['os-password'],vim_access['os-project-name']) + self._attach(name, + vim_access['os-username'], + vim_access['os-password'], + vim_access['os-project-name']) - def delete(self,vim_name): + def delete(self, vim_name): # first detach - resp=self._detach(vim_name) - # detach. continue if error, it could be the datacenter is left without attachment + 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)): + if 'result' not in self._ro_http.delete_cmd('openmano/datacenters/{}' + .format(vim_name)): raise ClientException("failed to delete vim {}".format(vim_name)) def list(self): - resp=self._http.get_cmd('v1/api/operational/datacenters') + 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'] + datacenters = resp['rw-launchpad:datacenters'] vim_accounts = list() if 'ro-accounts' not in datacenters: return vim_accounts - tenant=self._get_ro_tenant() + tenant = self._get_ro_tenant() if tenant is None: return vim_accounts @@ -107,11 +116,12 @@ class Vim(object): if 'datacenters' not in roaccount: continue for datacenter in roaccount['datacenters']: - vim_accounts.append(self._get_ro_datacenter(datacenter['name'],tenant['uuid'])) + 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)) + def _get_ro_tenant(self, name='osm'): + resp = self._ro_http.get_cmd('openmano/tenants/{}'.format(name)) if not resp: return None @@ -121,35 +131,35 @@ class Vim(object): else: return None - def _get_ro_datacenter(self,name,tenant_uuid='any'): - resp=self._ro_http.get_cmd('openmano/{}/datacenters/{}'.format(tenant_uuid,name)) + def _get_ro_datacenter(self, name, tenant_uuid='any'): + resp = self._ro_http.get_cmd('openmano/{}/datacenters/{}' + .format(tenant_uuid, name)) if not resp: raise NotFound("datacenter {} not found".format(name)) - + if 'datacenter' in resp and 'uuid' in resp['datacenter']: return resp['datacenter'] else: raise NotFound("datacenter {} not found".format(name)) - def get(self,name): - tenant=self._get_ro_tenant() + def get(self, name): + tenant = self._get_ro_tenant() if tenant is None: raise NotFound("no ro tenant found") - return self._get_ro_datacenter(name,tenant['uuid']) + return self._get_ro_datacenter(name, tenant['uuid']) - def get_datacenter(self,name): - resp=self._http.get_cmd('v1/api/operational/datacenters') + def get_datacenter(self, name): + resp = self._http.get_cmd('v1/api/operational/datacenters') if not resp: return None - datacenters=resp['rw-launchpad:datacenters'] 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 not 'datacenters' in roaccount: + if 'datacenters' not in roaccount: continue for datacenter in roaccount['datacenters']: if datacenter['name'] == name: @@ -157,7 +167,7 @@ class Vim(object): 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') if not resp or 'rw-launchpad:resource-orchestrator' not in resp: return None return resp['rw-launchpad:resource-orchestrator']