Last active
February 14, 2017 16:38
-
-
Save prehensilecode/8438983 to your computer and use it in GitHub Desktop.
Change node categories in Bright Cluster Manager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| ### Change all node categories | |
| from sys import exit | |
| import os | |
| # import Bright Cluster Manager bindings | |
| import pythoncm | |
| # Create an instance of ClusterManager, only one is needed | |
| clustermanager = pythoncm.ClusterManager() | |
| # Add connection to your cluster using cmsh certificate | |
| if os.path.isfile('/root/.cm/admin.pem'): | |
| cluster = clustermanager.addCluster('https://localhost:8081', '/root/.cm/admin.pem', '/root/.cm/admin.key') | |
| elif os.path.isfile('/root/.cm/cmsh/admin.pem'): | |
| cluster = clustermanager.addCluster('https://localhost:8081', '/root/.cm/cmsh/admin.pem', '/root/.cm/cmsh/admin.key') | |
| else: | |
| print "No certificate found" | |
| exit(1) | |
| if not cluster.connect(): | |
| print "Unable to connect" | |
| print cluster.getLastError() | |
| exit(1) | |
| nodes = cluster.getAll('node') | |
| categories = cluster.getAll('category') | |
| intelcat = None | |
| for category in categories: | |
| if category.name == 'compute-rhel65-intel': | |
| intelcat = category | |
| print 'Found category "%s"' % (intelcat.name) | |
| print '------' | |
| for node in nodes: | |
| if node.childType == 'PhysicalNode' and node.category.name == 'compute-rhel65': | |
| print 'Changing %s category from %s to %s ...' % (node.hostname, node.category.name, intelcat.name) | |
| node.category = intelcat | |
| c = node.commit() | |
| if not c.result: | |
| print 'Commit of %s failed:' % node.resolveName() | |
| for j in range(c.count): | |
| print c.getValidation(j).msg | |
| else: | |
| print 'Committed %s category to %s' % (node.resolveName(), node.category.name) | |
| cluster.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment