def _add_node_thread(self, nid, ip, port): self._logger.debug('invoked') node = utils.get_conctrller_object(utils.uri_generator(ip, port)) try: with self._nccall_sem: rs = node.do_describe_resource() if rs['code'] != 0x0: self._logger.warn(rs.data['msg']) return res_data = rs['data'] res_data.update({'uri': utils.uri_generator(ip, port), 'id': nid}) res = ClusterResource(rs['data']) except Exception, err: self._logger.warn(err) res = ClusterResource() res.uri = utils.uri_generator(ip, port) res.id = nid res.node_status = 'error'
def view_start_instance(request): if request.method != "POST": return INSTANCE_INDEX(request) args_dict = request.POST name = args_dict.get('name', None) if name == None: return INSTANCE_INDEX(request) try: inst = Instance.objects.get(instance_id=name) except: return INSTANCE_INDEX(request) current_user = auth.get_user(request) if not inst.user.username == current_user.username: return INSTANCE_INDEX(request) # send start instance message to cc cc_name = _schedule_instance(inst) if cc_name == None: return INSTANCE_INDEX(request) cc = Cluster.objects.get(name=cc_name) cc_server = utils.get_conctrller_object(utils.uri_generator(cc.socket.ip, cc.socket.port)) rs = cc_server.do_run_instances([inst.instance_id], None, inst.user_id, {'cores': inst.params.cores, 'mem': inst.params.mem, 'disk': inst.params.disk}, inst.image.image_id, inst.image.local_dev_real, None, None, None, None, [inst.net.mac], None) if rs['code'] != 0: return INSTANCE_INDEX(request) return HttpResponseRedirect("/clc/instance")
def _cluster_server(self, cluster): return utils.get_conctrller_object(utils.uri_generator(cluster.socket.ip, cluster.socket.port))
try: inst = Instance.objects.get(instance_id=inst_id) except Exception, ex: return INSTANCE_INDEX(request) cc_server = None for cluster in Cluster.objects.all(): if cc_server: break for node in cluster.nodes.all(): if cc_server: break for inst_t in node.instances.all(): if inst_t.instance_id == inst.instance_id: cc_server = utils.get_conctrller_object(utils.uri_generator(cluster.socket.ip, cluster.socket.port)) break if cc_server is None: return INSTANCE_INDEX(request) try: rs = cc_server.do_terminate_instances([inst.instance_id]) if rs['code'] != 0x0: return INSTANCE_INDEX(request) except Exception, ex: print ex return INSTANCE_INDEX(request) return HttpResponseRedirect("/clc/instance")