def __init__(self): config.init(sys.argv[1:]) try: self.keystone = ksclient.Client(auth_url=cfg.CONF.OS.auth_url, tenant_name=cfg.CONF.OS.tenant_name, username=cfg.CONF.OS.username, password=cfg.CONF.OS.password) self.token = self.keystone.auth_token neutron_endpoint_url = self.keystone.service_catalog.url_for( service_type='network') self.neutron = neutronclient.Client(endpoint_url=neutron_endpoint_url, token=self.token) except AuthorizationFailure: warn("OpenStack Authorization Failed\n") self.neutron = None except Unauthorized: warn("No valid OpenStack authentication information is found\n") self.neutron = None
def __init__(self): config.init(sys.argv[1:]) try: self.keystone = ksclient.Client( auth_url=cfg.CONF.OS.auth_url, tenant_name=cfg.CONF.OS.tenant_name, username=cfg.CONF.OS.username, password=cfg.CONF.OS.password) self.token = self.keystone.auth_token neutron_endpoint_url = self.keystone.service_catalog.url_for( service_type='network') self.neutron = neutronclient.Client( endpoint_url=neutron_endpoint_url, token=self.token) except AuthorizationFailure: warn("OpenStack Authorization Failed\n") self.neutron = None except Unauthorized: warn("No valid OpenStack authentication information is found\n") self.neutron = None
def __init__(self): config.init(sys.argv[1:]) username = os.getenv('OS_USERNAME') or cfg.CONF.OS.username or None password = os.getenv('OS_PASSWORD') or cfg.CONF.OS.password or None tenant_name = \ os.getenv('OS_TENANT_NAME') or cfg.CONF.OS.tenant_name or None auth_url = os.getenv('OS_AUTH_URL') or cfg.CONF.OS.auth_url or None try: self.keystone = ksclient.Client(auth_url=auth_url, tenant_name=tenant_name, username=username, password=password) self.token = self.keystone.auth_token neutron_endpoint_url = self.keystone.service_catalog.url_for( service_type='network') self.neutron = neutronclient.Client( endpoint_url=neutron_endpoint_url, token=self.token) except AuthorizationFailure: warn("OpenStack auth not loaded\n") self.neutron = None except Unauthorized: warn("No valid OpenStack auth info is found\n") self.neutron = None
#!/usr/bin/env python # -*- coding:utf-8 -*- # Test the openstack python sdk, based on restful APIs. # ref: http://docs.openstack.org/user-guide/content/sdk_auth.html __author__ = 'baohua' from easyovs import config from oslo.config import cfg import keystoneclient.v2_0.client as ksclient import neutronclient.v2_0.client as neutronclient import novaclient.v1_1.client as nvclient import sys if __name__ == '__main__': config.init(sys.argv[1:]) keystone = ksclient.Client(auth_url=cfg.CONF.OS.auth_url, tenant_name=cfg.CONF.OS.tenant_name, username=cfg.CONF.OS.username, password=cfg.CONF.OS.password) token = keystone.auth_token #nova_endpoint_url = keystone.service_catalog.url_for( # service_type='compute') nova = nvclient.Client(auth_token=token) neutron_endpoint_url = keystone.service_catalog.url_for( service_type='network') neutron = neutronclient.Client(endpoint_url=neutron_endpoint_url, token=token)