Exemple #1
0
def get_keystone_init(**kwargs):
    """
    Simple function to retrieve configuration information from
    the global environment.  If no kwargs is passed in, the necessary
    information is retrieved from the environment (ie, as when you source
    keystonerc_admin)

    The valid (optional) kwargs are:
      username: -> "OS_USERNAME"
      password: -> "
    :rtype : dict
    :return: A dictionary that can be used for keystone client
    """
    if not kwargs:
        config = load_config(__file__, "smog_config.yml", ["config"])
        os.environ.update(
            {k: v
             for k, v in config["credentials"].items() if v is not None})

    creds = {
        "username": os.environ.get("OS_USERNAME"),
        "password": os.environ.get("OS_PASSWORD"),
        "auth_url": os.environ.get("OS_AUTH_URL"),
        "tenant_name": os.environ.get("OS_TENANT_NAME")
    }

    # could have used short-cut evaluation, but this seemed more functional
    creds.update(
        {k: v
         for k, v in kwargs.items() if k in creds and v is not None})
    glob_logger.debug("Using keystone creds: {}".format(creds))

    valid_versions = ("/v2.0", "/v3")
    for v in valid_versions:
        if creds["auth_url"].endswith(v):
            creds["auth_url"] += "/v2.0/"

    return creds
Exemple #2
0
    def __init__(self, logger=glob_logger):
        super(ConfigureNFS, self).__init__(logger=logger)
        # Ughhh dynamic languages.  Put this here to help the IDE
        self.system_info_cfg = None
        self.share_storage_cfg = {}
        self.nova_cfg = None
        self.libvirtd_cfg = None
        self.firewall_cfg = None

        conf_files = ["system_info.yml", "share_storage.yml", "nova.yml",
                      "libvirtd.yml", "firewall.yml"]
        names = [x.replace(".yml", "_cfg") for x in conf_files]
        fn = lambda x: load_config(__file__, x, extra_paths=["configs"])
        cfgs = map(fn, conf_files)
        make = lambda y, z: setattr(self, y, z)
        res = list(map(make, names, cfgs))

        # For those not familiar with functional programming, the above is
        # equivalent to this:
        # self.system_info_cfg = load_config(__file__, "system_info.yml",
        #                                    extra_paths=["configs"])
        # self.share_storage_cfg = load_config(__file__, "share_storage.yml",
        #                                     extra_paths=["configs"])
        # ...

        self.opts = self.get_args()
        self.args_override()
        self.nfs_server = None
        self.nfssrv_info = None
        self.computes = self.system_info_cfg["hosts"]["computes"].split(",")
        controllers = self.system_info_cfg["hosts"]["controllers"]
        self.controllers = controllers.split(",")
        self.comp_info = {ip: distro_factory(ip) for ip in self.computes}

        self.setup_system_info()
        self.configure_nfs()
Exemple #3
0
def get_keystone_init(**kwargs):
    """
    Simple function to retrieve configuration information from
    the global environment.  If no kwargs is passed in, the necessary
    information is retrieved from the environment (ie, as when you source
    keystonerc_admin)

    The valid (optional) kwargs are:
      username: -> "OS_USERNAME"
      password: -> "
    :rtype : dict
    :return: A dictionary that can be used for keystone client
    """
    if not kwargs:
        config = load_config(__file__, "smog_config.yml", ["config"])
        os.environ.update({k: v
                           for k, v in config["credentials"].items()
                           if v is not None})

    creds = {"username": os.environ.get("OS_USERNAME"),
             "password": os.environ.get("OS_PASSWORD"),
             "auth_url": os.environ.get("OS_AUTH_URL"),
             "tenant_name": os.environ.get("OS_TENANT_NAME")}


    # could have used short-cut evaluation, but this seemed more functional
    creds.update({k: v for k, v in kwargs.items()
                  if k in creds and v is not None})
    glob_logger.debug("Using keystone creds: {}".format(creds))

    valid_versions = ("/v2.0", "/v3")
    for v in valid_versions:
        if creds["auth_url"].endswith(v):
            creds["auth_url"] += "/v2.0/"

    return creds