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


Python Options.update方法代码示例

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


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

示例1: PyvisdkApp

# 需要导入模块: from options import Options [as 别名]
# 或者: from options.Options import update [as 别名]
class PyvisdkApp(object):
    '''
    Base class implementation of a command line application.  See the :py:mod:`~pyvisdk.app` module for documentation on the format of the options file.
    '''


    def __init__(self, usage=None):
        '''
        Constructor
        '''
        self.options = Options()
        if not usage:
            usage = "usage: %prog [options]"
        self.parser = OptionParser(usage=usage)
        self.parser.add_option("-c", "--config", dest="VI_CONFIG", help="Specify non-default name or location for the VI Perl Toolkit configuration file. Default name and location for Linux is ~/.visdkrc and for Windows is %HOME%\visdk.rc.")
        self.parser.add_option("-p", "--password", dest="VI_PASSWORD", help="Password for the specified username. Sucessful authentication with username and password returns a session object that can be saved and used for subsequent connections using the same or different script. See sessionfile.")
        self.parser.add_option("--portnumber", dest="VI_PORTNUMBER", help="Port used for server connection.")
        self.parser.add_option("--protocol", dest="VI_PROTOCOL", help="Protocol used to connect to server. Default is HTTPS. If the server has been configured for HTTP, set to HTTP. ")
        self.parser.add_option("-s", "--server", dest="VI_SERVER", help="ESX Server or VirtualCenter Management Server host to which you want the application or script to connect. Default is localhost if none specified.")
        self.parser.add_option("--servicepath", dest="VI_SERVICEPATH", help="Service path for server connection. Default is /sdk/webService.")
        self.parser.add_option("--sessionfile", dest="VI_SESSIONFILE", help="Name of file containing the token saved from successful login. Alternative to specifying username and password. Sessions time out after 30 minutes of inactivity.")
        self.parser.add_option("--url", dest="VI_URL", help="Complete URL for SDK connection. An alternative to specifying protocol, server, and servicepath as individual connection parameters. For example, python app_name.py --url https://myserver.mycompany.com/sdk --username root --password mypassword")
        self.parser.add_option("-u", "--username", dest="VI_USERNAME", help="User account that has privileges to connect to the server.")
        self.parser.add_option("-v", "--verbose", dest="VI_VERBOSE", help="Increase loglevel. Use in conjunction with Util::trace subroutine to display additional debugging information. By default, value of --verbose (loglevel) is 0. ")
        self.parser.add_option("-V", "--version", help="Displays script version information, if available.")
        
    def parse(self):
        (cmd_opts, _) = self.parser.parse_args(sys.argv[1:]) # IGNORE W0201
        
        # load up options from the visdkrc file if there is any
        if cmd_opts.VI_CONFIG:
            self.options.load(cmd_opts.VI_CONFIG)
        else:
            self.options.load()
            
        # also, update options with environmental values, overriding those in the configuration file.
        self.options.load_env()
            
        # update our options with what was entered on the command line.  This will override previously
        # entered options
        for name, value in cmd_opts.__dict__.items():
            if value:
                self.options.update({name:value})
        
        # need to have server, username, and password or fail
        if not (self.options.VI_USERNAME and self.options.VI_PASSWORD and self.options.VI_SERVER):
            raise RuntimeError("Must specify --username, --password and --server")


    def connect(self):
        self.vim = Vim(self.options.VI_SERVER)
        self.vim.login(self.options.VI_USERNAME, self.options.VI_PASSWORD)
    
    def disconnect(self):
        self.vim.logout()
开发者ID:Infinidat,项目名称:pyvisdk,代码行数:57,代码来源:app.py


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