【问题标题】:Python VCenter API connection stringPython vCenter API 连接字符串
【发布时间】:2013-07-26 22:16:09
【问题描述】:

我正在编写一个 python 脚本来使用 PySphere 库自动删除 svmi netapp 快照。

创建一个连接实例:

vc_server = pysphere.VIServer()
vc_server.connect("vc.example.com", "example.com\dd432", "password")

一切都按预期的方式工作,我唯一的问题是我有办法在脚本中隐藏密码,也许是某种散列机制,让密码参数不在脚本中以明文形式指定密码?

谢谢。

【问题讨论】:

    标签: python passwords parameter-passing vmware esxi


    【解决方案1】:

    目前我找到了将文件系统下的密码放入 .cf 文件并限制对该文件的读取权限的唯一方法。当然应该有更好的方法。

        @classmethod
    
        def setUpClass(cls):
        config_path = os.path.join(os.path.dirname(__file__), "config_conn.cf")
        cls.config = ConfigParser.ConfigParser()
        cls.config.read(config_path)
    
        host = cls.config.get("READ_ONLY_ENV", "host")
        user = cls.config.get("READ_ONLY_ENV", "user")
        pswd = cls.config.get("READ_ONLY_ENV", "password")
    
        cls.server = VIServer()
        cls.server.connect(host, user, pswd)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-11
      • 2016-11-20
      • 2019-06-10
      • 2016-03-14
      • 2013-03-20
      • 1970-01-01
      • 2017-12-18
      • 2011-05-09
      相关资源
      最近更新 更多