-
Notifications
You must be signed in to change notification settings - Fork 5
/
nova_example.py
53 lines (42 loc) · 1.4 KB
/
nova_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python
import os
import sys
import argparse
from novaclient.v1_1 import client as novaclient
# Import code common to all of the examples.
import common
import keystone_example
def get_nova_client(keystone_client):
# We pass username, password, and project_id as None
# because we want to use our existing Keystone token rather
# than having Nova acquire a new one.
return novaclient.Client(
None,
None,
None,
auth_url=keystone_client.auth_url,
tenant_id=keystone_client.tenant_id,
auth_token=keystone_client.auth_token)
def parse_args():
p = common.create_parser()
p.add_argument('--all-tenants',
action='store_true')
return p.parse_args()
def main():
args = parse_args()
kc = keystone_example.get_keystone_client(
os_username=args.os_username,
os_password=args.os_password,
os_tenant_name=args.os_tenant_name,
os_tenant_id=args.os_tenant_id,
os_auth_url=args.os_auth_url
)
nc = get_nova_client(kc)
# Print a list of running servers.
for server in nc.servers.list(search_opts={'all_tenants':
args.all_tenants}):
print server.id, server.name
for network_name, network in server.networks.items():
print ' ', network_name, ', '.join(network)
if __name__ == '__main__':
main()