1
0
mirror of https://github.com/vmware/vsphere-automation-sdk-python.git synced 2024-11-23 01:49:59 -05:00

remove sample.cfg

This commit is contained in:
Tianhao He 2017-01-23 15:27:54 -08:00
parent 1002915230
commit a3ff53b114
4 changed files with 10 additions and 97 deletions

View File

@ -17,7 +17,6 @@ __copyright__ = 'Copyright 2013, 2016 VMware, Inc. All rights reserved.'
import argparse
import traceback
from samples.vsphere.common.service_manager_factory import ServiceManagerFactory
from samples.vsphere.common.sample_config import SampleConfig
class SampleBase(object):
@ -48,22 +47,13 @@ class SampleBase(object):
attr() # calling the method
self.args = self.argparser.parse_args() # parse all the sample arguments when they are all set
if self.args.server is None:
self.server = SampleConfig.get_server_url() # look for server IP in the sample config
else:
self.server = self.args.server
assert self.server is not None
print('server: {0}'.format(self.server))
if self.args.username is None:
self.username = SampleConfig.get_username() # look for username in the sample config
else:
self.username = self.args.username
assert self.username is not None
if self.args.password is None:
self.password = SampleConfig.get_password() # look for password in the sample config
else:
self.password = self.args.password
assert self.password is not None

View File

@ -1,55 +0,0 @@
"""
* *******************************************************
* Copyright (c) VMware, Inc. 2013, 2016. All Rights Reserved.
* *******************************************************
*
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
"""
__author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2013, 2016 VMware, Inc. All rights reserved.'
from os import path
try:
import configparser
except ImportError:
import ConfigParser as configparser
class SampleConfig(object):
config = configparser.RawConfigParser()
config.read(path.join(path.dirname(path.realpath(__file__)), '../../../sample.cfg'))
@classmethod
def get_sample_config(cls):
return cls.config
@classmethod
def get_server_url(cls):
config = SampleConfig.get_sample_config()
return config.get('connection', 'server')
@classmethod
def get_username(cls):
config = SampleConfig.get_sample_config()
return config.get('connection', 'username')
@classmethod
def get_password(cls):
config = SampleConfig.get_sample_config()
return config.get('connection', 'password')
def main():
print('serverurl: {0}'.format(SampleConfig.get_server_url()))
print('username: {0}'.format(SampleConfig.get_username()))
print('password: {0}'.format(SampleConfig.get_password()))
# Start program
# just for testing
if __name__ == "__main__":
main()

View File

@ -14,7 +14,6 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2014 VMware, Inc. All rights reserved.'
import argparse
from samples.vsphere.common.sample_config import SampleConfig
from samples.vsphere.common.lookup_service_helper import LookupServiceHelper
@ -38,16 +37,10 @@ class PrintServices(object):
self.args = self.argparser.parse_args() # parse all the sample arguments when they are all set
def setup(self):
if self.args.lswsdlurl is None:
self.lswsdlurl = SampleConfig.get_ls_wsdl_url() # look for lookup service WSDL in the sample config
else:
self.lswsdlurl = self.args.lswsdlurl
assert self.lswsdlurl is not None
print('lswsdlurl: {0}'.format(self.lswsdlurl))
if self.args.lssoapurl is None:
self.lssoapurl = SampleConfig.get_ls_soap_url() # look for lookup service SOAP URL in the sample config
else:
self.lssoapurl = self.args.lssoapurl
assert self.lssoapurl is not None
print('lssoapurl: {0}'.format(self.lssoapurl))

View File

@ -24,7 +24,6 @@ from vmware.vapi.security.session import create_session_security_context
from vmware.vapi.stdlib.client.factories import StubConfigurationFactory
from com.vmware.cis.tagging_client import Tag
from samples.vsphere.common.lookup_service_helper import LookupServiceHelper
from samples.vsphere.common.sample_config import SampleConfig
class VapiConnectionWorkflow(object):
@ -68,35 +67,21 @@ class VapiConnectionWorkflow(object):
self.args = self.argparser.parse_args() # parse all the sample arguments when they are all set
def setup(self):
if self.args.lswsdlurl is None:
self.lswsdlurl = SampleConfig.get_ls_wsdl_url() # look for lookup service WSDL in the sample config
else:
self.lswsdlurl = self.args.lswsdlurl
assert self.lswsdlurl is not None
print('lswsdlurl: {0}'.format(self.lswsdlurl))
if self.args.lssoapurl is None:
self.lssoapurl = SampleConfig.get_ls_soap_url() # look for lookup service SOAP URL in the sample config
else:
self.lssoapurl = self.args.lssoapurl
assert self.lssoapurl is not None
print('lssoapurl: {0}'.format(self.lssoapurl))
if self.args.username is None:
self.username = SampleConfig.get_username() # look for sso user name in the sample config
else:
self.username = self.args.username
assert self.username is not None
if self.args.password is None:
self.password = SampleConfig.get_password() # look for sso password in the sample config
else:
self.password = self.args.password
assert self.password is not None
if self.mgmtinstancename is None:
self.mgmtinstancename = self.args.mgmtinstancename
self.skip_verification = self.args.skipverification
def execute(self):