def node_bootfiles(arg_dict): result = {} # Check POST data if "nodes" not in arg_dict or "user" not in arg_dict: return json.dumps({ "parameters": "nodes: ['name1', 'name2' ], user: '******'" }) wanted = arg_dict["nodes"] user = arg_dict["user"] if len(user) == 0 or '@' not in user: for n in wanted: result[n] = "no_email" return json.dumps(result) # Get information about the requested nodes db = open_session() nodes = db.query(Schedule ).filter(Schedule.node_name.in_(wanted) ).filter(Schedule.owner == user ).all() for n in nodes: if n.state == "ready": # The deployment is completed, add a new action node_action = new_action(n, db) init_action_process(node_action, "bootfiles") db.add(node_action) result[n.node_name] = "success" else: logging.error("[%s] can not upload the boot files because the state is not 'ready' (state: %s)" % ( n.node_name, n.state)) result[n.node_name] = "failure: %s is not ready" % n.node_name close_session(db) # Build the result for n in wanted: if n not in result: result[n] = "failure" return json.dumps(result)
def register_environment(arg_dict): db = open_session() node = db.query(Schedule ).filter(Schedule.node_name == arg_dict["node_name"] ).filter(Schedule.owner == arg_dict["user"] ).first() if node is None: close_session(db) msg = "No reservation for the node '%s'" % arg_dict["node_name"] logging.error("[%s] %s" % (arg_dict["node_name"], msg)) return json.dumps({ "error": msg }) # Check the image file does not exist yet file_name = os.path.basename(arg_dict["img_path"]) env_path = get_config()["env_path"] if os.path.exists("%s%s" % (env_path, file_name)): msg = "The image file '%s' already exists in the server. Please, rename this file." % file_name logging.error("[%s] %s" % (arg_dict["node_name"], msg)) return json.dumps({ "error": msg }) node_action = db.query(Action).filter(Action.node_name == node.node_name).first() if node_action is not None: db.delete(node_action) # The deployment is completed, add a new action node_action = new_action(node, db) # The deployment is completed, add a new action init_action_process(node_action, "reg_env") db.add(node_action) # Delete old values old_props = db.query(ActionProperty ).filter(ActionProperty.node_name == node.node_name ).filter(ActionProperty.prop_name.in_(["img_path", "env_name" ]) ).all() for p in old_props: db.delete(p) act_prop = ActionProperty() act_prop.node_name = node.node_name act_prop.prop_name = "img_path" act_prop.prop_value = arg_dict["img_path"] act_prop.owner = node.owner db.add(act_prop) act_prop = ActionProperty() act_prop.node_name = node.node_name act_prop.prop_name = "env_name" act_prop.prop_value = arg_dict["env_name"] act_prop.owner = node.owner db.add(act_prop) close_session(db) return json.dumps({ "success": "environment is registering" })
def node_deployagain(arg_dict): result = {} # Check POST data if "nodes" not in arg_dict or "user" not in arg_dict: return json.dumps({ "parameters": { "user": "******", "nodes": ["name1", "name2"] } }) wanted = arg_dict["nodes"] user = arg_dict["user"] if len(user) == 0 or '@' not in user: for n in wanted: result[n] = "no_email" return json.dumps(result) # Get information about the requested nodes db = open_session() nodes = db.query(Schedule).filter( Schedule.node_name.in_(wanted)).filter(Schedule.owner == user).all() for n in nodes: if n.state == "ready": node_action = db.query(Action).filter( Action.node_name == n.node_name).first() if node_action is not None: db.delete(node_action) # The deployment is completed, add a new action node_action = new_action(n, db) # The deployment is completed, add a new action init_action_process(node_action, "deploy") db.add(node_action) result[n.node_name] = "success" else: result[n.node_name] = "failure: %s is not ready" % n.node_name close_session(db) # Build the result for n in wanted: if n not in result: result[n] = "failure" return json.dumps(result)
def node_destroy(arg_dict): # Check POST data if "nodes" not in arg_dict or "user" not in arg_dict: return json.dumps({ "parameters": "nodes: ['name1', 'name2' ], user: '******'" }) wanted = arg_dict["nodes"] user = arg_dict["user"] if len(user) == 0 or '@' not in user: for n in wanted: result[n] = "no_email" return json.dumps(result) logging.info("Destroying the nodes: %s" % wanted) result = {} db = open_session() # Delete actions in progress for the nodes to destroy actions = db.query(Action).filter(Action.node_name.in_(wanted)).all() for action in actions: db.delete(action) # Get the reservations to destroy nodes = db.query(Schedule ).filter(Schedule.node_name.in_(wanted) ).filter(Schedule.owner == user ).all() for n in nodes: if n.state == "configuring": # The node is not deployed, delete the reservation and the associated properties free_reserved_node(db, n.node_name) result[n.node_name] = "success" else: # Create a new action to start the destroy action node_action = new_action(n, db) init_action_process(node_action, "destroy") db.add(node_action) result[n.node_name] = "success" close_session(db) # Build the result for n in wanted: if n not in result: result[n] = "failure" return json.dumps(result)
def node_destroy(arg_dict): # Check POST data if "nodes" not in arg_dict or "user" not in arg_dict: return json.dumps({ "parameters": { "user": "******", "nodes": ["name1", "name2"] } }) wanted = arg_dict["nodes"] user = arg_dict["user"] if len(user) == 0 or '@' not in user: for n in wanted: result[n] = "no_email" return json.dumps(result) logging.info("Destroying the nodes: %s" % wanted) result = {} db = open_session() # Delete actions in progress for the nodes to destroy actions = db.query(Action).filter(Action.node_name.in_(wanted)).all() for action in actions: db.delete(action) # Get the reservations to destroy nodes = db.query(Schedule).filter( Schedule.node_name.in_(wanted)).filter(Schedule.owner == user).all() for n in nodes: # Create a new action to start the destroy action node_action = new_action(n, db) init_action_process(node_action, "destroy") db.add(node_action) result[n.node_name] = "success" close_session(db) # Build the result for n in wanted: if n not in result: result[n] = "failure" return json.dumps(result)