当前位置: 首页>>代码示例>>Python>>正文


Python Config.path_expand方法代码示例

本文整理汇总了Python中cloudmesh_client.common.ConfigDict.Config.path_expand方法的典型用法代码示例。如果您正苦于以下问题:Python Config.path_expand方法的具体用法?Python Config.path_expand怎么用?Python Config.path_expand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cloudmesh_client.common.ConfigDict.Config的用法示例。


在下文中一共展示了Config.path_expand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_from_dir

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def get_from_dir(cls, directory=None, store=True):
        directory = directory or Config.path_expand("~/.ssh")
        files = [file for file in os.listdir(expanduser(Config.path_expand(directory)))
                 if file.lower().endswith(".pub")]
        d = []
        for file in files:
            location = Config.path_expand("{:}/{:}".format(directory, file))

            sshkey = SSHkey(location).get()

            i = sshkey["comment"]
            if i is not None:
                i = i.replace("@", "_")
                i = i.replace("-", "_")
                i = i.replace(" ", "_")
                i = i.replace(".", "_")
            else:
                # use base name
                i = file.replace(".pub", "")
            sshkey["kind"] = "key"
            sshkey["source"] = 'file'

            if store:
                cls._add_from_sshkey(
                    dict(sshkey),
                    keyname=sshkey["name"],
                    source=sshkey["source"],
                    uri=sshkey["uri"])
            else:
                d.append(dict(sshkey))
        if not store:
            return d
开发者ID:arpiagariu,项目名称:client,代码行数:34,代码来源:key.py

示例2: get_from_dir

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def get_from_dir(self, directory=None):
        directory = directory or Config.path_expand("~/.ssh")
        files = [file for file in os.listdir(expanduser(Config.path_expand(directory)))
                 if file.lower().endswith(".pub")]
        for file in files:
            location = Config.path_expand("{:}/{:}".format(directory, file))

            sshkey = SSHkey(location)
            i = sshkey.comment
            self.__keys__[i] = sshkey.__key__
开发者ID:sohiljain,项目名称:client,代码行数:12,代码来源:SSHKeyManager.py

示例3: add_from_path

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def add_from_path(cls,
                      path,
                      keyname=None,
                      user=None,
                      source=None,
                      uri=None,
                      store=True):
        """
        Adds the key to the database based on the path

        :param keyname: name of the key or path to the key
        :return:
        """

        user = user or cls.cm.user

        sshkey = SSHkey(Config.path_expand(path))

        if store:
            cls._add_from_sshkey(sshkey.__key__,
                             keyname,
                             user,
                             source=source,
                             uri=uri)
        else:
            return sshkey.__key__
开发者ID:arpiagariu,项目名称:client,代码行数:28,代码来源:key.py

示例4: get_hostuser

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def get_hostuser(cls, host):
        """
        Method to return user login
        for a host in ssh config
        :param host:
        :return:
        """
        filename = Config.path_expand("~/.ssh/config")
        with open(filename, 'r') as f:
            lines = f.read().split("\n")

        found = False
        for line in lines:
            # search for host
            if "Host " in line:
                _host = line.strip().replace("Host ", "", 1).replace(" ", "")
                # if host found in ssh config
                if _host == host:
                    found = True
                    pass

            # search for user
            if "User " in line and found is True:
                # return corresponding user
                username = line.strip().replace("User ", "", 1).replace(" ", "")
                return username
开发者ID:rajaramcomputers,项目名称:client,代码行数:28,代码来源:sync.py

示例5: read

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def read(self, file_path, keyname=None):
        self.__key__ = {}
        if file_path is not None:
            file_path = Config.path_expand(file_path)
            uri = 'file://{}'.format(file_path)
            self.__key__ = {
                'uri': uri,
                'string': open(file_path, "r").read().rstrip()
            }

            (self.__key__['type'],
             self.__key__['key'],
             self.__key__['comment']) = self._parse(self.__key__['string'])
            self.__key__['fingerprint'] = self._fingerprint(self.__key__['string'])

            # Workaround for multiple file entries in cloudmesh.yaml getting same name derived from file name (like id_rsa).
            # This caused the dict to have just 1 entry as the name is the key.
            # Change tracked in git issue #8
            if keyname is None:
                name = basename(file_path).replace(".pub", "").replace("id_", "")
            else:
                name = keyname

            self.__key__['name'] = name
            self.__key__['comment'] = self.__key__['comment']
            self.__key__['source'] = 'ssh'
        return self.__key__
开发者ID:rajaramcomputers,项目名称:client,代码行数:29,代码来源:SSHkey.py

示例6: remote

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def remote(cls, host, force=False):
        """

        TODO: there is a bug in the instalation of kilo the openrc file on
        the remote machine is not called openrc.sh but contains username and
        project number.

        :param host: the remote host
        :param force:
        :return:
        """

        config = ConfigDict("cloudmesh.yaml")

        host_spec = config["cloudmesh.clouds." + host]
        host_credentials = host_spec["credentials"]

        if 'cm_openrc' in host_spec:
            Console.ok("looking for openrc")
        else:
            Console.error("no cm_openrc specified in the host")
            return

        hostname = config["cloudmesh.clouds." + host + ".cm_host"]
        Console.ok("fetching information from {:}  ...".format(host))

        openrc = host_spec["cm_openrc"]

        directory = os.path.dirname(openrc)
        base = os.path.basename(openrc)

        _from_dir = "{:}:{:}".format(hostname, directory).replace("~/", "")
        _to_dir = os.path.dirname(Config.path_expand(directory))
        openrc_file = Config.path_expand(openrc)
        print("From:  ", _from_dir)
        print("To:    ", _to_dir)
        print("Openrc:", openrc_file)

        cls.make_dir(_to_dir)
        r = ""
        Console.ok("Reading rc file from {}".format(host))
        try:
            r = Shell.scp('-r', _from_dir, _to_dir)
        except Exception, e:
            print(e)
            return
开发者ID:atavism,项目名称:client,代码行数:48,代码来源:register.py

示例7: initialize

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def initialize(self, cloudname, user=None):

        d = ConfigDict("cloudmesh.yaml")
        self.cloud_details = d["cloudmesh"]["clouds"][cloudname]

        # pprint(self.cloud_details)

        self.cloud = cloudname
        self.default_flavor = self.cloud_details["default"]["flavor"]
        self.default_image = self.cloud_details["default"]["image"]
        self.tenant = self.cloud_details['credentials']['OS_TENANT_NAME']
        version = 2
        credentials = self.cloud_details["credentials"]
        cert = False
        if "OS_CACERT" in credentials:
            if credentials["OS_CACERT"] is not False:
                cert = Config.path_expand(credentials["OS_CACERT"])
        auth_url = credentials["OS_AUTH_URL"]
        ksversion = auth_url.split("/")[-1]

        """
        # GitHub issue 101
        # mechanism to interactively ask for password
        # when OS_PASSWORD set as "readline",
        # or read os.environ if set as "env".
        """
        os_password = credentials["OS_PASSWORD"]
        prompt = "Password for cloud - {}:".format(cloudname)
        if os_password.lower() in ["readline", "read", "tbd"]:
            if cloudname in CloudProviderOpenstackAPI.cloud_pwd and \
                        'pwd' in CloudProviderOpenstackAPI.cloud_pwd[cloudname]:
                os_password = CloudProviderOpenstackAPI.cloud_pwd[cloudname]["pwd"]
            else:
                os_password = getpass.getpass(prompt=prompt)
        elif os_password.lower() == "env":
            if cloudname in CloudProviderOpenstackAPI.cloud_pwd and \
                        'pwd' in CloudProviderOpenstackAPI.cloud_pwd[cloudname]:
                os_password = CloudProviderOpenstackAPI.cloud_pwd[cloudname]["pwd"]
            else:
                os_password = os.environ.get("OS_PASSWORD", getpass.getpass(prompt=prompt))

        # store the password for this session
        CloudProviderOpenstackAPI.cloud_pwd[cloudname] = {}
        CloudProviderOpenstackAPI.cloud_pwd[cloudname]["pwd"] = os_password
        CloudProviderOpenstackAPI.cloud_pwd[cloudname]["status"] = "Active"

        if "v2.0" == ksversion:
            self.provider = client.Client(
                version,
                credentials["OS_USERNAME"],
                os_password,
                credentials["OS_TENANT_NAME"],
                credentials["OS_AUTH_URL"],
                cert)
        elif "v3" == ksversion:
            sess = session.Session(auth=self._ksv3_auth(credentials),
                                   verify=cert)
            self.provider = client.Client(2, session=sess)
开发者ID:pombredanne,项目名称:client-6,代码行数:60,代码来源:CloudProviderOpenstackAPI.py

示例8: __init__

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def __init__(self):
        self.__dict__ = self.__shared_state

        if self.initialized is None:
            self.filename = Config.path_expand(os.path.join("~", ".cloudmesh", "cloudmesh.db"))
            self.create()
            self.create_tables()
            self.start()
            self.user = ConfigDict(filename="cloudmesh.yaml")["cloudmesh.profile.user"]
开发者ID:arpiagariu,项目名称:client,代码行数:11,代码来源:CloudmeshDatabase.py

示例9: sync

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def sync(cls, cloudname, localdir, remotedir, operation=None):
        """
        Syncs a local directory with a remote directory.
        Either from local to remote OR vice-versa
        :param cloudname:
        :param localdir:
        :param remotedir:
        :param operation: get/put
        :return:
        """
        # Get the operating system
        os_type = cls.operating_system()

        # fix the local dir path
        localdirpath = Config.path_expand(localdir)

        # check if local directory exists
        if not os.path.exists(localdirpath):
            if operation == "put":
                Console.error("The local directory [{}] does not exist."
                              .format(localdirpath))
                return None
            elif operation == "get":
                # for receiving, create local dir
                os.mkdir(localdirpath)
                Console.msg("Created local directory [{}] for sync."
                            .format(localdirpath))

        """
            rsync now works on windows machines as well.
            we install rsync (v5.4.1.20150827) on windows via chocolatey
            $ choco install rsync
        """

        host = cls.get_host(cloudname)
        if host is None:
            Console.error("Cloud [{}] not found in cloudmesh.yaml file."
                          .format(cloudname))
            return None
        else:
            args = None
            if operation == "put":
                args = [
                    "-r",
                    localdir,
                    host + ":" + remotedir
                ]
            elif operation == "get":
                args = [
                    "-r",
                    host + ":" + remotedir,
                    localdir
                ]
            # call rsync
            return Shell.rsync(*args)
开发者ID:arpiagariu,项目名称:client,代码行数:57,代码来源:sync.py

示例10: set_os_environment

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
 def set_os_environment(cls, cloudname):
     try:
         d = ConfigDict("cloudmesh.yaml")
         credentials = d["cloudmesh"]["clouds"][cloudname]["credentials"]
         for key in credentials.keys():
             if key == "OS_CACERT":
                 os.environ[key] = Config.path_expand(credentials[key])
             else:
                 os.environ[key] = credentials[key]
     except Exception, e:
         print(e)
开发者ID:atavism,项目名称:client,代码行数:13,代码来源:_sh_quota.py

示例11: get_from_yaml

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
 def get_from_yaml(self, filename=None, load_order=None):
     """
     :param filename: name of the yaml file
     :return: a SSHKeyManager (dict of keys)
     """
     config = None
     if filename is None:
         # default = Config.path_expand(os.path.join("~", ".cloudmesh", "cloudmesh.yaml"))
         # config = ConfigDict("cloudmesh.yaml")
         filename = "cloudmesh.yaml"
         config = ConfigDict(filename)
     elif load_order:
         config = ConfigDict(filename, load_order)
     else:
         Console.error("Wrong arguments")
         return
     config_keys = config["cloudmesh"]["keys"]
     default = config_keys["default"]
     keylist = config_keys["keylist"]
     sshmanager = SSHKeyManager()
     for key in list(keylist.keys()):
         keyname = key
         value = keylist[key]
         if os.path.isfile(Config.path_expand(value)):
             path = Config.path_expand(value)
             sshmanager.add_from_file(path, keyname)
         else:
             sshkey = SSHkey()
             uri = Config.path_expand(os.path.join("~", ".cloudmesh", filename))
             sshkey.__key__['uri'] = 'yaml://{}'.format(uri)
             sshkey.__key__['string'] = value
             (sshkey.__key__['type'],
              sshkey.__key__['key'],
              sshkey.__key__['comment']) = sshkey._parse(sshkey.__key__['string'])
             sshkey.__key__['fingerprint'] = sshkey._fingerprint(sshkey.__key__['string'])
             sshkey.__key__['name'] = keyname
             sshkey.__key__['filename'] = filename
             sshmanager.add_from_object(sshkey)
     return sshmanager
     """
开发者ID:sohiljain,项目名称:client,代码行数:42,代码来源:SSHKeyManager.py

示例12: activate

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def activate(self):
        """activates the shared variables"""

        # engine = create_engine('sqlite:////tmp/test.db', echo=debug)

        self.filename = Config.path_expand(
            os.path.join("~", ".cloudmesh", "cloudmesh.db"))
        self.endpoint = 'sqlite:///{:}'.format(self.filename)
        self.engine = create_engine(self.endpoint)
        self.Base = declarative_base(bind=self.engine)

        self.meta = MetaData()
        self.meta.reflect(bind=self.engine)
开发者ID:rajaramcomputers,项目名称:client,代码行数:15,代码来源:model.py

示例13: set_os_environ

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def set_os_environ(cls, cloudname):
        """Set os environment variables on a given cloudname"""
        try:
            d = ConfigDict("cloudmesh.yaml")
            credentials = d["cloudmesh"]["clouds"][cloudname]["credentials"]
            for key, value in credentials.iteritems():
                if key == "OS_CACERT":
                    os.environ[key] = Config.path_expand(value)
                else:
                    os.environ[key] = value

                print("Key: " + key + ", Value: " + os.environ[key])

            nova = client.Client("2",
                                 credentials["OS_USERNAME"],
                                 credentials["OS_PASSWORD"],
                                 credentials["OS_TENANT_NAME"],
                                 credentials["OS_AUTH_URL"],
                                 Config.path_expand(credentials["OS_CACERT"]))
            return nova
        except Exception, e:
            print(e)
开发者ID:rajaramcomputers,项目名称:client,代码行数:24,代码来源:secgroup.py

示例14: add

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
    def add(self, key_path, keyname=None, user=None, source=None, uri=None):
        """
        Adds the key to the database based on the path

        :param keyname: name of the key or path to the key
        :return:
        """

        sshkey = SSHkey(Config.path_expand(key_path))

        self.add_from_sshkey(sshkey.__key__,
                             keyname, user,
                             source=source,
                             uri=uri)
开发者ID:rajaramcomputers,项目名称:client,代码行数:16,代码来源:SSHKeyDBManager.py

示例15: set_os_environ

# 需要导入模块: from cloudmesh_client.common.ConfigDict import Config [as 别名]
# 或者: from cloudmesh_client.common.ConfigDict.Config import path_expand [as 别名]
def set_os_environ(cloudname):
    """Set os environment variables on a given cloudname"""
    # TODO: this has a severe bug as it is not unsetting variables
    # Also this coded duplicates in part from register
    try:
        d = ConfigDict("cloudmesh.yaml")
        credentials = d["cloudmesh"]["clouds"][cloudname]["credentials"]
        for key, value in credentials.iteritems():
            if key == "OS_CACERT":
                os.environ[key] = Config.path_expand(value)
            else:
                os.environ[key] = value
    except Exception as e:
        print(e)
开发者ID:alistairking,项目名称:client,代码行数:16,代码来源:CloudProviderOpenstackAPI.py


注:本文中的cloudmesh_client.common.ConfigDict.Config.path_expand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。