示例#1
0
 def _do_network_init(self):
     ran_fn = self.net_init_fn
     if not sh.isfile(ran_fn) and self.get_bool_option("do-network-init"):
         # Figure out the commands to run
         cmds = []
         mp = {"CFG_FILE": self.config_path, "BIN_DIR": self.bin_dir}
         mp["BIN_DIR"] = self.bin_dir
         if self.get_bool_option("enable_fixed"):
             # Create a fixed network
             mp["FIXED_NETWORK_SIZE"] = self.get_option("fixed_network_size", default_value="256")
             mp["FIXED_RANGE"] = self.get_option("fixed_range", default_value="10.0.0.0/24")
             cmds.extend(FIXED_NET_CMDS)
         if self.get_bool_option("enable_floating"):
             # Create a floating network + test floating pool
             cmds.extend(FLOATING_NET_CMDS)
             mp["FLOATING_RANGE"] = self.get_option("floating_range", default_value="172.24.4.224/28")
             mp["TEST_FLOATING_RANGE"] = self.get_option("test_floating_range", default_value="192.168.253.0/29")
             mp["TEST_FLOATING_POOL"] = self.get_option("test_floating_pool", default_value="test")
         # Anything to run??
         if cmds:
             LOG.info("Creating your nova network to be used with instances.")
             utils.execute_template(*cmds, params=mp)
         # Writing this makes sure that we don't init again
         cmd_mp = {"cmds": cmds, "replacements": mp}
         sh.write_file(ran_fn, utils.prettify_yaml(cmd_mp))
         LOG.info("If you wish to re-run network initialization, delete %s", colorizer.quote(ran_fn))
示例#2
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['quantum'] = qhelper.get_shared_params(ip=self.get_option('ip'), **self.get_option('quantum'))
         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(self._filter_init(init_what), params)
         khelper.Initializer(params['keystone']['service_token'],
                             params['keystone']['endpoints']['admin']['uri']).initialize(**init_what)
         # 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))
示例#3
0
 def _do_network_init(self):
     ran_fn = sh.joinpths(self.get_option("trace_dir"), NET_INITED_FN)
     if not sh.isfile(ran_fn) and self.net_enabled:
         LOG.info("Creating your nova network to be used with instances.")
         # Figure out the commands to run
         mp = {}
         cmds = []
         mp["CFG_FILE"] = sh.joinpths(self.get_option("cfg_dir"), API_CONF)
         mp["BIN_DIR"] = sh.joinpths(self.get_option("app_dir"), BIN_DIR)
         if self.cfg.getboolean("nova", "enable_fixed"):
             # Create a fixed network
             mp["FIXED_NETWORK_SIZE"] = self.cfg.getdefaulted("nova", "fixed_network_size", "256")
             mp["FIXED_RANGE"] = self.cfg.getdefaulted("nova", "fixed_range", "10.0.0.0/24")
             cmds.extend(FIXED_NET_CMDS)
         if not self.get_option("quantum"):
             if self.cfg.getboolean("nova", "enable_floating"):
                 # Create a floating network + test floating pool
                 cmds.extend(FLOATING_NET_CMDS)
                 mp["FLOATING_RANGE"] = self.cfg.getdefaulted("nova", "floating_range", "172.24.4.224/28")
                 mp["TEST_FLOATING_RANGE"] = self.cfg.getdefaulted("nova", "test_floating_range", "192.168.253.0/29")
                 mp["TEST_FLOATING_POOL"] = self.cfg.getdefaulted("nova", "test_floating_pool", "test")
         else:
             LOG.info("Not creating floating IPs (not supported by quantum server)")
             LOG.info(
                 "Waiting %s seconds so that quantum can start up before running first time init." % (self.wait_time)
             )
             sh.sleep(self.wait_time)
         # Anything to run??
         if cmds:
             utils.execute_template(*cmds, params=mp)
         # Writing this makes sure that we don't init again
         cmd_mp = {"cmds": cmds, "replacements": mp}
         sh.write_file(ran_fn, utils.prettify_yaml(cmd_mp))
         LOG.info("If you wish to re-run initialization, delete %s", colorizer.quote(ran_fn))
示例#4
0
 def _do_network_init(self):
     ran_fn = self.net_init_fn
     if not sh.isfile(ran_fn) and self.get_bool_option('do-network-init'):
         # Figure out the commands to run
         cmds = []
         mp = {
             'CFG_FILE': self.config_path,
             'BIN_DIR': self.bin_dir
         }
         mp['BIN_DIR'] = self.bin_dir
         if self.get_bool_option('enable_fixed'):
             # Create a fixed network
             mp['FIXED_NETWORK_SIZE'] = self.get_option('fixed_network_size', default_value='256')
             mp['FIXED_RANGE'] = self.get_option('fixed_range', default_value='10.0.0.0/24')
             cmds.extend(FIXED_NET_CMDS)
         if self.get_bool_option('enable_floating'):
             # Create a floating network + test floating pool
             cmds.extend(FLOATING_NET_CMDS)
             mp['FLOATING_RANGE'] = self.get_option('floating_range', default_value='172.24.4.224/28')
             mp['TEST_FLOATING_RANGE'] = self.get_option('test_floating_range', default_value='192.168.253.0/29')
             mp['TEST_FLOATING_POOL'] = self.get_option('test_floating_pool', default_value='test')
         # Anything to run??
         if cmds:
             LOG.info("Creating your nova network to be used with instances.")
             utils.execute_template(*cmds, params=mp)
         # Writing this makes sure that we don't init again
         cmd_mp = {
             'cmds': cmds,
             'replacements': mp,
         }
         sh.write_file(ran_fn, utils.prettify_yaml(cmd_mp))
         LOG.info("If you wish to re-run network initialization, delete %s", colorizer.quote(ran_fn))
示例#5
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"))
         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(self._filter_init(init_what), params)
         khelper.Initializer(
             params["keystone"]["service_token"], params["keystone"]["endpoints"]["admin"]["uri"]
         ).initialize(**init_what)
         # 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))
示例#6
0
文件: nova.py 项目: spandhe/anvil
 def _do_network_init(self):
     if not sh.isfile(
             self.net_init_fn) and self.get_bool_option('do-network-init'):
         # Figure out the commands to run
         cmds = []
         mp = {}
         if self.get_bool_option('enable_fixed'):
             # Create a fixed network
             mp['FIXED_NETWORK_SIZE'] = self.get_option(
                 'fixed_network_size', default_value='256')
             mp['FIXED_RANGE'] = self.get_option(
                 'fixed_range', default_value='10.0.0.0/24')
             cmds.extend(FIXED_NET_CMDS)
         if self.get_bool_option('enable_floating'):
             # Create a floating network + test floating pool
             cmds.extend(FLOATING_NET_CMDS)
             mp['FLOATING_RANGE'] = self.get_option(
                 'floating_range', default_value='172.24.4.224/28')
             mp['TEST_FLOATING_RANGE'] = self.get_option(
                 'test_floating_range', default_value='192.168.253.0/29')
             mp['TEST_FLOATING_POOL'] = self.get_option(
                 'test_floating_pool', default_value='test')
         # Anything to run??
         if cmds:
             LOG.info(
                 "Creating your nova network to be used with instances.")
             utils.execute_template(*cmds, params=mp)
         # Writing this makes sure that we don't init again
         cmd_mp = {
             'cmds': cmds,
             'replacements': mp,
         }
         sh.write_file(self.net_init_fn, utils.prettify_yaml(cmd_mp))
         LOG.info("If you wish to re-run network initialization, delete %s",
                  colorizer.quote(self.net_init_fn))
示例#7
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))
示例#8
0
 def install(self):
     url_fn = self._extract_url_fn()
     if not url_fn:
         raise IOError("Can not determine file name from url: %r" %
                       (self.url))
     (cache_path, details_path) = self._cached_paths()
     use_cached = self._validate_cache(cache_path, details_path)
     if use_cached:
         LOG.info("Found valid cached image + metadata at: %s",
                  colorizer.quote(cache_path))
         unpack_info = utils.load_yaml_text(sh.load_file(details_path))
     else:
         sh.mkdir(cache_path)
         if not self._is_url_local():
             (fetched_fn, bytes_down) = down.UrlLibDownloader(
                 self.url, sh.joinpths(cache_path, url_fn)).download()
             LOG.debug("For url %s we downloaded %s bytes to %s", self.url,
                       bytes_down, fetched_fn)
         else:
             fetched_fn = self.url
         unpack_info = Unpacker().unpack(url_fn, fetched_fn, cache_path)
         sh.write_file(details_path, utils.prettify_yaml(unpack_info))
     tgt_image_name = self._generate_img_name(url_fn)
     img_id = self._register(tgt_image_name, unpack_info)
     return (tgt_image_name, img_id)
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)
示例#10
0
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)
示例#11
0
def store_current_settings(c_settings):
    try:
        # Remove certain keys that just shouldn't be saved
        to_save = dict(c_settings)
        for k in ["action", "verbose", "dryrun"]:
            if k in c_settings:
                to_save.pop(k, None)
        with open("/etc/anvil/settings.yaml", "w") as fh:
            fh.write("# Anvil last used settings\n")
            fh.write(utils.add_header("/etc/anvil/settings.yaml", utils.prettify_yaml(to_save)))
            fh.flush()
    except Exception as e:
        LOG.debug("Failed writing to %s due to %s", "/etc/anvil/settings.yaml", e)
示例#12
0
def store_current_settings(c_settings):
    try:
        # Remove certain keys that just shouldn't be saved
        to_save = dict(c_settings)
        for k in ['action', 'verbose']:
            if k in c_settings:
                to_save.pop(k, None)
        buf = six.StringIO()
        buf.write("# Anvil last used settings\n")
        buf.write(utils.add_header(SETTINGS_FILE,
                                   utils.prettify_yaml(to_save),
                                   adjusted=sh.isfile(SETTINGS_FILE)))
        sh.write_file(SETTINGS_FILE, buf.getvalue())
    except Exception as e:
        LOG.debug("Failed writing to %s due to %s", SETTINGS_FILE, e)
示例#13
0
def store_current_settings(settings):
    base_dir = sh.dirname(SETTINGS_FN)
    if not sh.isdir(base_dir):
        # Don't use sh here so that we always
        # read this (even if dry-run)    
        os.makedirs(base_dir)
    try:
        with sh.Rooted(True):
            with open(SETTINGS_FN, 'w') as fh:
                fh.write("# Anvil last used settings\n")
                fh.write(utils.add_header(SETTINGS_FN, utils.prettify_yaml(settings)))
                fh.flush()
        (uid, gid) = sh.get_suids()
        sh.chown_r(base_dir, uid, gid)
    except Exception as e:
        pass
示例#14
0
def store_current_settings(c_settings):
    try:
        # Remove certain keys that just shouldn't be saved
        to_save = dict(c_settings)
        for k in ['action', 'verbose', 'dryrun']:
            if k in c_settings:
                to_save.pop(k, None)
        with sh.Rooted(True):
            with open(SETTINGS_FN, 'w') as fh:
                fh.write("# Anvil last used settings\n")
                fh.write(utils.add_header(SETTINGS_FN, utils.prettify_yaml(to_save)))
                fh.flush()
        (uid, gid) = sh.get_suids()
        sh.chown(SETTINGS_FN, uid, gid)
    except Exception as e:
        LOG.debug("Failed writing to %s due to %s", SETTINGS_FN, e)
示例#15
0
文件: __main__.py 项目: minacel/anvil
def store_current_settings(c_settings):
    # Remove certain keys that just shouldn't be saved
    to_save = dict(c_settings)
    for k in ['action', 'verbose']:
        if k in c_settings:
            to_save.pop(k, None)
    buf = six.StringIO()
    buf.write("# Anvil last used settings\n")
    buf.write(
        utils.add_header(SETTINGS_FILE,
                         utils.prettify_yaml(to_save),
                         adjusted=sh.isfile(SETTINGS_FILE)))
    try:
        sh.write_file(SETTINGS_FILE, buf.getvalue())
    except OSError as e:
        LOG.warn("Failed writing to %s due to %s", SETTINGS_FILE, e)
示例#16
0
文件: __main__.py 项目: spandhe/anvil
def store_current_settings(c_settings):
    try:
        # Remove certain keys that just shouldn't be saved
        to_save = dict(c_settings)
        for k in ['action', 'verbose', 'dryrun']:
            if k in c_settings:
                to_save.pop(k, None)
        with open("/etc/anvil/settings.yaml", 'w') as fh:
            fh.write("# Anvil last used settings\n")
            fh.write(
                utils.add_header("/etc/anvil/settings.yaml",
                                 utils.prettify_yaml(to_save)))
            fh.flush()
    except Exception as e:
        LOG.debug("Failed writing to %s due to %s", "/etc/anvil/settings.yaml",
                  e)
 def post_start(self):
     if not sh.isfile(self.init_fn):
         LOG.info("Waiting %s seconds so that keystone can start up before running first time init." % (self.wait_time))
         sh.sleep(self.wait_time)
         LOG.info("Running commands to initialize keystone.")
         LOG.debug("Initializing with %s", self.init_what)
         initial_cfg = dict()
         initial_cfg['glance'] = ghelper.get_shared_params(self.cfg)
         initial_cfg['keystone'] = khelper.get_shared_params(self.cfg)
         initial_cfg['nova'] = nhelper.get_shared_params(self.cfg)
         initial_cfg['quantum'] = qhelper.get_shared_params(self.cfg)
         initial_cfg['swift'] = shelper.get_shared_params(self.cfg)
         init_what = utils.param_replace_deep(copy.deepcopy(self.init_what), initial_cfg)
         khelper.Initializer(initial_cfg['keystone']).initialize(**init_what)
         # 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))
示例#18
0
def store_current_settings(c_settings):
    try:
        # Remove certain keys that just shouldn't be saved
        to_save = dict(c_settings)
        for k in ['action', 'verbose', 'dryrun']:
            if k in c_settings:
                to_save.pop(k, None)
        with sh.Rooted(True):
            with open(SETTINGS_FN, 'w') as fh:
                fh.write("# Anvil last used settings\n")
                fh.write(
                    utils.add_header(SETTINGS_FN,
                                     utils.prettify_yaml(to_save)))
                fh.flush()
        (uid, gid) = sh.get_suids()
        sh.chown(SETTINGS_FN, uid, gid)
    except Exception as e:
        LOG.debug("Failed writing to %s due to %s", SETTINGS_FN, e)
示例#19
0
 def install(self):
     url_fn = self._extract_url_fn()
     if not url_fn:
         raise IOError("Can not determine file name from url: %r" % (self.url))
     (cache_path, details_path) = self._cached_paths()
     use_cached = self._validate_cache(cache_path, details_path)
     if use_cached:
         LOG.info("Found valid cached image + metadata at: %s", colorizer.quote(cache_path))
         unpack_info = utils.load_yaml_text(sh.load_file(details_path))
     else:
         sh.mkdir(cache_path)
         if not self._is_url_local():
             (fetched_fn, bytes_down) = down.UrlLibDownloader(self.url,
                                                              sh.joinpths(cache_path, url_fn)).download()
             LOG.debug("For url %s we downloaded %s bytes to %s", self.url, bytes_down, fetched_fn)
         else:
             fetched_fn = self.url
         unpack_info = Unpacker().unpack(url_fn, fetched_fn, cache_path)
         sh.write_file(details_path, utils.prettify_yaml(unpack_info))
     tgt_image_name = self._generate_img_name(url_fn)
     img_id = self._register(tgt_image_name, unpack_info)
     return (tgt_image_name, img_id)
示例#20
0
 def _update_passwords(self):
     if not self.store_passwords:
         return
     if not self.passwords.cache:
         return
     who_update = []
     for fn in self.password_files:
         if sh.isfile(fn):
             who_update.append(fn)
     if not who_update:
         who_update.append(self.default_password_file)
     who_done = []
     for fn in who_update:
         if sh.isfile(fn):
             contents = utils.load_yaml(fn)
         else:
             contents = {}
         contents.update(self.passwords.cache)
         sh.write_file(fn, utils.add_header(fn, utils.prettify_yaml(contents)))
         who_done.append(fn)
     utils.log_iterable(who_done,
                        header="Updated/created %s password files" % len(who_done),
                        logger=LOG)
示例#21
0
 def save_details(self, details):
     """Save cached image details."""
     sh.write_file(self._details_path, utils.prettify_yaml(details))
示例#22
0
 def _format_contents(self, contents):
     return utils.prettify_yaml(contents)
示例#23
0
 def _format_contents(self, contents):
     return utils.prettify_yaml(contents)