+
+
+
+ def _format_exception(self, exception):
+ '''Transform a keystone, nova, neutron exception into a vimconn exception'''
+ if isinstance(exception, (HTTPException, gl1Exceptions.HTTPException, gl1Exceptions.CommunicationError,
+ ConnectionError, ksExceptions.ConnectionError, neExceptions.ConnectionFailed,
+ neClient.exceptions.ConnectionFailed)):
+ raise vimconn.vimconnConnectionException(type(exception).__name__ + ": " + str(exception))
+ elif isinstance(exception, (nvExceptions.ClientException, ksExceptions.ClientException,
+ neExceptions.NeutronException, nvExceptions.BadRequest)):
+ raise vimconn.vimconnUnexpectedResponse(type(exception).__name__ + ": " + str(exception))
+ elif isinstance(exception, (neExceptions.NetworkNotFoundClient, nvExceptions.NotFound)):
+ raise vimconn.vimconnNotFoundException(type(exception).__name__ + ": " + str(exception))
+ elif isinstance(exception, nvExceptions.Conflict):
+ raise vimconn.vimconnConflictException(type(exception).__name__ + ": " + str(exception))
+ else: # ()
+ raise vimconn.vimconnConnectionException(type(exception).__name__ + ": " + str(exception))
+
+ def get_tenant_list(self, filter_dict={}):
+ '''Obtain tenants of VIM
+ filter_dict can contain the following keys:
+ name: filter by tenant name
+ id: filter by tenant uuid/id
+ <other VIM specific>
+ Returns the tenant list of dictionaries: [{'name':'<name>, 'id':'<id>, ...}, ...]
+ '''
+ self.logger.debug("Getting tenant from VIM filter: '%s'", str(filter_dict))
+ try:
+ self._reload_connection()
+ tenant_class_list=self.keystone.tenants.findall(**filter_dict)
+ tenant_list=[]
+ for tenant in tenant_class_list:
+ tenant_list.append(tenant.to_dict())
+ return tenant_list
+ except (ksExceptions.ConnectionError, ksExceptions.ClientException) as e:
+ self._format_exception(e)
+
+ def new_tenant(self, tenant_name, tenant_description):
+ '''Adds a new tenant to openstack VIM. Returns the tenant identifier'''
+ self.logger.debug("Adding a new tenant name: %s", tenant_name)
+ try:
+ self._reload_connection()
+ tenant=self.keystone.tenants.create(tenant_name, tenant_description)
+ return tenant.id
+ except (ksExceptions.ConnectionError, ksExceptions.ClientException) as e:
+ self._format_exception(e)
+
+ def delete_tenant(self, tenant_id):
+ '''Delete a tenant from openstack VIM. Returns the old tenant identifier'''
+ self.logger.debug("Deleting tenant %s from VIM", tenant_id)
+ try:
+ self._reload_connection()
+ self.keystone.tenants.delete(tenant_id)
+ return tenant_id
+ except (ksExceptions.ConnectionError, ksExceptions.ClientException) as e:
+ self._format_exception(e)