Exemplo n.º 1
0
 def post_start(self):
     if not sh.isfile(self.init_fn) and self.get_bool_option('do-init'):
         self.wait_active()
         LOG.info("Running commands to initialize keystone.")
         (fn, contents) = utils.load_template(self.name, INIT_WHAT_FN)
         LOG.debug("Initializing with contents of %s", fn)
         params = {}
         params['keystone'] = khelper.get_shared_params(**utils.merge_dicts(self.options, khelper.get_shared_passwords(self)))
         params['glance'] = ghelper.get_shared_params(ip=self.get_option('ip'), **self.get_option('glance'))
         params['nova'] = nhelper.get_shared_params(ip=self.get_option('ip'), **self.get_option('nova'))
         params['neutron'] = net_helper.get_shared_params(ip=self.get_option('ip'), **self.get_option('neutron'))
         params['cinder'] = chelper.get_shared_params(ip=self.get_option('ip'), **self.get_option('cinder'))
         wait_urls = [
             params['keystone']['endpoints']['admin']['uri'],
             params['keystone']['endpoints']['public']['uri'],
         ]
         for url in wait_urls:
             utils.wait_for_url(url)
         init_what = utils.load_yaml_text(contents)
         init_what = utils.expand_template_deep(init_what, params)
         try:
             init_how = khelper.Initializer(params['keystone']['service_token'],
                                            params['keystone']['endpoints']['admin']['uri'])
             init_how.initialize(**init_what)
         except RuntimeError:
             LOG.exception("Failed to initialize keystone, is the keystone client library available?")
         else:
             # Writing this makes sure that we don't init again
             sh.write_file(self.init_fn, utils.prettify_yaml(init_what))
             LOG.info("If you wish to re-run initialization, delete %s", colorizer.quote(self.init_fn))
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)