def __init__(self, name, config_str, scale_manager): self.name = name self.config = EndpointConfig(config_str) self.scale_manager = scale_manager self.state = State.default self.cloud = self.config.cloud_type() self.decommissioned_instances = [] self.cloud_conn = cloud_connection.get_connection( self.cloud, self.config.cloud_config())
def update_config(self, config_str): # Check if our configuration is about to change. old_url = self.config.url() old_static_addresses = self.config.static_ips() old_port = self.config.port() old_cloud_config = self.config.cloud_config() old_public = self.config.public() old_weight = self.config.weight() old_redirect = self.config.redirect() new_config = EndpointConfig(config_str) new_url = new_config.url() new_static_addresses = new_config.static_ips() new_port = new_config.port() new_cloud_config = new_config.cloud_config() new_public = new_config.public() new_weight = new_config.weight() new_redirect = new_config.redirect() # Drop all removed static addresses. for ip in old_static_addresses: if not(ip in new_static_addresses): self.scale_manager.drop_ip(self.name, ip) # Remove all old instances from loadbalancer, # (Only necessary if we've changed the endpoint URL). if old_url != new_url: self.scale_manager.remove_endpoint(self.name) # Reload the configuration. self.config.reload(config_str) # Reconnect to the cloud controller (if necessary). if old_cloud_config != new_cloud_config: self.cloud_conn = cloud_connection.get_connection(self.config.cloud_type(), self.config.cloud_config()) # Do a referesh (to capture the new endpoint). if old_url != new_url: self.scale_manager.add_endpoint(self) elif old_static_addresses != new_static_addresses or \ old_port != new_port or \ old_public != new_public or \ old_weight != new_weight or \ old_redirect != new_redirect: self._update_loadbalancer()
def test_get_connection_mock(self): assert isinstance(get_connection("mock"), Connection)
def test_get_connection_empty_str(self): assert isinstance(get_connection(""), CloudConnection)
def test_get_connection_none(self): assert isinstance(get_connection(None), CloudConnection)