in pygenie/client.py [0:0]
def create_cluster(self, cluster):
"""
Create a new cluster. If an "id" is not specified in the configuration
then Genie will automatically assign the cluster an UUID.
Args:
cluster (dict): a cluster configuration
Returns:
str: the newly created cluster id"
Example:
>>> cluster = {'name':'testcluster'}
>>> create_cluster(cluster)
>>> 00355f22-a8f2-4c64-8ff4-be9bba0c7b44
"""
req_var = ('name', 'version', 'user', 'status')
# TODO: genie2 -> 3 compatibility
# Unpack old genie2 Cluster objects into a a dictionary. This adds some
# backwards compatibility with genie2 clients
if cluster.__class__.__name__ == "Cluster":
new_cluster = {}
for key, val in cluster.__dict__.items():
if key in ['updated', 'created']:
val = cluster.updated.strftime("%Y-%m-%dT%H:%M:%S.000Z")
new_cluster[key] = val
cluster = new_cluster
for var in req_var:
if not cluster.get(var):
raise GenieError('Missing required kwarg: %s' % var)
if cluster['status'].upper() not in ['TERMINATED', 'OUT_OF_SERVICE', 'UP']:
raise GenieError('kwarg "status" must be in [TERMINATED, OUT_OF_SERVICE, UP]')
resp = self.call(self.path_cluster, method='POST', data=cluster,
raise_not_status=201)
cluster_id = resp['headers'].get('Location').split('/')[-1]
return cluster_id