def ModifyHostInterface(self, hostifidx=None): if not utils.IsNetAgentMode(): return False if utils.IsDryRun(): return True if len(self.HostIfUuid) != 0: #dissociate this from subnet first InterfaceClient.UpdateHostInterfaces(self.Node, [self], True) if hostifidx == None: self.HostIfIdx = [InterfaceClient.GetHostInterface(self.Node)] else: self.HostIfIdx = [hostifidx] node_uuid = EzAccessStoreClient[self.Node].GetNodeUuid(self.Node) self.HostIfUuid = [] for ifidx in self.HostIfIdx: self.HostIfUuid.append(utils.PdsUuid(ifidx, node_uuid=node_uuid)) vnicObjs = list( filter(lambda x: (x.ObjType == api.ObjectTypes.VNIC), self.Children)) for vnic in vnicObjs: vnic.HostIfIdx = self.HostIfIdx[0] vnic.HostIfUuid = utils.PdsUuid(vnic.HostIfIdx, node_uuid=node_uuid) InterfaceClient.UpdateHostInterfaces(self.Node, [self]) return True
def CreateObjects(self, node): objDb = self.GetObjectsByOrigins(node) fixed = objDb[topo.OriginTypes.FIXED] discovered = objDb[topo.OriginTypes.DISCOVERED] implicitly_created = objDb[topo.OriginTypes.IMPLICITLY_CREATED] logger.info(f"{self.ObjType.name} objects: {len(fixed)} fixed, " f"{len(discovered)} discovered, " f"and {len(implicitly_created)} implicity_created") # return if there is no fixed object if len(fixed) == 0: logger.info(f"Skip Creating {self.ObjType.name} Objects in {node}") return True self.ShowObjects(node) logger.info(f"Creating {len(fixed)} {self.ObjType.name} Objects in {node}") if utils.IsNetAgentMode(): api.client[node].Create(self.ObjType, fixed) #api.client[node].Update(self.ObjType, implicitly_created) else: cookie = utils.GetBatchCookie(node) msgs = list(map(lambda x: x.GetGrpcCreateMessage(cookie), fixed)) api.client[node].Create(self.ObjType, msgs) #TODO: Add validation for create & based on that set HW habitant list(map(lambda x: x.SetHwHabitant(True), fixed)) return True
def ValidatePdsSpecCompositeAttrs(self, objSpec, spec): mismatchingAttrs = [] listAttrs = [ 'HostIf', 'IngV4SecurityPolicyId', 'IngV6SecurityPolicyId', 'EgV4SecurityPolicyId', 'EgV6SecurityPolicyId' ] for attr in listAttrs: if not utils.ValidateListAttr(getattr(objSpec, attr), getattr(spec, attr)): mismatchingAttrs.append(attr) if self.IpV6Valid and spec.V6Prefix != objSpec.V6Prefix: mismatchingAttrs.append('V6Prefix') if self.IpV6Valid and spec.IPv6VirtualRouterIP != objSpec.IPv6VirtualRouterIP: mismatchingAttrs.append('IPv6VirtualRouterIP') # Currently In NetAgentMode we create multiple DHCP Relay policies if utils.IsNetAgentMode(): if not utils.ValidateListAttr(getattr(objspec, 'DHCPPolicyId'), getattr(spec, 'DHCPPolicyId')): mismatchingAttrs.append('DHCPPolicyId') else: # In other modes we create a single DHCP Proxy Policy if getattr(objSpec, 'DHCPPolicyId') != getattr( spec, 'DHCPPolicyId'): mismatchingAttrs.append('DHCPPolicyId') return mismatchingAttrs
def Create(self, spec=None): node = self.Node if utils.IsSkipSetup(): logger.info("Skip Creating objects in pds-agent for node ", node) return logger.info("Creating objects in pds-agent for node ", node) InterfaceClient.LoadHostDrivers(node) BatchClient.Start(node) DeviceClient.CreateObjects(node) if (EzAccessStoreClient[node].IsDeviceOverlayRoutingEnabled()): # Cannot extend batch across controlplane hijacked objects # when Overlay routing is enabled BatchClient.Commit(node) BatchClient.Start(node) InterfaceClient.CreateObjects(node) NexthopClient.CreateObjects(node) IpsecEncryptClient.CreateObjects(node) IpsecDecryptClient.CreateObjects(node) TunnelClient.CreateObjects(node) NHGroupClient.CreateObjects(node) VpcClient.CreateObjects(node) MirrorClient.CreateObjects(node) SecurityProfileClient.CreateObjects(node) BatchClient.Commit(node) if not utils.IsDol() and utils.IsNetAgentMode(): SubnetClient.UpdateHostInterfaces(node) OperEventClient.CreateObjects(node) # RmappingClient.OperateObjects(node, 'Create') return True
def CreateObjectsOfType(self, node, nh_type): if (EzAccessStoreClient[node].IsDeviceOverlayRoutingEnabled()): logger.info("Skipping creating nexthop-group objects") return True res = True nhgrp_objs = list() if nh_type == nh_pb2.NEXTHOP_GROUP_TYPE_NONE: nhgrps = filter(lambda x: x.Type == nh_type, self.Objects(node)) nhgrp_objs.extend(nhgrps) elif nh_type == nh_pb2.NEXTHOP_GROUP_TYPE_OVERLAY_ECMP: overlay_nhgrps = filter(lambda x: x.Type == nh_type, self.Objects(node)) nhgrp_objs.extend(overlay_nhgrps) elif nh_type == nh_pb2.NEXTHOP_GROUP_TYPE_UNDERLAY_ECMP: underlay_nhgrps = filter(lambda x: x.Type == nh_type, self.Objects(node)) nhgrp_objs.extend(underlay_nhgrps) else: assert (0) logger.info( f"Creating {len(nhgrp_objs)} of type {nh_type} {self.ObjType.name} Objects in {node}" ) if utils.IsNetAgentMode(): res = api.client[node].Create(self.ObjType, nhgrp_objs) else: cookie = utils.GetBatchCookie(node) msgs = list( map(lambda x: x.GetGrpcCreateMessage(cookie), nhgrp_objs)) res = api.client[node].Create(self.ObjType, msgs) #TODO: Add validation for create & based on that set HW habitant list(map(lambda x: x.SetHwHabitant(True), nhgrp_objs)) return res
def HttpRead(self, node): if not utils.IsNetAgentMode(): return True resp = api.client[node].GetHttp(self.ObjType) logger.info("HTTP read:", resp) if resp and not self.ValidateHttpRead(node, resp): logger.error("Http Read validation failed for ", self.ObjType) return False return True
def CreateObjects(self, node): if utils.IsNetAgentMode(): route.client.CreateObjects(node) # netagent requires route table before vpc super().CreateObjects(node) DHCPRelayClient.CreateObjects(node) DHCPProxyClient.CreateObjects(node) tag.client.CreateObjects(node) policy.client.CreateObjects(node) policer.client.CreateObjects(node) if not utils.IsNetAgentMode(): route.client.CreateObjects(node) meter.client.CreateObjects(node) BGPClient.CreateObjects(node) BGPPeerClient.CreateObjects(node) BGPPeerAfClient.CreateObjects(node) evpnipvrf.client.CreateObjects(node) evpnipvrfrt.client.CreateObjects(node) subnet.client.CreateObjects(node) nat_pb.client.CreateObjects(node) return
def CreateObjects(self, node): if EzAccessStoreClient[node].IsBitwMode(): logger.info(f"Skip Creating {self.ObjType.name} Objects in {node}") return if not utils.IsNetAgentMode(): cookie = utils.GetBatchCookie(node) if utils.IsL3InterfaceSupported(): cfgObjects = self.__uplinkl3ifs[node].values() # create l3 if for uplink interface logger.info( f"Creating {len(cfgObjects)} L3 {self.ObjType.name} Objects in {node}" ) msgs = list( map(lambda x: x.GetGrpcCreateMessage(cookie), cfgObjects)) api.client[node].Create(api.ObjectTypes.INTERFACE, msgs) list(map(lambda x: x.SetHwHabitant(True), cfgObjects)) if ((EzAccessStoreClient[node].IsDeviceOverlayRoutingEnabled() and utils.IsDol()) or (not EzAccessStoreClient[node].IsDeviceOverlayRoutingEnabled() and not utils.IsDol())): # create loopback interface lo_obj = self.__loopback_if[node] if lo_obj: logger.info( f"Creating 1 Loopback {self.ObjType.name} {lo_obj} Objects in {node}" ) lo_obj.Show() msgs = list( map(lambda x: x.GetGrpcCreateMessage(cookie), [lo_obj])) api.client[node].Create(api.ObjectTypes.INTERFACE, msgs) # create control interface ctrl_obj = self.__control_if[node] if ctrl_obj: logger.info( f"Creating 1 Control {self.ObjType.name} {ctrl_obj} Objects in {node}" ) ctrl_obj.Show() msgs = list( map(lambda x: x.GetGrpcCreateMessage(cookie), [ctrl_obj])) api.client[node].Create(api.ObjectTypes.INTERFACE, msgs) list(map(lambda x: x.SetHwHabitant(True), [ctrl_obj])) else: obj = self.__loopback_if[node] obj.Show() api.client[node].Update(api.ObjectTypes.INTERFACE, [obj]) return
def PopulateSpec(self, grpcmsg): spec = grpcmsg.Request.add() spec.Id = self.GetKey() spec.VPCId = self.VPC.GetKey() spec.ToS = self.ToS utils.GetRpcIPv4Prefix(self.IPPrefix[1], spec.V4Prefix) if self.IpV6Valid: utils.GetRpcIPv6Prefix(self.IPPrefix[0], spec.V6Prefix) spec.IPv4VirtualRouterIP = int(self.VirtualRouterIPAddr[1]) if self.IpV6Valid: spec.IPv6VirtualRouterIP = self.VirtualRouterIPAddr[0].packed spec.VirtualRouterMac = self.VirtualRouterMACAddr.getnum() spec.V4RouteTableId = utils.PdsUuid.GetUUIDfromId( self.V4RouteTableId, ObjectTypes.ROUTE) spec.V6RouteTableId = utils.PdsUuid.GetUUIDfromId( self.V6RouteTableId, ObjectTypes.ROUTE) specAttrs = [ 'IngV4SecurityPolicyId', 'IngV6SecurityPolicyId', 'EgV4SecurityPolicyId', 'EgV6SecurityPolicyId' ] ObjAttrs = [ 'IngV4SecurityPolicyIds', 'IngV6SecurityPolicyIds', 'EgV4SecurityPolicyIds', 'EgV6SecurityPolicyIds' ] for specAttr, ObjAttr in zip(specAttrs, ObjAttrs): policies = getattr(self, ObjAttr, None) if not policies: continue getattr(spec, specAttr).extend(list(map(lambda policyid: \ utils.PdsUuid.GetUUIDfromId(policyid, ObjectTypes.POLICY), policies))) if utils.IsNetAgentMode(): for policyid in self.DHCPPolicyIds: spec.DHCPPolicyId.append( utils.PdsUuid.GetUUIDfromId(policyid, ObjectTypes.DHCP_RELAY)) else: if self.DHCPPolicyIds != None: spec.DHCPPolicyId.append( utils.PdsUuid.GetUUIDfromId(self.DHCPPolicyIds, ObjectTypes.DHCP_PROXY)) utils.PopulateRpcEncap( base.Encap.GetRpcEncapType(self.FabricEncap.GetType()), self.FabricEncap.GetValue(), spec.FabricEncap) if utils.IsPipelineApulu(): for uuid in self.HostIfUuid: spec.HostIf.append(uuid.GetUuid()) spec.ToS = self.ToS return
def UpdateHostInterfaces(self, node, subnets, dissociate=False): if utils.IsDryRun() or not utils.IsNetAgentMode(): return for subnet in subnets: if len(subnet.HostIfIdx) == 0: continue hostif = self.FindHostInterface(node, subnet.HostIfIdx[0]) if hostif: hostif.UpdateVrfAndNetwork(subnet, dissociate) hostif.Show() api.client[node].Update(api.ObjectTypes.INTERFACE, [hostif]) print("after update pf") resp = api.client[node].GetHttp(api.ObjectTypes.INTERFACE) for r in resp: print(r) return
def UpdateImplicit(self): if not utils.IsNetAgentMode(): return if utils.IsDol() and utils.IsDryRun(): return if not self.IsOriginImplicitlyCreated(): return # We need to read info from naples and update the DS resp = api.client[self.Node].GetHttp(self.ObjType) if not resp: return for ifinst in resp: if self.Type == topo.InterfaceTypes.L3: if (not ifinst['spec']['type'] == 'L3'): continue riid = ifinst['meta']['name'] if (self.InterfaceId != int(riid[len(riid) - 1])): continue elif self.Type == topo.InterfaceTypes.LOOPBACK: if (not ifinst['spec']['type'] == 'LOOPBACK'): continue elif self.Type == topo.InterfaceTypes.ETH: if (not ifinst['spec']['type'] == 'HOST_PF'): continue if (ifinst['status']['if-host-status']['host-ifname'] != self.IfName): continue else: continue # Found matching interface, get basic info uuid_str = ifinst['meta']['uuid'] self.UUID = utils.PdsUuid(bytes.fromhex(uuid_str.replace('-','')),\ self.ObjType) # instance found. Store meta info self.Tenant = ifinst['meta']['tenant'] self.Namespace = ifinst['meta']['namespace'] self.SetIfNameFromAgentData(ifinst['meta']['name']) # get ifinfo if 'ip-address' in ifinst['spec']: self.IpPrefix = ipaddress.ip_network(ifinst['spec']['ip-address'],\ False) if 'vrf-name' in ifinst['spec']: self.VrfName = ifinst['spec']['vrf-name'] return
def Generate(self, topospec): node = self.Node BatchClient.GenerateObjects(node, topospec) DeviceClient.GenerateObjects(node, topospec) PortClient.GenerateObjects(node, topospec) PolicerClient.GenerateObjects(node, topospec) InterfaceClient.GenerateHostInterfaces(node, topospec) MirrorClient.GenerateObjects(node, topospec) SecurityProfileClient.GenerateObjects(node, topospec) VpcClient.GenerateObjects(node, topospec) OperClient.GenerateObjects(node) OperEventClient.GenerateObjects(node) if utils.IsDol() and not utils.IsNetAgentMode(): UpgradeClient.GenerateObjects(node) NodeObject.__validate(node) return
def IsReadSupported(self): if utils.IsNetAgentMode(): # Netagent messes up the UUID so don't read return False return True
def PublishHostInterfaces(self, node): if utils.IsDryRun() or utils.IsNetAgentMode(): return for ifobj in self.__hostifs[node].values(): ifobj.ProcessUpdate() return
def IsReadSupported(self): if utils.IsNetAgentMode(): # TODO: Fix validation & remove this return False return True
def ReadAgentInterfaces(self, node): if utils.IsDryRun(): return if not utils.IsNetAgentMode(): return resp = api.client[node].GetHttp(api.ObjectTypes.INTERFACE) return resp
def IsReadSupported(self): if utils.IsNetAgentMode(): # TODO: Add UpdateImplicit support & remove this check return False return True
def IsReadSupported(self): if utils.IsNetAgentMode(): return False return True
def IsReadSupported(self): if utils.IsNetAgentMode() and utils.IsDol(): # TODO: fix l3 intf return False return True
def __init__(self, node, parent, spec, poolid): super().__init__(api.ObjectTypes.SUBNET, node) if hasattr(spec, 'origin'): self.SetOrigin(spec.origin) parent.AddChild(self) ################# PUBLIC ATTRIBUTES OF SUBNET OBJECT ##################### if (hasattr(spec, 'id')): self.SubnetId = spec.id else: self.SubnetId = next(ResmgrClient[node].SubnetIdAllocator) self.GID('Subnet%d' % self.SubnetId) self.UUID = utils.PdsUuid(self.SubnetId, self.ObjType) self.VPC = parent self.PfxSel = parent.PfxSel self.IPPrefix = {} if getattr(spec, 'v6prefix', None) != None or \ getattr(spec, 'v6prefixlen', None) != None: self.IPPrefix[0] = parent.AllocIPv6SubnetPrefix(poolid) self.IpV6Valid = True else: self.IpV6Valid = False if getattr(spec, 'v4prefix', None) != None: self.IPPrefix[1] = ipaddress.ip_network( spec.v4prefix.replace('\\', '/')) else: self.IPPrefix[1] = parent.AllocIPv4SubnetPrefix(poolid) self.ToS = getattr(spec, 'tos', 0) self.VirtualRouterIPAddr = {} self.VirtualRouterMacAddr = None self.V4RouteTableId = route.client.GetRouteV4TableId( node, parent.VPCId) self.V6RouteTableId = route.client.GetRouteV6TableId( node, parent.VPCId) self.IngV4SecurityPolicyIds = utils.GetPolicies( self, spec, node, "V4", "ingress") self.IngV6SecurityPolicyIds = utils.GetPolicies( self, spec, node, "V6", "ingress") self.EgV4SecurityPolicyIds = utils.GetPolicies(self, spec, node, "V4", "egress") self.EgV6SecurityPolicyIds = utils.GetPolicies(self, spec, node, "V6", "egress") self.V4RouteTable = route.client.GetRouteV4Table( node, parent.VPCId, self.V4RouteTableId) self.V6RouteTable = route.client.GetRouteV6Table( node, parent.VPCId, self.V6RouteTableId) self.ToS = 0 self.IPAMname = 'Dhcp1' self.FabricEncap = base.Encap.ParseFromSpec( spec, "fabricencap", 'vxlan', next(ResmgrClient[node].VxlanIdAllocator)) # TODO: clean this host if logic self.HostIfIdx = [] if utils.IsDol(): self.HostIf = InterfaceClient.GetHostInterface(node) if self.HostIf: self.HostIfIdx.append( utils.LifId2HostIfIndex(self.HostIf.lif.id)) node_uuid = None else: self.HostIf = None hostifidx = getattr(spec, 'hostifidx', None) if hostifidx: if isinstance(hostifidx, list): for ifidx in hostifidx: self.HostIfIdx.append( utils.LifIfIndex2HostIfIndex(int(ifidx))) else: self.HostIfIdx.append(int(hostifidx)) elif getattr(spec, 'vnic', None): hostifidx = InterfaceClient.GetHostInterface(node) if hostifidx: self.HostIfIdx.append( utils.LifIfIndex2HostIfIndex(hostifidx)) node_uuid = EzAccessStoreClient[node].GetNodeUuid(node) self.HostIfUuid = [] for ifidx in self.HostIfIdx: self.HostIfUuid.append(utils.PdsUuid(ifidx, node_uuid=node_uuid)) # TODO: randomize maybe? if utils.IsNetAgentMode(): self.DHCPPolicyIds = list( map(lambda x: x.Id, DHCPRelayClient.Objects(node))) else: self.DHCPPolicyIds = getattr(spec, 'dhcppolicy', None) self.Status = SubnetStatus() ################# PRIVATE ATTRIBUTES OF SUBNET OBJECT ##################### if self.IpV6Valid: Resmgr.CreateIPv6AddrPoolForSubnet(self.SubnetId, self.IPPrefix[0]) Resmgr.CreateIPv4AddrPoolForSubnet(self.SubnetId, self.IPPrefix[1]) self.__set_vrouter_attributes(spec) self.DeriveOperInfo() self.Mutable = utils.IsUpdateSupported() self.GenerateChildren(node, spec) self.__fill_default_rules_in_policy(node) self.Show() return