forked from iranzo/rhevm-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathovirt-policy.py
executable file
·68 lines (53 loc) · 2.05 KB
/
ovirt-policy.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
68
#!/usr/bin/env python
#
# Author: Pablo Iranzo Gomez ([email protected])
#
# Description: Script for switching clusters policy to specified one, actually power_saving or evenly_distributed
#
# Requires rhevm-sdk to work
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
from ovirt_functions import *
description = """
RHEV-policy is a script for managing via API cluster policy
Actual policy is:
- power_saving
- evenly_distributed
"""
#Parse args in ovirt_functions: parseoptions(basename, description, args)
options = parseoptions(sys.argv[0], description, sys.argv[1:])
options.username, options.password = getuserpass(options)
baseurl = "https://%s:%s" % (options.server, options.port)
api = apilogin(url=baseurl, username=options.username, password=options.password)
# FUNCTIONS
def process_cluster(clusid):
"""Processes cluster
@param clusid: Cluster ID to process
"""
if options.verbosity > 1:
print("\nProcessing cluster with id %s and name %s" % (clusid, api.clusters.get(id=clusid).name))
print("#############################################################################")
cluster = api.clusters.get(id=clusid)
cluster.scheduling_policy.policy = options.policy
try:
cluster.update()
except:
if options.verbosity > 2:
print("Problem updating policy")
# evenly_distributed
# power_saving
# MAIN PROGRAM
if __name__ == "__main__":
if not options.cluster:
# Processing each cluster of our RHEVM
for cluster in api.clusters.list():
process_cluster(cluster.id)
else:
process_cluster(api.clusters.get(name=options.cluster).id)