def templates_get(template_id): nt = None try: nt = api.get_node_template(id=template_id) except Exception, e: abort_and_log(500, "Exception while getting NodeTemplate by id " "'%s'" % template_id, e)
def clusters_get(cluster_id): c = None try: c = api.get_cluster(id=cluster_id) except Exception, e: abort_and_log(500, 'Exception while getting Cluster with id ' '\'%s\'' % cluster_id, e)
def terminate_node_template(**args): template = NodeTemplate.query.filter_by(**args).first() if template: if len(template.nodes): abort_and_log(500, "There are active nodes created using " "template '%s' you trying to terminate" % args) else: DB.session.delete(template) DB.session.commit() return True else: return False
def _node_template(nt): if not nt: abort_and_log(404, 'NodeTemplate not found') d = { 'id': nt.id, 'name': nt.name, 'node_type': { 'name': nt.node_type.name, 'processes': [p.name for p in nt.node_type.processes]}, 'flavor_id': nt.flavor_id } for conf in nt.node_template_configs: c_section = conf.node_process_property.node_process.name c_name = conf.node_process_property.name c_value = conf.value if c_section not in d: d[c_section] = dict() d[c_section][c_name] = c_value return Resource('node_template', d)
def _cluster(cluster): if not cluster: abort_and_log(404, 'Cluster not found') d = { 'id': cluster.id, 'name': cluster.name, 'base_image_id': cluster.base_image_id, 'status': cluster.status, 'service_urls': {}, 'node_templates': {}, 'nodes': [{'vm_id': n.vm_id, 'node_template': { 'id': n.node_template.id, 'name': n.node_template.name }} for n in cluster.nodes] } for ntc in cluster.node_counts: d['node_templates'][ntc.node_template.name] = ntc.count for service in cluster.service_urls: d['service_urls'][service.name] = service.url return Resource('cluster', d)
def clusters_create(): data = request_data() try: return render(api.create_cluster(data).wrapped_dict) except Exception, e: abort_and_log(500, "Exception while adding new Cluster", e)
def clusters_list(): try: return render(clusters=[c.dict for c in api.get_clusters()]) except Exception, e: abort_and_log(500, 'Exception while listing Clusters', e)
def templates_create(): data = request_data() try: return render(api.create_node_template(data).wrapped_dict) except Exception, e: abort_and_log(500, "Exception while adding NodeTemplate", e)
def templates_list(): try: return render( node_templates=[nt.dict for nt in api.get_node_templates()]) except Exception, e: abort_and_log(500, "Exception while listing NodeTemplates", e)
try: return render(api.create_node_template(data).wrapped_dict) except Exception, e: abort_and_log(500, "Exception while adding NodeTemplate", e) @rest.get('/node-templates/<template_id>') def templates_get(template_id): nt = None try: nt = api.get_node_template(id=template_id) except Exception, e: abort_and_log(500, "Exception while getting NodeTemplate by id " "'%s'" % template_id, e) if nt is None: abort_and_log(404, "NodeTemplate with id '%s' not found" % template_id) return render(nt.wrapped_dict) @rest.put('/node-templates/<template_id>') def templates_update(template_id): raise NotImplementedError("Template update op isn't implemented (id '%s')" % template_id) @rest.delete('/node-templates/<template_id>') def templates_delete(template_id): api.terminate_node_template(id=template_id) return render()