python openstackclient_python openstack client api example (kilo)

籍光熙
2023-12-01

2015年12月15日 发布

import keystoneclient.v2_0.client as ksclient

import novaclient.v2.client as noclient

import glanceclient.v2.client as glclient

import neutronclient.v2_0.client as neclient

k_auth_url = "http://controller:35357/v2.0"

k_username = "admin"

k_password = "xxxxxxxx"

k_tenant_name = "admin"

k_user_id = "ee2666f18d3b4934abfa11b14b099b3b"

keystone = ksclient.Client(auth_url=k_auth_url, username=k_username,

password=k_password, tenant_name=k_tenant_name)

k_token = keystone.auth_token

print k_token

print keystone.services.list()

print keystone.users.list()

print keystone.tenants.list()

print keystone.endpoints.list()

print keystone.roles.list()

print "Nova API Test "

n_auth_url = "http://controller:8774/v2"

n_username = "admin"

n_password = "xxxxxxxxxx"

n_tenant_name = "admin"

nova = noclient.Client(auth_url=n_auth_url, username=n_username, api_key=n_password, tenant_name=n_tenant_name)

print "Glance API Test"

g_auth_url = "http://controller:9292/v2.0"

g_token = "221da36c42a798da38d9"

glance_endpoint = keystone.service_catalog.url_for(service_type='image', endpoint_type='publicURL')

print glance_endpoint

glance = glclient.Client(glance_endpoint, token=k_token)

images = glance.images.list()

print images.next()

print "Neutron API Test"

neutron_endpoint = keystone.service_catalog.url_for(service_type='network',endpoint_type='publicURL')

print neutron_endpoint

print k_token

neutron = neclient.Client(endpoint_url=neutron_endpoint, token=k_token)

neutron.format = 'json'

nets = neutron.list_networks()

print nets

相关阅读

相关文章

相关问答