-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcloud_status
More file actions
executable file
·104 lines (89 loc) · 4.28 KB
/
Copy pathcloud_status
File metadata and controls
executable file
·104 lines (89 loc) · 4.28 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
# vim: set expandtab ts=4 sw=4:
# Copyright (C) 2009 University of Victoria
# You may distribute under the terms of either the GNU General Public
# License or the Apache v2 License, as specified in the README file.
# cloud_status - tool to display information about cloud scheduler
#
import xmlrpclib
import sys
import socket
from optparse import OptionParser
import logging
import cloudscheduler.utilities as utilities
# We need to set up logging with a Null Handler before we
# import our modules, since they use it.
log = logging.getLogger("cloudscheduler")
null_handler = utilities.NullHandler()
log.addHandler(null_handler)
import cloudscheduler.cloud_management as cloud_management
import cloudscheduler.config as config
def main(argv=None):
# Parse command line options
parser = OptionParser()
parser.add_option("-f", "--config-file", dest="config_file", metavar="FILE",
help="Designate a Cloud Sceduler config file")
parser.add_option("-p", "--port", dest="port", metavar="FILE",
help="Pick a custom port to connect to Cloud Scheduler"
"information server")
parser.add_option("-a", "--all-cluster", action="store_true",
dest="all_cluster", default=False,
help="Get All clusters in Cloud Scheduler")
parser.add_option("-c", "--cluster", dest="cluster_name", metavar="NAME",
help="Get Information on a cluster")
parser.add_option("-m", "--virtual-machines",action="store_true",
dest="vms", default=False,
help="Get all VMs in Cloud Scheduler")
parser.add_option("-n", "--vm-info", dest="vm_id", metavar="ID",
help="Get information on a virtual machine")
parser.add_option("-j", "--json", dest="json", action="store_true",
default=False, help="Get JSON output")
parser.add_option("-d", "--developer-information", action="store_true",
dest="dev_info", default=False,
help="Show developer information about cloud_scheduler")
(cli_options, args) = parser.parse_args()
# Initialize config
if cli_options.config_file:
config.setup(cli_options.config_file)
else:
config.setup()
# Get port to connect to info server.
# Precedence: -p argument, then from config module
if cli_options.port:
server_port = cli_options.port
else:
server_port = config.info_server_port
server_hostname = "localhost"
# Connect to info server
try:
s = xmlrpclib.ServerProxy("http://%s:%s" %
(server_hostname, server_port))
if cli_options.all_cluster and not cli_options.json:
print s.get_cluster_resources()
elif cli_options.vms:
print s.get_cluster_vm_resources()
elif not cli_options.json and cli_options.vm_id and cli_options.cluster_name:
print s.get_vm_info(cli_options.cluster_name, cli_options.vm_id)
elif cli_options.vm_id and not cli_options.cluster_name:
print "Please provide -c cluster_name with vm ID"
elif not cli_options.json and cli_options.cluster_name and not cli_options.vm_id:
print s.get_cluster_info(cli_options.cluster_name)
elif cli_options.json and cli_options.all_cluster:
print s.get_json_resource()
elif cli_options.json and cli_options.vm_id and cli_options.cluster_name:
print s.get_json_vm(cli_options.cluster_name, cli_options.vm_id)
elif cli_options.json and cli_options.cluster_name and not cli_options.vm_id:
print s.get_json_cluster(cli_options.cluster_name)
elif (cli_options.dev_info):
print s.get_developer_information()
else:
print s.get_cloud_resources()
except socket.error:
print "%s: couldn't connect to cloud scheduler at %s on port %s."\
% (sys.argv[0], server_hostname, server_port)
print "Is the cloud scheduler running on port %s?" % server_port
except:
print "Unexpected error: ", sys.exc_info()[0], sys.exc_info()[1]
print "Is the cloud scheduler running on port %s?" % server_port
if __name__ == "__main__":
sys.exit(main())