def _construct_siblings(self, name, siblings, base_params, sibling_instances): # First setup the sibling instance action references for (action, _entry_point) in siblings.items(): if action not in sibling_instances: sibling_instances[action] = {} there_siblings = {} for (action, entry_point) in siblings.items(): sibling_params = utils.merge_dicts(base_params, self.cli_opts, preserve=True) # Give the sibling the reference to all other siblings being created # which will be populated when they are created (now or later) for # the same action sibling_params['instances'] = sibling_instances[action] a_sibling = importer.construct_entry_point(entry_point, **sibling_params) # Update the sibling we are returning and the corresponding # siblings for that action (so that the sibling can have the # correct 'sibling' instances associated with it, if it needs those...) there_siblings[action] = a_sibling # Update all siblings being constructed so that there siblings will # be correct when fetched... sibling_instances[action][name] = a_sibling return there_siblings
def start(self): # Perform a check just to make sure said programs aren't already started and bail out # so that it we don't unintentionally start new ones and thus causing confusion for all # involved... what_may_already_be_started = [] try: what_may_already_be_started = self.tracereader.apps_started() except excp.NoTraceException: pass if what_may_already_be_started: msg = "%s programs of component %s may already be running, did you forget to stop those?" raise excp.StartException( msg % (len(what_may_already_be_started), self.name)) # Select how we are going to start it and get on with the show... runner_entry_point = self.get_option("run_type", default_value=DEFAULT_RUNNER) starter_args = [self, runner_entry_point] starter = importer.construct_entry_point(runner_entry_point, *starter_args) amount_started = 0 for program in self.applications: self._start_app(program, starter) amount_started += 1 return amount_started
def _construct_instances(self, persona): """ Create component objects for each component in the persona. """ persona_subsystems = persona.wanted_subsystems or {} persona_opts = persona.component_options or {} wanted_components = persona.wanted_components or [] # All siblings for the current persona instances = {} # Keeps track of all sibling instances across all components + actions # so that each instance or sibling instance will be connected to the # right set of siblings.... sibling_instances = {} for c in wanted_components: d_component = self.distro.extract_component(c, self.lookup_name) LOG.debug("Constructing component %r (%s)", c, d_component.entry_point) d_subsystems = d_component.options.pop('subsystems', {}) sibling_params = {} sibling_params['name'] = c # First create its siblings with a 'minimal' set of options # This is done, so that they will work in a minimal state, they do not # get access to the persona options since those are action specific (or could be), # if this is not useful, we can give them full access, unsure if its worse or better... active_subsystems = self._merge_subsystems( distro_subsystems=d_subsystems, desired_subsystems=persona_subsystems.get(c, [])) sibling_params['subsystems'] = active_subsystems sibling_params['siblings'] = { } # This gets adjusted during construction sibling_params['passwords'] = self.passwords sibling_params['distro'] = self.distro sibling_params['options'] = self._merge_options( c, component_opts=self._get_interpolated_options(c), distro_opts=d_component.options, persona_opts={}) LOG.debug("Constructing %r %s siblings...", c, len(d_component.siblings)) my_siblings = self._construct_siblings(c, d_component.siblings, sibling_params, sibling_instances) # Now inject the full options and create the target instance # with the full set of options and not the restricted set that # siblings get... instance_params = dict(sibling_params) instance_params['instances'] = instances instance_params['options'] = self._merge_options( c, component_opts=self._get_interpolated_options(c), distro_opts=d_component.options, persona_opts=persona_opts.get(c, {})) instance_params['siblings'] = my_siblings instance_params = utils.merge_dicts(instance_params, self.cli_opts, preserve=True) instances[c] = importer.construct_entry_point( d_component.entry_point, **instance_params) return instances
def start(self): # Select how we are going to start it run_type = self.get_option("run_type", default_value='anvil.runners.fork:ForkRunner') starter = importer.construct_entry_point(run_type, self) am_started = 0 for app_info in self.apps_to_start: self._start_app(app_info, run_type, starter) self._post_app_start(app_info) am_started += 1 return am_started
def start(self): # Select how we are going to start it run_type = self.get_option("run_type", default_value='anvil.runners.fork:ForkRunner') starter = importer.construct_entry_point(run_type, self) am_started = 0 for app_info in self.apps_to_start: self._start_app(app_info, run_type, starter) self._post_app_start(app_info) am_started += 1 return am_started
def _construct_instances(self, persona): """ Create component objects for each component in the persona. """ persona_subsystems = persona.wanted_subsystems or {} persona_opts = persona.component_options or {} wanted_components = persona.wanted_components or [] # All siblings for the current persona instances = {} # Keeps track of all sibling instances across all components + actions # so that each instance or sibling instance will be connected to the # right set of siblings.... sibling_instances = {} for c in wanted_components: d_component = self.distro.extract_component(c, self.lookup_name) LOG.debug("Constructing component %r (%s)", c, d_component.entry_point) d_subsystems = d_component.options.pop("subsystems", {}) sibling_params = {} sibling_params["name"] = c # First create its siblings with a 'minimal' set of options # This is done, so that they will work in a minimal state, they do not # get access to the persona options since those are action specific (or could be), # if this is not useful, we can give them full access, unsure if its worse or better... active_subsystems = self._merge_subsystems( distro_subsystems=d_subsystems, desired_subsystems=persona_subsystems.get(c, []) ) sibling_params["subsystems"] = active_subsystems sibling_params["siblings"] = {} # This gets adjusted during construction sibling_params["passwords"] = self.passwords sibling_params["distro"] = self.distro sibling_params["options"] = self._merge_options( c, component_opts=self._get_interpolated_options(c), distro_opts=d_component.options, persona_opts={} ) LOG.debug("Constructing %r %s siblings...", c, len(d_component.siblings)) my_siblings = self._construct_siblings(c, d_component.siblings, sibling_params, sibling_instances) # Now inject the full options and create the target instance # with the full set of options and not the restricted set that # siblings get... instance_params = dict(sibling_params) instance_params["instances"] = instances instance_params["options"] = self._merge_options( c, component_opts=self._get_interpolated_options(c), distro_opts=d_component.options, persona_opts=persona_opts.get(c, {}), ) instance_params["siblings"] = my_siblings instance_params = utils.merge_dicts(instance_params, self.cli_opts, preserve=True) instances[c] = importer.construct_entry_point(d_component.entry_point, **instance_params) return instances
def _construct_instances(self, persona): """Create component objects for each component in the persona.""" # Keeps track of all sibling instances across all components + actions # so that each instance or sibling instance will be connected to the # right set of siblings.... sibling_instances = {} components_created = set() groups = [] for group in persona.matched_components: instances = utils.OrderedDict() for c in group: if c in components_created: raise RuntimeError("Can not duplicate component %s in a" " later group %s" % (c, group.id)) d_component = self.distro.extract_component( c, self.lookup_name, default_entry_point_creator=self._make_default_entry_points) LOG.debug("Constructing component %r (%s)", c, d_component.entry_point) d_subsystems = d_component.options.pop('subsystems', {}) sibling_params = {} sibling_params['name'] = c # First create its siblings with a 'minimal' set of options # This is done, so that they will work in a minimal state, they do not # get access to the persona options since those are action specific (or could be), # if this is not useful, we can give them full access, unsure if its worse or better... active_subsystems = self._merge_subsystems(distro_subsystems=d_subsystems, desired_subsystems=persona.wanted_subsystems.get(c, [])) sibling_params['subsystems'] = active_subsystems sibling_params['siblings'] = {} # This gets adjusted during construction sibling_params['distro'] = self.distro sibling_params['options'] = self.config_loader.load( distro=d_component, component=c, origins_patch=self.cli_opts.get('origins_patch')) LOG.debug("Constructing %r %s siblings...", c, len(d_component.siblings)) my_siblings = self._construct_siblings(c, d_component.siblings, sibling_params, sibling_instances) # Now inject the full options and create the target instance # with the full set of options and not the restricted set that # siblings get... instance_params = dict(sibling_params) instance_params['instances'] = instances instance_params['options'] = self.config_loader.load( distro=d_component, component=c, persona=persona, origins_patch=self.cli_opts.get('origins_patch')) instance_params['siblings'] = my_siblings instance_params = utils.merge_dicts(instance_params, self.cli_opts, preserve=True) instances[c] = importer.construct_entry_point(d_component.entry_point, **instance_params) if c not in SPECIAL_GROUPS: components_created.add(c) groups.append((group.id, instances)) return groups
def _locate_investigators(self, apps_started): investigator_created = {} to_investigate = [] for (app_name, _trace_fn, run_type) in apps_started: investigator = investigator_created.get(run_type) if investigator is None: try: investigator = importer.construct_entry_point(run_type, self) investigator_created[run_type] = investigator except RuntimeError as e: LOG.warn("Could not load class %s which should be used to investigate %s: %s", colorizer.quote(run_type), colorizer.quote(app_name), e) continue to_investigate.append((app_name, investigator)) return to_investigate
def _locate_investigators(self, apps_started): investigator_created = {} to_investigate = [] for (app_name, _trace_fn, run_type) in apps_started: investigator = investigator_created.get(run_type) if investigator is None: try: investigator = importer.construct_entry_point(run_type, self) investigator_created[run_type] = investigator except RuntimeError as e: LOG.warn("Could not load class %s which should be used to investigate %s: %s", colorizer.quote(run_type), colorizer.quote(app_name), e) continue to_investigate.append((app_name, investigator)) return to_investigate
def _locate_investigators(self, applications_started): # Recreate the runners that can be used to dive deeper into the applications list # that was started (a 3 tuple of (name, trace, who_started)). investigators_created = {} to_investigate = [] for (name, _trace, who_started) in applications_started: investigator = investigators_created.get(who_started) if investigator is None: try: investigator_args = [self, who_started] investigator = importer.construct_entry_point(who_started, *investigator_args) investigators_created[who_started] = investigator except RuntimeError as e: LOG.warn("Could not load class %s which should be used to investigate %s: %s", colorizer.quote(who_started), colorizer.quote(name), e) continue to_investigate.append((name, investigator)) return to_investigate
def _locate_investigators(self, applications_started): # Recreate the runners that can be used to dive deeper into the applications list # that was started (a 3 tuple of (name, trace, who_started)). investigators_created = {} to_investigate = [] for (name, _trace, who_started) in applications_started: investigator = investigators_created.get(who_started) if investigator is None: try: investigator_args = [self, who_started] investigator = importer.construct_entry_point( who_started, *investigator_args) investigators_created[who_started] = investigator except RuntimeError as e: LOG.warn( "Could not load class %s which should be used to investigate %s: %s", colorizer.quote(who_started), colorizer.quote(name), e) continue to_investigate.append((name, investigator)) return to_investigate
def replace_services_endpoints(token, options): client = importer.construct_entry_point( "keystoneclient.v2_0.client:Client", token=token, endpoint=options.keystone_uri) current_endpoints = client.endpoints.list() current_services = client.services.list() def filter_resource(r): raw = dict(r.__dict__) # Can't access the raw attrs, arg... raw_cleaned = {} for k, v in raw.items(): if k == 'manager' or k.startswith('_'): continue raw_cleaned[k] = v return raw_cleaned for e in current_endpoints: print("Deleting endpoint: ") print(utils.prettify_yaml(filter_resource(e))) client.endpoints.delete(e.id) for s in current_services: print("Deleting service: ") print(utils.prettify_yaml(filter_resource(s))) client.services.delete(s.id) if options.file: with (open(options.file, 'r')) as fh: contents = yaml.load(fh) set_contents = { 'services': contents.get('services', []), 'endpoints': contents.get('endpoints', []), } print("Regenerating with:") print(utils.prettify_yaml(set_contents)) set_contents['users'] = [] set_contents['roles'] = [] set_contents['tenants'] = [] initer = keystone.Initializer(token, options.keystone_uri) initer.initialize(**set_contents)
def _construct_siblings(self, name, siblings, base_params, sibling_instances): # First setup the sibling instance action references for (action, _entry_point) in siblings.items(): if action not in sibling_instances: sibling_instances[action] = {} there_siblings = {} for (action, entry_point) in siblings.items(): sibling_params = utils.merge_dicts(base_params, self.cli_opts, preserve=True) # Give the sibling the reference to all other siblings being created # which will be populated when they are created (now or later) for # the same action sibling_params['instances'] = sibling_instances[action] a_sibling = importer.construct_entry_point(entry_point, **sibling_params) # Update the sibling we are returning and the corresponding # siblings for that action (so that the sibling can have the # correct 'sibling' instances associated with it, if it needs those...) there_siblings[action] = a_sibling # Update all siblings being constructed so that there siblings will # be correct when fetched... sibling_instances[action][name] = a_sibling return there_siblings
def start(self): # Perform a check just to make sure said programs aren't already started and bail out # so that it we don't unintentionally start new ones and thus causing confusion for all # involved... what_may_already_be_started = [] try: what_may_already_be_started = self.tracereader.apps_started() except excp.NoTraceException: pass if what_may_already_be_started: msg = "%s programs of component %s may already be running, did you forget to stop those?" raise excp.StartException(msg % (len(what_may_already_be_started), self.name)) # Select how we are going to start it and get on with the show... runner_entry_point = self.get_option("run_type", default_value=DEFAULT_RUNNER) starter_args = [self, runner_entry_point] starter = importer.construct_entry_point(runner_entry_point, *starter_args) amount_started = 0 for program in self.applications: self._start_app(program, starter) amount_started += 1 return amount_started
def replace_services_endpoints(token, options): client = importer.construct_entry_point("keystoneclient.v2_0.client:Client", token=token, endpoint=options.keystone_uri) current_endpoints = client.endpoints.list() current_services = client.services.list() def filter_resource(r): raw = dict(r.__dict__) # Can't access the raw attrs, arg... raw_cleaned = {} for k, v in raw.items(): if k == 'manager' or k.startswith('_'): continue raw_cleaned[k] = v return raw_cleaned for e in current_endpoints: print("Deleting endpoint: ") print(utils.prettify_yaml(filter_resource(e))) client.endpoints.delete(e.id) for s in current_services: print("Deleting service: ") print(utils.prettify_yaml(filter_resource(s))) client.services.delete(s.id) if options.file: with(open(options.file, 'r')) as fh: contents = yaml.load(fh) set_contents = { 'services': contents.get('services', []), 'endpoints': contents.get('endpoints', []), } print("Regenerating with:") print(utils.prettify_yaml(set_contents)) set_contents['users'] = [] set_contents['roles'] = [] set_contents['tenants'] = [] initer = keystone.Initializer(token, options.keystone_uri) initer.initialize(**set_contents)
def __init__(self, service_token, admin_uri): # Late load since its using a client lib that is only avail after install... self.client = importer.construct_entry_point("keystoneclient.v2_0.client:Client", token=service_token, endpoint=admin_uri)
def _construct_instances(self, persona): """Create component objects for each component in the persona.""" # Keeps track of all sibling instances across all components + actions # so that each instance or sibling instance will be connected to the # right set of siblings.... sibling_instances = {} components_created = set() groups = [] for group in persona.matched_components: instances = utils.OrderedDict() for c in group: if c in components_created: raise RuntimeError("Can not duplicate component %s in a" " later group %s" % (c, group.id)) d_component = self.distro.extract_component( c, self.lookup_name, default_entry_point_creator=self._make_default_entry_points ) LOG.debug("Constructing component %r (%s)", c, d_component.entry_point) d_subsystems = d_component.options.pop('subsystems', {}) sibling_params = {} sibling_params['name'] = c # First create its siblings with a 'minimal' set of options # This is done, so that they will work in a minimal state, they do not # get access to the persona options since those are action specific (or could be), # if this is not useful, we can give them full access, unsure if its worse or better... active_subsystems = self._merge_subsystems( distro_subsystems=d_subsystems, desired_subsystems=persona.wanted_subsystems.get(c, [])) sibling_params['subsystems'] = active_subsystems sibling_params['siblings'] = { } # This gets adjusted during construction sibling_params['distro'] = self.distro sibling_params['options'] = self.config_loader.load( distro=d_component, component=c, origins_patch=self.cli_opts.get('origins_patch')) LOG.debug("Constructing %r %s siblings...", c, len(d_component.siblings)) my_siblings = self._construct_siblings(c, d_component.siblings, sibling_params, sibling_instances) # Now inject the full options and create the target instance # with the full set of options and not the restricted set that # siblings get... instance_params = dict(sibling_params) instance_params['instances'] = instances instance_params['options'] = self.config_loader.load( distro=d_component, component=c, persona=persona, origins_patch=self.cli_opts.get('origins_patch')) instance_params['siblings'] = my_siblings instance_params = utils.merge_dicts(instance_params, self.cli_opts, preserve=True) instances[c] = importer.construct_entry_point( d_component.entry_point, **instance_params) if c not in SPECIAL_GROUPS: components_created.add(c) groups.append((group.id, instances)) return groups
def __init__(self, service_token, admin_uri): # Late load since its using a client lib that is only avail after install... self.client = importer.construct_entry_point( "keystoneclient.v2_0.client:Client", token=service_token, endpoint=admin_uri)