def __init__(self, dbobj, logger, required_only=False): """Initialize the chooser. To clear out bindings that are not required, pass in required_only=True. Several staging areas and caches are set up within this object. The general flow is that potential service instance choices are kept in staging_services (dictionary of service to list of service instances) and finalized into chosen_services (dictionary of service to single service instance). The original state of the object is held in the cache original_service_instances (dictionary of service to single service instance). The instances_bound and instances_unbound lists are populated after chosen_services with the differences between chosen_services and original_service_instances. Subclasses should call this before starting their own initialization. """ self.dbobj = dbobj self.session = object_session(dbobj) self.required_only = required_only self.logger = logger self.description = self.generate_description() self.logger.debug("Creating service Chooser for %s", self.description) # Cache of the service maps self.mapped_services = {} # Stores interim service instance lists self.staging_services = {} # Report as many errors as possible in one shot self.errors = [] # Cache the servers backing service instances self.servers = {} # Set of service instances with a new client self.instances_bound = set() # Set of service instances losing a client self.instances_unbound = set() # Track the chosen services self.chosen_services = {} # Keep stashed plenaries for rollback purposes self.plenaries = PlenaryCollection(logger=self.logger)
legacy_env = HostEnvironment.get_unique(session, 'legacy', compel=True) if dbpersona.host_environment == legacy_env: HostEnvironment.polymorphic_subclass( host_environment, "Unknown environment name") Personality.validate_env_in_name(personality, host_environment) dbpersona.host_environment = HostEnvironment.get_unique( session, host_environment, compel=True) else: raise ArgumentError( "The personality '{0}' already has env set to '{1}'" " and cannot be updated".format(str(dbpersona), host_environment)) plenaries = PlenaryCollection(logger=logger) if grn or eon_id: dbgrn = lookup_grn(session, grn, eon_id, logger=logger, config=self.config) old_grn = dbpersona.owner_grn dbpersona.owner_grn = dbgrn if not leave_existing: # If this is a public personality, then there may be hosts with # various GRNs inside the personality, so make sure we preserve # those GRNs by filtering on the original GRN of the personality q = session.query(Host)