def get_client_node_data(node_type, node_name, vpc_name): log_service("get client node data() "+ node_type + node_name + vpc_name) file_path = "" 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 "+ node_name) 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 else: file_path = "var/l2_transits/" + node_name else: log_service("Wrong node type") return False return do_json.json_read(file_path + ".json")
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 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)
import constants import ipaddress """@params: param1 = connection config name (required) """ if __name__ == "__main__": if (len(sys.argv) < 2): raas_utils.log_service("Please give connection config file") exit(1) connection_config_file = sys.argv[1] connection_name = connection_config_file.split('/')[-1].split('.')[0] cid = hyp_utils.get_client_id() connection_data = do_json.json_read(connection_config_file) raas_utils.log_service(connection_data) vpc_name = connection_data["vpc_name"] pc_name = connection_data["pc_name"] leaf_name = connection_data["leaf_name"] if not raas_utils.client_exists_pc(vpc_name, pc_name): raas_utils.log_service("pc does not exists " + pc_name) exit(1) if not raas_utils.client_exists_leaf(vpc_name, leaf_name): raas_utils.log_service("leaf does not exist " + leaf_name) exit(1) pc_hypervisor_name = connection_data["pc_hypervisor_name"] leaf_hypervisor_name = connection_data["leaf_hypervisor_name"]
"""@params: param1 = vpc config file (required) """ if __name__=="__main__": if (len(sys.argv) < 2): raas_utils.log_client("VPC config not provided") raas_utils.log_service("Please give vpc config file") exit(1) spine_config_file = sys.argv[1] spine_name = spine_config_file.split('/')[-1].split('.')[0] #Assumed customer always gives correct config file spine_data = do_json.json_read(spine_config_file) hypervisor = spine_data["hypervisor_name"] hypervisor_arg = "hypervisor="+hypervisor hypervisors_data = hyp_utils.get_hypervisors_data() hypervisor_ip = hyp_utils.get_hyp_ip(hypervisor) vpc_name = spine_data["vpc_name"] if not raas_utils.client_exists_vpc(vpc_name): raas_utils.log_client("VPC does not exist") raas_utils.log_service("VPC does not exist") exit(1)
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 get_new_veth_subnet(subnet_name): file_path = "var/reserved_subnets.json" subnet_data = do_json.json_read(file_path) return subnet_data[subnet_name]
"""@params: param1 = l1_transit config file (required) """ if __name__=="__main__": if (len(sys.argv) < 2): raas_utils.log_client("Please give l1_transit config file.....aborting") raas_utils.log_service("Please give l1_transit config file......aborting") exit(1) l1_transit_config_file = sys.argv[1] l1_transit_name = l1_transit_config_file.split('/')[-1].split('.')[0] #Assumed customer always gives correct config file l1_transit_data = do_json.json_read(l1_transit_config_file) hypervisor = l1_transit_data["hypervisor_name"] hypervisor_arg = "hypervisor="+hypervisor hypervisors_data = hyp_utils.get_hypervisors_data() hypervisor_ip = hyp_utils.get_hyp_ip(hypervisor) if raas_utils.client_exists_l1_transit(l1_transit_name): raas_utils.log_service("l1_transit already exists "+ l1_transit_name +".....aborting") raas_utils.log_client("l1_transit already exists "+ l1_transit_name+".....aborting") exit(1) #All prereq checks done at this point l1_transit_capacity = l1_transit_data["capacity"]
def get_mgmt_nid(): json_data = do_json.json_read(constants.mgmt_net_file) return json_data["network_id"]
"""@params: param1 = vpc config file (required) """ if __name__=="__main__": if (len(sys.argv) < 2): print("Please give vpc config file") exit(1) peer_config_file = sys.argv[1] leaf_name = leaf_config_file.split('/')[-1].split('.')[0] #Assumed customer always gives correct config file peering_data = do_json.json_read(leaf_config_file) hypervisor = leaf_data["hypervisor_name"] hypervisor_arg = "hypervisor="+hypervisor hypervisors_data = hyp_utils.get_hypervisors_data() hypervisor_ip = hyp_utils.get_hyp_ip(hypervisor) vpc_name = leaf_data["vpc_name"] if not raas_utils.client_exists_vpc(vpc_name): print(vpc_name+ " VPC does not exist") exit(1) vpc_id=hyp_utils.get_hyp_vpc_name(hypervisor,vpc_name) spine_name = leaf_data["spine_name"] if not raas_utils.client_exists_spine(vpc_name,spine_name):
import ipaddress """@params: param1 = bgp config file (required) """ if __name__ == "__main__": if (len(sys.argv) < 2): raas_utils.log_service("Please give bgp config file") exit(1) weight_file = sys.argv[1] #pc_name = pc_config_file.split('/')[-1].split('.')[0] #Assumed customer always gives correct config file weight_data = do_json.json_read(weight_file) hypervisor = weight_data["hypervisor_name"] hypervisor_arg = "hypervisor=" + hypervisor hypervisors_data = hyp_utils.get_hypervisors_data() hypervisor_ip = hyp_utils.get_hyp_ip(hypervisor) node_type = weight_data["node_type"] path_choice_type = weight_data["path_choice_type"] vpc_name = "" #check if vpc exists for spine if (node_type == "spine"): vpc_name = weight_data["vpc_name"] if not raas_utils.client_exists_vpc(vpc_name):
def get_client_id(): hypervisors_data = do_json.json_read(constants.hypervisors_file) return hypervisors_data["customer_id"]
def get_hypervisors_data(): hypervisors_data = do_json.json_read(constants.hypervisors_file) return hypervisors_data
"""@params: param1 = vpc config file (required) """ if __name__=="__main__": if (len(sys.argv) < 2): raas_utils.log_client("Config not provided.........aborting") raas_utils.log_service("Please give vpc config file") exit(1) pc_config_file = sys.argv[1] pc_name = pc_config_file.split('/')[-1].split('.')[0] #Assumed customer always gives correct config file pc_data = do_json.json_read(pc_config_file) hypervisor = pc_data["hypervisor_name"] hypervisor_arg = "hypervisor="+hypervisor hypervisors_data = hyp_utils.get_hypervisors_data() hypervisor_ip = hyp_utils.get_hyp_ip(hypervisor) vpc_name = pc_data["vpc_name"] if not raas_utils.client_exists_vpc(vpc_name): raas_utils.log_service("VPC does not exist") exit(1) if raas_utils.client_exists_pc(vpc_name, pc_name):
import ipaddress """@params: param1 = bgp config file (required) """ if __name__ == "__main__": if (len(sys.argv) < 2): raas_utils.log_service("Please give bgp config file") exit(1) multipath_file = sys.argv[1] #pc_name = pc_config_file.split('/')[-1].split('.')[0] #Assumed customer always gives correct config file multipath_data = do_json.json_read(multipath_file) hypervisor = multipath_data["hypervisor_name"] hypervisor_arg = "hypervisor=" + hypervisor hypervisors_data = hyp_utils.get_hypervisors_data() hypervisor_ip = hyp_utils.get_hyp_ip(hypervisor) node_type = multipath_data["node_type"] vpc_name = "" #check if vpc exists for spine if (node_type == "spine"): vpc_name = multipath_data["vpc_name"] if not raas_utils.client_exists_vpc(vpc_name): raas_utils.log_service("VPC does not exist")
def get_spine_ip(vpc, spine): file_path = constants.var_vpc + vpc + \ constants.vpc_spines + spine + ".json" spine_data = do_json.json_read(file_path) spine_ip = spine_data["ip"] return spine_ip
#logging.basicConfig(filename='raas.log', filemode='a', format='%(asctime)s %(name)s - %(levelname)s - %(message)s', level=logging.INFO) """@params: param1 = bgp config file (required) """ if __name__ == "__main__": if (len(sys.argv) < 2): raas_utils.log_service("Please give bgp config file") exit(1) advertise_file = sys.argv[1] #pc_name = pc_config_file.split('/')[-1].split('.')[0] #Assumed customer always gives correct config file advertise_data = do_json.json_read(advertise_file) hypervisor = advertise_data["hypervisor_name"] hypervisor_arg = "hypervisor=" + hypervisor hypervisors_data = hyp_utils.get_hypervisors_data() hypervisor_ip = hyp_utils.get_hyp_ip(hypervisor) vpc_name = advertise_data["vpc_name"] if not raas_utils.client_exists_vpc(vpc_name): raas_utils.log_service("VPC does not exist") exit(1) spine_name = advertise_data["spine_name"] l1_transit_name = advertise_data["l1_transit_name"]
"""@params: param1 = config file (required) """ if __name__=="__main__": if (len(sys.argv) < 2): raas_utils.log_service("Please give peering config file") exit(1) peer_config_file = sys.argv[1] leaf_name = peer_config_file.split('/')[-1].split('.')[0] #Assumed customer always gives correct config file peering_data = do_json.json_read(peer_config_file) hypervisor = peering_data["hypervisor_name"] hypervisor_arg = "hypervisor="+hypervisor hypervisors_data = hyp_utils.get_hypervisors_data() hypervisor_ip = hyp_utils.get_hyp_ip(hypervisor) vpc_name = peering_data["vpc_name"] if not raas_utils.client_exists_vpc(vpc_name): raas_utils.log_service(vpc_name+ " VPC does not exist") exit(1) vpc_id=hyp_utils.get_hyp_vpc_name(hypervisor,vpc_name) spine_name = peering_data["spine_name"] if not raas_utils.client_exists_spine(vpc_name,spine_name):