Skip to content

Commit 9409a97

Browse files
committed
Merge pull request #30 from schubergphilis/os_preference
rebalance OS now skipping dedicated hosts
2 parents fa05f2e + a19ef3c commit 9409a97

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.pyc
22
*.swp
33
config
4+
*.iml
5+
.idea/

cloudstackops/cloudstackops.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,36 @@ def getHostsFromCluster(self, clusterID):
433433
# Call CloudStack API
434434
return self._callAPI(apicall)
435435

436+
# Find enabled hosts in a given cluster excluding it's hosts which have been marked dedicated
437+
def getSharedHostsFromCluster(self, clusterID):
438+
apicall = listHosts.listHostsCmd()
439+
apicall.clusterid = str(clusterID)
440+
apicall.resourcestate = "Enabled"
441+
apicall.listAll = "true"
442+
443+
# Call CloudStack API
444+
clusterhostdetails = self._callAPI(apicall)
445+
446+
# Remove dedicated hosts from the results
447+
dedicatedhosts = self.getDedicatedHosts()
448+
clusterhostdetails_orig = list(clusterhostdetails)
449+
if dedicatedhosts:
450+
for h in clusterhostdetails_orig:
451+
for d in dedicatedhosts:
452+
if h.name == d.name:
453+
if self.DEBUG == 1:
454+
print "Remove dedicated host from the list: " + str(d.name)
455+
clusterhostdetails.remove(h)
456+
return clusterhostdetails
457+
458+
# Find dedicated hosts
459+
def getDedicatedHosts(self):
460+
apicall = listDedicatedHosts.listDedicatedHostsCmd()
461+
apicall.listAll = "true"
462+
463+
# Call CloudStack API
464+
return self._callAPI(apicall)
465+
436466
# Generic listVirtualMachines function
437467
def listVirtualmachines(self, args):
438468
args = self.remove_empty_values(args)

rebalanceOSTypesOnCluster.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,17 @@ def sortHostByMemory(hosts,reverse=False):
137137
print "ApiKey: " + c.apikey
138138
print "SecretKey: " + c.secretkey
139139

140-
fromClusterHostsData = c.getHostsFromCluster(clusterID)
141-
if fromClusterHostsData == 1 or fromClusterHostsData == None:
140+
# Fetch the list of hosts in a cluster which are not marked dedicated aka shared:
141+
fromClusterHostsData = c.getSharedHostsFromCluster(clusterID)
142+
if fromClusterHostsData == [] or fromClusterHostsData == None:
142143
print
143144
sys.stdout.write("\033[F")
144-
print "No (enabled) hosts found on cluster " + clustername
145+
print "No (enabled or non-dedicated) hosts found on cluster " + clusterName
146+
print "Nothing to work on, exiting."
147+
exit (1)
145148

146149
# Settings
147-
minInstances = 10
150+
minInstances = 7
148151
maxInstances = 25
149152
osFamilies = []
150153
osFamilies.append('Windows')

0 commit comments

Comments
 (0)