From a3ff53b11423bccfe98e47f76eb7a2f447180826 Mon Sep 17 00:00:00 2001 From: Tianhao He Date: Mon, 23 Jan 2017 15:27:54 -0800 Subject: [PATCH] remove sample.cfg --- samples/vsphere/common/sample_base.py | 16 +----- samples/vsphere/common/sample_config.py | 55 ------------------- .../vsphere/lookupservice/print_services.py | 11 +--- .../workflow/vapi_connection_workflow.py | 25 ++------- 4 files changed, 10 insertions(+), 97 deletions(-) delete mode 100644 samples/vsphere/common/sample_config.py diff --git a/samples/vsphere/common/sample_base.py b/samples/vsphere/common/sample_base.py index 9d42a625..4a4dcc2c 100644 --- a/samples/vsphere/common/sample_base.py +++ b/samples/vsphere/common/sample_base.py @@ -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,23 +47,14 @@ 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 + 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 + 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 + self.password = self.args.password assert self.password is not None self.cleardata = self.args.cleardata diff --git a/samples/vsphere/common/sample_config.py b/samples/vsphere/common/sample_config.py deleted file mode 100644 index cf78895c..00000000 --- a/samples/vsphere/common/sample_config.py +++ /dev/null @@ -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() diff --git a/samples/vsphere/lookupservice/print_services.py b/samples/vsphere/lookupservice/print_services.py index ddb1d9dd..17aac42b 100644 --- a/samples/vsphere/lookupservice/print_services.py +++ b/samples/vsphere/lookupservice/print_services.py @@ -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,17 +37,11 @@ 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 + 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 + self.lssoapurl = self.args.lssoapurl assert self.lssoapurl is not None print('lssoapurl: {0}'.format(self.lssoapurl)) diff --git a/samples/vsphere/workflow/vapi_connection_workflow.py b/samples/vsphere/workflow/vapi_connection_workflow.py index b4250e0d..7640c853 100644 --- a/samples/vsphere/workflow/vapi_connection_workflow.py +++ b/samples/vsphere/workflow/vapi_connection_workflow.py @@ -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 + 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 + 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 + 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 + self.password = self.args.password assert self.password is not None - if self.mgmtinstancename is None: - self.mgmtinstancename = self.args.mgmtinstancename - + self.mgmtinstancename = self.args.mgmtinstancename self.skip_verification = self.args.skipverification def execute(self):