def write_spine_ip(vpc, spine, spine_ip): file_path = constants.var_vpc + vpc + \ constants.vpc_spines + spine + ".json" spine_data = do_json.json_read(file_path) spine_data["ip"] = spine_ip do_json.json_write(spine_data, file_path)
def write_client_node_data(node_type, node_name, vpc_name, key, value): file_path = "" client_node_data = get_client_node_data(node_type, node_name, vpc_name) client_node_data[key] = value if (node_type == "spine"): if not client_exists_spine(vpc_name, node_name): log_service("Spine does not exists") return False else: file_path = "var/vpc/" + vpc_name + "/spines/" + node_name elif (node_type == "l1_transit"): if not client_exists_l1_transit(node_name): log_service("l1_transit does not exists") return False else: file_path = "var/l1_transits/" + node_name elif (node_type == "l2_transit"): if not client_exists_l2_transit(node_name): log_service("l2_transit does not exists") return False file_path = "var/l2_transits/" + node_name else: log_service("Wrong node type") return False do_json.json_write(client_node_data, file_path+".json")
def client_add_leaf_pc(vpc_name, pc_name, leaf_name): file_path = constants.var_vpc + vpc_name + \ constants.vpc_pcs + pc_name + ".json" pc_data = do_json.json_read(file_path) leafs = pc_data["leafs"] leafs.append(leaf_name) pc_data["leafs"] = leafs do_json.json_write(pc_data, file_path)
def client_add_leaf(hypervisor, vpc_name, leaf_name, network_id): file_path = constants.var_vpc + vpc_name + \ constants.vpc_leafs + leaf_name + ".json" new_leaf_data = constants.new_leaf_data new_leaf_data["hypervisor_name"] = hypervisor new_leaf_data["vpc_name"] = vpc_name new_leaf_data["leaf_name"] = leaf_name new_leaf_data["network_id"] = network_id do_json.json_write(new_leaf_data, file_path)
def client_add_pc(hypervisor_name,vpc_name, pc_name, capacity): file_path = constants.var_vpc + vpc_name + \ constants.vpc_pcs + pc_name + ".json" log_service(constants.new_pc_data) new_pc_data = constants.new_pc_data new_pc_data["hypervisor_name"] = hypervisor_name new_pc_data["vpc_name"] = vpc_name new_pc_data["pc_name"] = pc_name new_pc_data["capacity"] = capacity do_json.json_write(new_pc_data, file_path)
def client_add_spine(hypervisor, vpc_name, spine_name, capacity): file_path = constants.var_vpc + vpc_name + \ constants.vpc_spines + spine_name + ".json" new_spine_data = constants.new_spine_data new_spine_data["hypervisor_name"] = hypervisor new_spine_data["vpc_name"] = vpc_name new_spine_data["spine_name"] = spine_name new_spine_data["capacity"] = capacity do_json.json_write(new_spine_data, file_path)
def client_add_l2_transit(hypervisor, l2_transit_name, capacity): dir_path = constants.l2_transits if not os.path.exists(dir_path): os.makedirs(dir_path) file_path = dir_path + l2_transit_name + ".json" new_l2_transit_data = constants.new_l2_transit_data new_l2_transit_data["hypervisor_name"] = hypervisor new_l2_transit_data["l2_transit_name"] = l2_transit_name new_l2_transit_data["capacity"] = capacity do_json.json_write(new_l2_transit_data, file_path)
def client_add_l1_transit(hypervisor, l1_transit_name, capacity, self_as): dir_path = constants.l1_transits; if not os.path.exists(dir_path): os.makedirs(dir_path) file_path = dir_path + l1_transit_name + ".json" new_l1_transit_data = constants.new_l1_transit_data new_l1_transit_data["hypervisor_name"] = hypervisor new_l1_transit_data["l1_transit_name"] = l1_transit_name new_l1_transit_data["capacity"] = capacity new_l1_transit_data["self_as"] = self_as do_json.json_write(new_l1_transit_data, file_path)
def client_add_vpc(hypervisor, vpc_name): vpc_dir = constants.var_vpc + vpc_name + "/" file_path = vpc_dir + vpc_name + ".json" if not os.path.exists(vpc_dir): os.makedirs(vpc_dir) new_vpc_data = constants.new_vpc_data new_vpc_data["hypervisor_name"] = hypervisor new_vpc_data["vpc_name"] = vpc_name do_json.json_write(new_vpc_data, file_path) vpc_spines_dir = vpc_dir + constants.vpc_spines if not os.path.exists(vpc_spines_dir): os.makedirs(vpc_spines_dir) vpc_leafs_dir = vpc_dir + constants.vpc_leafs if not os.path.exists(vpc_leafs_dir): os.makedirs(vpc_leafs_dir) vpc_pcs_dir = vpc_dir + constants.vpc_pcs if not os.path.exists(vpc_pcs_dir): os.makedirs(vpc_pcs_dir)
def update_veth_subnet(subnet_name,new_subnet): file_path = "var/reserved_subnets.json" subnet_data = do_json.json_read(file_path) subnet_data[subnet_name]=new_subnet do_json.json_write(subnet_data, file_path)
def write_hypervisors_data(hypervisors_data): do_json.json_write(hypervisors_data, constants.hypervisors_file)