def parse_thing(s): if s in self.containers: return self.containers[s].service if s in self.services: return self.services[s] raise exceptions.OrchestrationException( '{} is neither a service nor a container!'.format(s))
def __init__(self, config): self._config = config # Create container ships. self.ships = dict( (k, entities.Ship(k, v['ip'], docker_port=v.get('docker_port', entities.Ship. DEFAULT_DOCKER_PORT), ssh_tunnel=v.get('ssh_tunnel'), timeout=v.get('timeout'))) for k, v in self._config['ships'].items()) # Register defined private Docker registries authentications self.registries = self._config.get('registries') or {} for name, registry in self.registries.items(): if 'username' not in registry or 'password' not in registry: raise exceptions.OrchestrationException( 'Incomplete registry auth data for {}!'.format(name)) # Build all the entities. self.services = {} self.containers = {} for kind, service in self._config['services'].items(): self.services[kind] = entities.Service(kind, service['image'], service.get('env', {})) for name, instance in service['instances'].items(): self.containers[name] = \ entities.Container(name, self.ships[instance['ship']], self.services[kind], instance, self._config['name']) # Resolve dependencies between services. for kind, service in self._config['services'].items(): for dependency in service.get('requires', []): self.services[kind].add_dependency(self.services[dependency]) self.services[dependency].add_dependent(self.services[kind]) for wants_info in service.get('wants_info', []): self.services[kind].add_wants_info(self.services[wants_info]) # Provide link environment variables to each container of each service # that requires it or wants it. for service in self.services.values(): for container in service.containers: # Containers always know about their peers in the same service. container.env.update(service.get_link_variables(True)) # Containers also get links from the service's dependencies. for dependency in service.requires.union(service.wants_info): container.env.update(dependency.get_link_variables()) # Instantiate audit bindings self.auditor = audit.AuditorFactory.from_config( self._config.get('audit', []))
def __init__(self, config): self._config = config if 'name' not in config: raise exceptions.EnvironmentConfigurationException( 'Environment name is missing') self.ships = (shipproviders.ShipsProviderFactory .from_config(config).ships()) # Register defined private Docker registries authentications self.registries = self._config.get('registries') or {} for name, registry in self.registries.items(): if 'username' not in registry or 'password' not in registry: raise exceptions.OrchestrationException( 'Incomplete registry auth data for {}!'.format(name)) # Build all the entities. self.services = {} self.containers = {} for kind, service in self._config.get('services', {}).items(): self.services[kind] = entities.Service(kind, service['image'], self.schema, service.get('env', {})) for name, instance in service['instances'].items(): self.containers[name] = \ entities.Container(name, self.ships[instance['ship']], self.services[kind], instance, self.schema, self.env_name) # Resolve dependencies between services. for kind, service in self._config.get('services', {}).items(): for dependency in service.get('requires', []): self.services[kind].add_dependency(self.services[dependency]) self.services[dependency].add_dependent(self.services[kind]) for wants_info in service.get('wants_info', []): self.services[kind].add_wants_info(self.services[wants_info]) # Provide link environment variables to each container of each service # that requires it or wants it. for service in self.services.values(): for container in service.containers: # Containers always know about their peers in the same service. container.env.update(service.get_link_variables(True)) # Containers also get links from the service's dependencies. for dependency in service.requires.union(service.wants_info): container.env.update(dependency.get_link_variables()) # Check for host locality and volume conflicts on volumes_from for container in self.containers.values(): for volumes_from in container.volumes_from: if volumes_from not in self.containers: raise exceptions.InvalidVolumeConfigurationException( 'Unknown container {} to get volumes from for {}!' .format(volumes_from, container.name)) other = self.containers[volumes_from] if other.ship != container.ship: raise exceptions.InvalidVolumeConfigurationException( '{} and {} must be on the same host for ' 'volumes_from declaration in {}!' .format(other.name, container.name, container.name)) conflicts = container.get_volumes().intersection( other.get_volumes()) if conflicts: raise exceptions.InvalidVolumeConfigurationException( 'Volume conflicts between {} and {}: {}!' .format(container.name, other.name, ', '.join(conflicts))) # Instantiate audit bindings self.auditor = audit.AuditorFactory.from_config( self._config.get('audit', []))