forked from larsks/kaizen-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openstack.py
67 lines (43 loc) · 1.44 KB
/
openstack.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
import json
import subprocess
from functools import cache
def openstack(*args):
"""Run `openstack` CLI.
Append `-f json` to whatever arguments we receive from the caller, and
parse the returned JSON before returning a result."""
cmd = ["openstack"]
cmd.extend(args)
cmd.extend(["-f", "json"])
return json.loads(subprocess.check_output(cmd))
def list_projects():
"""Return a list of projects"""
return openstack("project", "list")
@cache
def get_project(uuid):
"""Return details about a single project"""
return openstack("project", "show", uuid)
@cache
def get_flavor(uuid):
"""Return details about a single flavor"""
return openstack("flavor", "show", uuid)
def list_servers():
"""Return a list of nova servers (aka "instances")"""
return openstack("server", "list", "--all")
@cache
def get_server(uuid):
"""Return details about a single server"""
return openstack("server", "show", uuid)
def list_volumes():
"""Return a list of cinder volumes"""
return openstack("volume", "list", "--all")
@cache
def get_volume(uuid):
"""Return details about a single volume"""
return openstack("volume", "show", uuid)
def list_floating_ips():
"""Return a list of floating ips"""
return openstack("floating", "ip", "list")
def get_floating_ip(uuid):
"""Return information about a single floating ip"""
return openstack("floating", "ip", "show", uuid)