示例#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['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))
示例#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"))
         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 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))
示例#4
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)
示例#5
0
def load_previous_settings():
    settings_prev = None
    if sh.isfile(SETTINGS_FN):
        try:
            # Don't use sh here so that we always
            # read this (even if dry-run)    
            with open(SETTINGS_FN, 'r') as fh:
                settings_prev = utils.load_yaml_text(fh.read())
        except Exception:
            pass
    return settings_prev
示例#6
0
def load_previous_settings():
    settings_prev = None
    try:
        # Don't use sh here so that we always
        # read this (even if dry-run)
        with open(SETTINGS_FN, 'r') as fh:
            settings_prev = utils.load_yaml_text(fh.read())
    except Exception:
        # Errors could be expected on format problems
        # or on the file not being readable....
        pass
    return settings_prev
示例#7
0
def load_previous_settings():
    settings_prev = None
    try:
        # Don't use sh here so that we always
        # read this (even if dry-run)
        with open("/etc/anvil/settings.yaml", "r") as fh:
            settings_prev = utils.load_yaml_text(fh.read())
    except Exception:
        # Errors could be expected on format problems
        # or on the file not being readable....
        pass
    return settings_prev
示例#8
0
 def list_phases(self):
     if self.state is not None:
         return self.state
     state = {}
     # Shell not used to avoid dry-run capturing
     try:
         with open(self.fn, 'r') as fh:
             state = utils.load_yaml_text(fh.read())
             if not isinstance(state, (dict)):
                 raise TypeError("Phase file %s expected dictionary root type" % (self.fn))
     except IOError:
         pass
     self.state = state
     return self.state
示例#9
0
 def list_phases(self):
     if self.state is not None:
         return self.state
     state = {}
     # Shell not used to avoid dry-run capturing
     try:
         with open(self.filename, 'r') as fh:
             state = utils.load_yaml_text(fh.read())
             if not isinstance(state, (dict)):
                 raise TypeError(
                     "Phase file %s expected dictionary root type" %
                     (self.filename))
     except IOError:
         pass
     self.state = state
     return self.state
示例#10
0
 def _validate_cache(self, cache_path, details_path):
     for path in [cache_path, details_path]:
         if not sh.exists(path):
             return False
     check_files = []
     try:
         unpack_info = utils.load_yaml_text(sh.load_file(details_path))
         check_files.append(unpack_info['file_name'])
         if 'kernel' in unpack_info:
             check_files.append(unpack_info['kernel']['file_name'])
         if 'ramdisk' in unpack_info:
             check_files.append(unpack_info['ramdisk']['file_name'])
     except Exception:
         return False
     for path in check_files:
         if not sh.isfile(path):
             return False
     return True
示例#11
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)
示例#12
0
 def load_details(self):
     """Load cached image details."""
     return utils.load_yaml_text(sh.load_file(self._details_path))