def _unregister_provider(provider_id): """Unregister a provider. """ provider = _retrieve_provider(provider_id) _check_machines_exist(provider) Provider.remove(provider) _LOGGER.debug("Unregistered provider (%s).", provider_id)
def _register_provider(provider_id, provider_type, username, password, url, tenant, default_image, default_flavor, extra): """Register a provider. """ _check_provider_exists(provider_id) _check_extra_parameter(extra) provider = Provider(provider_id=provider_id, provider_type=provider_type, username=username, password=password, url=url, tenant=tenant, default_image=default_image, default_flavor=default_flavor, extra=extra ) Provider.add(provider) _LOGGER.debug("Registered provider (%s).", provider)
def _check_provider_exists(provider_id): """Check whether a provider exists or not. """ provider = Provider.fetch(provider_id) if provider: raise _errors.ProviderError("Provider (%s) already exists." % (provider_id, ))
def execute(self, provider_id=None): """Return information on existing provider(s). :param provider_id: None if one wants to list the existing providers or provider's id if one wants information on a provider. """ rset = ResultSet( names=('provider_id', 'type', 'username', 'url', 'tenant', 'default_image', 'default_flavor', 'extra'), types=(str, str, str, str, str, str, str, str) ) if provider_id is None: for prv in Provider.providers(): rset.append_row(( prv.provider_id, prv.provider_type, prv.username, prv.url, prv.tenant, prv.default_image, prv.default_flavor, prv.extra )) else: prv = _retrieve_provider(provider_id) rset.append_row(( prv.provider_id, prv.provider_type, prv.username, prv.url, prv.tenant, prv.default_image, prv.default_flavor, prv.extra )) return CommandResult(None, results=rset)
def _retrieve_provider(provider_id): """Return a provider object from an id. """ provider = Provider.fetch(provider_id) if not provider: raise _errors.ProviderError("Provider (%s) does not exist." % (provider_id, )) return provider
def _check_provider_exists(provider_id): """Check whether a provider exists or not. """ provider = Provider.fetch(provider_id) if provider: raise _errors.ProviderError( "Provider (%s) already exists." % (provider_id, ) )
def test_providers(self): """Test fetching set of providers. """ provider_1 = Provider(provider_id=self.provider_id, provider_type=self.provider_type, username=self.username, password=self.password, url=self.url, tenant=self.tenant, default_image=self.image, default_flavor=self.flavor, extra=self.extra) Provider.add(provider_1) provider_id = "other.provider" provider_2 = Provider(provider_id=provider_id, provider_type=self.provider_type, username=self.username, password=self.password, url=self.url, tenant=self.tenant, default_image=self.image, default_flavor=self.flavor, extra=self.extra) Provider.add(provider_2) ret = [ isinstance(provider, Provider) for provider in \ Provider.providers() ] self.assertEqual(len(ret), 2) self.assertTrue(all(ret))
def test_library(self): """Test whether libraries are installed. """ provider = Provider(provider_id=self.provider_id, provider_type=self.provider_type, username=self.username, password=self.password, url=self.url, tenant=self.tenant, default_image=self.image, default_flavor=self.flavor, extra=self.extra) Provider.add(provider) self.assertNotEqual(None, provider.get_provider_machine()) Provider.remove(provider) self.assertRaises(_errors.ProviderError, Provider, provider_id=self.provider_id, provider_type="UNKNOWN_TYPE", username=self.username, password=self.password, url=self.url, tenant=self.tenant, default_image=self.image, default_flavor=self.flavor, extra=self.extra)
def _retrieve_provider(provider_id): """Return a provider object from an id. """ provider = Provider.fetch(provider_id) if not provider: raise _errors.ProviderError( "Provider (%s) does not exist." % (provider_id, ) ) return provider
def setUp(self): """Configure the existing environment. """ self.provider_id = "provider" self.provider_type = "NULLPROVIDER" self.username = "******" self.password = "******" self.url = "http://127.0.0.1:5000/v2.0" self.tenant = "tenant" self.provider = Provider(provider_id=self.provider_id, provider_type=self.provider_type, username=self.username, password=self.password, url=self.url, tenant=self.tenant) Provider.add(self.provider) self.uuid_1 = _uuid.uuid4() self.uuid_2 = _uuid.uuid4() self.av_zone = "MySQL Fabric's Zone"
def test_storage(self): """Test using Provider's storage. """ src_provider = Provider(provider_id=self.provider_id, provider_type=self.provider_type, username=self.username, password=self.password, url=self.url, tenant=self.tenant, default_image=self.image, default_flavor=self.flavor, extra=self.extra) Provider.add(src_provider) dst_provider = Provider.fetch(self.provider_id) self.assertEqual(src_provider, dst_provider) self.assertNotEqual(id(src_provider), id(dst_provider)) Provider.remove(src_provider) dst_provider = Provider.fetch(self.provider_id) self.assertEqual(None, dst_provider)
def test_properties(self): """Test setting/reading Provider's properties. """ provider = Provider(provider_id=self.provider_id, provider_type=self.provider_type, username=self.username, password=self.password, url=self.url, tenant=self.tenant, default_image=self.image, default_flavor=self.flavor, extra=self.extra) # Check property provider_id. self.assertEqual(provider.provider_id, self.provider_id) # Check property provider_type. self.assertEqual(provider.provider_type, self.provider_type) # Check property username. self.assertEqual(provider.username, self.username) # Check property password. self.assertEqual(provider.password, self.password) # Check property url. self.assertEqual(provider.url, self.url) # Check property tenant. self.assertEqual(provider.tenant, self.tenant) # Check property default_image. self.assertEqual(provider.default_image, self.image) # Check property default_flavor. self.assertEqual(provider.default_flavor, self.flavor) # Check property extra. self.assertEqual(provider.extra, self.extra)