Hello Amit, Happy to hear the code snip helped, I am using Python3 and the build in configparser: https://docs.python.org/3/library/configparser.html. If you are using Python2 the syntax is slightly different.
I have a config file that looks like this: --snip-- [DEFAULT] verify_certs = false [influxdb] host = <influx_host> port = 8086 database_name = openstackstackstats username = openstack password = <password> [allocation_ratio] cpu_allocation_ratio = 6.0 ram_allocation_ratio = 2.0 disk_allocation_ratio = 2.0 #https://blueprints.launchpad.net/nova/+spec/add-ratio-to-hypervisor-show # https://review.openstack.org/#/c/350344/1/specs/ocata/implemented/add-ratio-to-hypervisor-show.rst #This values are provided via the API in Ocata --snip-- Then in my code I have the following, the "config" variable below is the configobj that gets passed into the method "def _create_connection(self, cloud_params, configobj):" --snip-- .... import configparser .... def main(): config_paths = [ '/etc/openstackstats.conf', '%s/openstackstats.conf' % (os.path.expanduser("~")), ] options = parse_options() .... log.debug("Default config file search paths:") for cfg in config_paths: log.debug("Will attempt to load: %s" % (cfg)) .... config = configparser.ConfigParser() configs_found = config.read(config_paths) if len(configs_found) < 1: log.critical("No configuration files found") sys.exit(1) for cfg in configs_found: log.debug("Loaded configuration: %s" % (cfg)) cloud_params = _load_openrc(log) stats = StatsManager(cloud_params, config) stats.processstats() --snip-- I hope this helps :) Michael On Sat, Mar 4, 2017 at 9:05 AM, Amit Kumar <ebiib...@gmail.com> wrote: > Thanks Michael for providing the code snippet. It was of great help. I was > doing things as expected but missed to set interface in profile. > > Could you please provide some reference to what configparser object. I am > using code provided by you except setting config parser object and getting > SSL error when setting 'keystone' interface as 'public'. Error is pasted > here: http://paste.openstack.org/show/601428/ > > I am using auth_url as 'https://192.168.255.45:5000/v3'. 192.168.255.45 > is public interface. But when I am setting 'keystone' interface as > 'internal' with internal ip 172.29.236.11, connection is successful. Seems > this SSL error be related to config parser object. > > Regards, > Amit > > > On Sat, Mar 4, 2017 at 2:12 AM, Michael Gale <gale.mich...@gmail.com> > wrote: > >> Hey, >> >> Here is how I am authenticating using openstacksdk: >> >> --snip-- >> from openstack import connection >> from openstack import profile >> from openstack import utils >> >> def _create_connection(self, cloud_params, configobj): >> >> auth_args = { >> 'auth_url' : cloud_params['OS_AUTH_URL'], >> 'username' : cloud_params['OS_USERNAME'], >> 'password' : cloud_params['OS_PASSWORD'], >> 'project_name' : cloud_params['OS_PROJECT_NAME'], >> 'user_domain_name' : cloud_params['OS_USER_DOMAIN_NAME'], >> 'project_domain_name' : cloud_params['OS_USER_DOMAIN_NAME'], >> } >> >> prof = profile.Profile() >> prof.set_region(profile.Profile.ALL, >> cloud_params['OS_REGION_NAME']) >> prof.set_interface('identity', 'public') >> >> log.info("Authenticating against: %s" % >> (cloud_params['OS_AUTH_URL'])) >> log.debug("Authenticating project: %s" % >> (cloud_params['OS_PROJECT_NAME'])) >> >> conn = connection.Connection( >> profile=prof, >> verify=configobj.getboolean('DEFAULT', 'verify_certs'), >> user_agent='openstatstats', >> **auth_args >> ) >> >> log.info("Authentication successful") >> >> return conn >> --snip-- >> >> cloud_params is a dictionary with the OS_* vars loaded from the >> environment vars, configobj is a configparser object. >> >> Michael >> >> >> >> On Fri, Mar 3, 2017 at 4:12 AM, Amit Kumar <ebiib...@gmail.com> wrote: >> >>> Andy, thanks for your response. >>> >>> Address is reachable. I am running Horizon UI on this address >>> successfully. I used "http" whereas it should be "https" but it is not >>> working currently with https as well. >>> >>> Anyways, I tried the script from utility container where openstack >>> command line client is successful in executing the commands but python sdk >>> connection is failing with following error: >>> >>> *"openstack.exceptions.HttpException: HttpException: Expecting to find >>> domain in project - the server could not comply with the request since it >>> is either malformed or otherwise incorrect. The client is assumed to be in >>> error."* >>> >>> On noting the difference in wireshark traces, openstack command line >>> client is adding "domain" related information in request but this domain >>> related information is missing while attempting connection using python SDK. >>> >>> @openstack-sdk, could anyone provide information that how to add domain >>> related information while attempting connection using python sdk. >>> >>> Regards, >>> Amit >>> >>> >>> On Thu, Mar 2, 2017 at 8:54 PM, Andy McCrae <andy.mcc...@gmail.com> >>> wrote: >>> >>>> Hi Amit, >>>> >>>> Sending it again to include the ML! >>>> >>>> On 2 March 2017 at 11:01, Amit Kumar <ebiib...@gmail.com> wrote: >>>> >>>>> Hi All, >>>>> >>>>> I have deployed Openstack using Openstack-Ansible. I am using Newton >>>>> release from tag 14.0.8. My test environment is containing only Compute >>>>> Node and Controller Node (Infra Node). >>>>> When using Openstack Python SDK, I am getting following error while >>>>> making connection to external_vib_lp_address (192.168.255.45) binded to >>>>> port 5000. >>>>> >>>>> *openstack.exceptions.SDKException: Connection failure that may be >>>>> retried.* >>>>> >>>> >>>> Based on the error this is a connection issue - have you tested >>>> manually connecting to the external address you listed on that port? >>>> A good place to start would be to start looking at why it can't connect >>>> and seeing if you can manually connect outside of using the SDK. >>>> >>>> Are you trying to connect from a separate host to the OpenStack >>>> environment? If so can you even access 192.168.255.45? >>>> >>>> If you're still having issues feel free to jump into #openstack-ansible >>>> on Freenode and hopefully you'll be able to get more help there! >>>> >>>> Andy >>>> >>> >>> >>> _______________________________________________ >>> Mailing list: http://lists.openstack.org/cgi >>> -bin/mailman/listinfo/openstack >>> Post to : openstack@lists.openstack.org >>> Unsubscribe : http://lists.openstack.org/cgi >>> -bin/mailman/listinfo/openstack >>> >>> >> >> >> -- >> >> “The Man who says he can, and the man who says he can not.. Are both >> correct” >> > > -- “The Man who says he can, and the man who says he can not.. Are both correct”
_______________________________________________ Mailing list: http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack Post to : openstack@lists.openstack.org Unsubscribe : http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack