openstack api獲取例項列表
openstack Rocky版本 api獲取例項
方法一:
import sys
from openstack import connection
from openstack import utils
conn = connection.Connection(
auth_url='http://192.168.10.10/identity',
username='admin',
project_name='demo',
project_domain_name='Default',
user_domain_name='Default',
password='admin')
for server in conn.compute.servers():
print(server)
for flavor in conn.compute.flavors():
print(flavor)
data=conn.compute.servers.get(vm)
方法二:
from novaclient import client as nvclient
from keystoneauth1 import loading
from keystoneauth1 import session
loader = loading.get_plugin_loader('password')
auth = loader.load_from_options(auth_url='http://192.168.10.10/identity',
username='admin',
password='admin',
project_name='demo',
project_domain_name='Default',
user_domain_name='Default')
sess = session.Session(auth=auth)
nova = nvclient.Client(2.1, session=sess)
vm=nova.servers.get(vmid)