def __add_workloads(redirect_port): req = topo_svc.WorkloadMsg() req.workload_op = topo_svc.ADD for ep in config_api.GetEndpoints(): wl_msg = req.workloads.add() # Make the workload_name unique across nodes by appending node-name wl_msg.workload_name = ep.name + ep.node_name wl_msg.node_name = ep.node_name intf = wl_msg.interfaces.add() if not ep.vnic.DhcpEnabled: intf.ip_prefix = ep.ip_addresses[0] intf.sec_ip_prefix.extend(ep.ip_addresses[1:]) # wl_msg.ipv6_prefix = ep.ip_addresses[1] intf.mac_address = ep.macaddr if ep.vlan != 0: intf.interface_type = topo_svc.INTERFACE_TYPE_VSS else: intf.interface_type = topo_svc.INTERFACE_TYPE_NONE intf.encap_vlan = ep.vlan interface = ep.interface if interface != None: intf.interface = interface intf.parent_interface = intf.interface wl_msg.workload_type = api.GetWorkloadTypeForNode(wl_msg.node_name) wl_msg.workload_image = api.GetWorkloadImageForNode(wl_msg.node_name) wl_msg.mgmt_ip = api.GetMgmtIPAddress(wl_msg.node_name) if redirect_port: _add_exposed_ports(wl_msg) api.Logger.info(f"Workload {wl_msg.workload_name} " f"Node {wl_msg.node_name} Intf {intf.interface} Parent-Intf {intf.parent_interface} " f"IP {intf.ip_prefix} MAC {intf.mac_address} " f"VLAN {intf.encap_vlan}") if len(req.workloads): api.Logger.info("Adding %d Workloads" % len(req.workloads)) resp = api.AddWorkloads(req, skip_bringup=api.IsConfigOnly()) if resp is None: sys.exit(1) dhcp_wl_list = [] for ep in config_api.GetEndpoints(): workload_name = ep.name + ep.node_name wl = api.GetWorkloadByName(workload_name) if wl is None: return api.types.status.CRITICAL wl.vnic = ep.vnic if wl.vnic.DhcpEnabled: dhcp_wl_list.append(wl) wl.ip_prefix = ep.ip_addresses[0] wl.ip_address = wl.ip_prefix.split('/')[0] wl.sec_ip_prefixes = [] wl.sec_ip_addresses = [] for secip in ep.ip_addresses[1:]: wl.sec_ip_prefixes.append(secip) wl.sec_ip_addresses.append(secip.split('/')[0]) if len(dhcp_wl_list): if not dhcp_utils.AcquireIPFromDhcp(dhcp_wl_list): return api.types.status.CRITICAL
def __readd_classic_workloads(target_node=None): req = topo_svc.WorkloadMsg() req.workload_op = topo_svc.ADD for wl in api.GetWorkloads(): if target_node and target_node != wl.node_name: api.Logger.debug("Skipping add classic workload for node %s" % wl.node_name) continue wl_msg = req.workloads.add() intf = wl_msg.interfaces.add() intf.ip_prefix = wl.ip_prefix intf.ipv6_prefix = wl.ipv6_prefix intf.mac_address = wl.mac_address intf.encap_vlan = wl.encap_vlan intf.uplink_vlan = wl.uplink_vlan wl_msg.workload_name = wl.workload_name wl_msg.node_name = wl.node_name intf.pinned_port = wl.pinned_port intf.interface_type = wl.interface_type intf.interface = wl.parent_interface intf.parent_interface = wl.parent_interface intf.device_name = wl.device_name wl_msg.workload_type = wl.workload_type wl_msg.workload_image = wl.workload_image wl_msg.mgmt_ip = api.GetMgmtIPAddress(wl_msg.node_name) if len(req.workloads): resp = api.AddWorkloads(req) if resp is None: return api.types.status.FAILURE return api.types.status.SUCCESS
def AddNaplesWorkloads(target_node=None): req = topo_svc.WorkloadMsg() req.workload_op = topo_svc.ADD wloads = api.GetNaplesWorkloads() for wl in wloads: if wl.SkipNodePush() or (target_node and target_node != wl.node_name): api.Logger.debug("Skipping add workload for node %s" % wl.node_name) continue wl_msg = req.workloads.add() intf = wl_msg.interfaces.add() wl_msg.workload_name = wl.workload_name wl_msg.node_name = wl.node_name intf.ip_prefix = wl.ip_address + "/" + '24' #wl_msg.ipv6_prefix = __prepare_ipv6_address_str_for_endpoint(ep) intf.interface = wl.interface intf.parent_interface = wl.interface intf.interface_type = topo_svc.INTERFACE_TYPE_VSS intf.device_name = wl.device_name wl_msg.workload_type = topo_svc.WorkloadType.Value( 'WORKLOAD_TYPE_BARE_METAL') if len(req.workloads): resp = api.AddWorkloads(req, skip_store=True) if resp is None: return api.types.status.FAILURE return api.types.status.SUCCESS
def __readd_classic_workloads(target_node = None, workloads = []): req = topo_svc.WorkloadMsg() req.workload_op = topo_svc.ADD workloads = workloads if workloads else api.GetWorkloads() for wl in workloads: if target_node and target_node != wl.node_name: api.Logger.debug("Skipping add classic workload for node %s" % wl.node_name) continue wl_msg = req.workloads.add() intf = wl_msg.interfaces.add() intf.ip_prefix = wl.ip_prefix intf.ipv6_prefix = wl.ipv6_prefix intf.sec_ip_prefix.extend(wl.sec_ip_prefixes) intf.mac_address = wl.mac_address intf.encap_vlan = wl.encap_vlan intf.uplink_vlan = wl.uplink_vlan wl_msg.workload_name = wl.workload_name wl_msg.node_name = wl.node_name intf.pinned_port = wl.pinned_port intf.interface_type = wl.interface_type # Interface to be set to parent intf in vlan case, same as workloads created first time interface = wl.parent_interface if interface != None: intf.interface = interface intf.parent_interface = wl.parent_interface wl_msg.workload_type = wl.workload_type wl_msg.workload_image = wl.workload_image wl_msg.mgmt_ip = api.GetMgmtIPAddress(wl_msg.node_name) if len(req.workloads): resp = api.AddWorkloads(req, skip_store=True) if resp is None: sys.exit(1)
def Main(tc): generated_configs = api.GetVeniceConfigs() ip_index = 101 req = topo_svc.WorkloadMsg() req.workload_op = topo_svc.ADD for cfg_object in generated_configs: obj = json.loads(cfg_object.Config) if obj["kind"] != "Workload": continue wl = req.workloads.add() wl.workload_name = obj["meta"]["name"] wl.node_name = obj["spec"]["host-name"] if_obj = obj["spec"]["interfaces"][0] wl.mac_address = if_obj["mac-address"] wl.encap_vlan = if_obj["micro-seg-vlan"] wl.uplink_vlan = if_obj["external-vlan"] wl.ip_prefix = "192.168.%d.%d/24" % (wl.uplink_vlan, ip_index) wl.interface = 'lif100' wl.parent_interface = 'lif100' wl.pinned_port = 1 wl.interface_type = topo_svc.INTERFACE_TYPE_VSS wl.workload_type = api.GetWorkloadTypeForNode(wl.node_name) wl.workload_image = api.GetWorkloadImageForNode(wl.node_name) ip_index += 1 resp = api.AddWorkloads(req) return api.types.status.SUCCESS
def __recover_workloads(target_node=None): objects = netagent_api.QueryConfigs(kind='Endpoint') netagent_api.UpdateNodeUuidEndpoints(objects) req = topo_svc.WorkloadMsg() resp = api.RestoreWorkloads(req) if resp is None: return api.types.status.FAILURE return api.types.status.SUCCESS
def __delete_classic_workloads(target_node=None): req = topo_svc.WorkloadMsg() for wl in api.GetWorkloads(): if target_node and target_node != wl.node_name: api.Logger.debug("Skipping delete workload for node %s" % wl.node_name) continue req.workload_op = topo_svc.DELETE wl_msg = req.workloads.add() wl_msg.workload_name = wl.workload_name wl_msg.node_name = wl.node_name if len(req.workloads): resp = api.DeleteWorkloads(req, True) if resp is None: return api.types.status.FAILURE return api.types.status.SUCCESS
def __add_workloads(nodes): req = topo_svc.WorkloadMsg() # Create list(s) based on NicMode classic_wload_nodes = [] unified_wload_nodes = [] vmotion_enabled_nodes = [] # Iterate over all devices for node in nodes: for dev_name in api.GetDeviceNames(node.Name()): if api.GetTestbedNicMode(node.Name(), dev_name) in [ 'hostpin', 'hostpin_dvs', 'unified' ]: if node.Name() not in unified_wload_nodes: unified_wload_nodes.append(node.Name()) if api.GetTestbedNicMode(node.Name(), dev_name) == 'hostpin_dvs': if node.Name() not in vmotion_enabled_nodes: vmotion_enabled_nodes.append(node.Name()) elif api.GetTestbedNicMode(node.Name(), dev_name) in ['classic', 'sriov']: if node.Name() not in classic_wload_nodes: classic_wload_nodes.append(node.Name()) else: api.Logger.error( "Unknown NicMode for node %s device %s - Skipping" % (node, dev_name)) ret = api.types.status.SUCCESS if classic_wload_nodes: api.Logger.info("Creating Classic-Workloads for %s" % classic_wload_nodes) ret = wl_orch.AddConfigClassicWorkloads(req, classic_wload_nodes) if unified_wload_nodes: api.Logger.info("Creating hostpin/unified mode workloads for %s" % unified_wload_nodes) ret = wl_orch.AddConfigWorkloads(req, unified_wload_nodes) if ret == api.types.status.SUCCESS and len(req.workloads): resp = api.AddWorkloads(req, skip_bringup=api.IsConfigOnly()) if resp is None: return api.types.status.FAILURE if vmotion_enabled_nodes: ret = __setup_vmotion_on_hosts(vmotion_enabled_nodes) return ret
def __delete_classic_workloads(target_node = None, workloads = None): req = topo_svc.WorkloadMsg() req.workload_op = topo_svc.DELETE workloads = workloads if workloads else api.GetWorkloads() for wl in workloads: if target_node and target_node != wl.node_name: api.Logger.debug("Skipping delete workload for node %s" % wl.node_name) continue wl_msg = req.workloads.add() wl_msg.workload_name = wl.workload_name wl_msg.node_name = wl.node_name if len(req.workloads): resp = api.DeleteWorkloads(req, skip_store=True) if resp is None: sys.exit(1)
def __delete_workloads(target_node=None): ep_objs = netagent_api.QueryConfigs(kind='Endpoint') req = topo_svc.WorkloadMsg() for ep in ep_objs: node_name = getattr(ep.spec, "_node_name", None) if not node_name: node_name = ep.spec.node_uuid if target_node and target_node != node_name: api.Logger.info("Skipping delete workload for node %s" % node_name) continue req.workload_op = topo_svc.DELETE wl_msg = req.workloads.add() wl_msg.workload_name = ep.meta.name wl_msg.node_name = node_name if len(req.workloads): resp = api.DeleteWorkloads(req) if resp is None: return api.types.status.FAILURE return api.types.status.SUCCESS
def __add_workloads(): ep_objs = netagent_api.QueryConfigs(kind='Endpoint') for ep in ep_objs.endpoints: req = topo_svc.WorkloadMsg() req.workload_op = topo_svc.ADD wl_msg = req.workloads.add() wl_msg.workload_name = ep.meta.name wl_msg.node_name = getattr(ep.spec, "node-uuid", None) wl_msg.encap_vlan = getattr(ep.spec, 'useg-vlan') wl_msg.ip_prefix = __prepare_ip_address_str_for_endpoint(ep) wl_msg.mac_address = getattr(ep.spec, 'mac-address') lif_uplink = __alloc_lif(wl_msg.node_name) wl_msg.interface = lif_uplink[0] wl_msg.parent_interface = lif_uplink[0] wl_msg.pinned_port = lif_uplink[1] wl_msg.interface_type = topo_svc.INTERFACE_TYPE_SRIOV wl_msg.uplink_vlan = __get_l2segment_vlan_for_endpoint(ep) wl_msg.workload_type = api.GetWorkloadTypeForNode(wl_msg.node_name) wl_msg.workload_image = api.GetWorkloadImageForNode(wl_msg.node_name) resp = api.AddWorkloads(req)