Beispiel #1
0
 def GetGrpcCreateMessage(self):
     grpcmsg = interface_pb2.InterfaceRequest()
     spec = grpcmsg.Request.add()
     spec.Id = self.uuid.GetUuid()
     spec.AdminStatus = self.ifadminstatus
     if self.iftype == interface_pb2.IF_TYPE_L3:
         spec.L3IfSpec.VpcId = utils.PdsUuid.GetUUIDfromId(
             self.ifobj.vpcid, objtype=api.ObjectTypes.VPC)
         spec.L3IfSpec.Prefix.Addr.Af = 1
         spec.L3IfSpec.Prefix.Len = int(self.ifobj.prefix._prefixlen)
         spec.L3IfSpec.Prefix.Addr.V4Addr = int(self.ifobj.prefix.ip)
         spec.L3IfSpec.PortId = self.ifobj.portuuid.GetUuid()
         spec.L3IfSpec.Encap.type = self.ifobj.encap
         if self.ifobj.macaddr:
             spec.L3IfSpec.MACAddress = utils.getmac2num(self.ifobj.macaddr,
                                                         reorder=False)
     elif self.iftype == interface_pb2.IF_TYPE_CONTROL:
         spec.ControlIfSpec.Prefix.Addr.Af = 1
         spec.ControlIfSpec.Prefix.Len = int(self.ifobj.prefix._prefixlen)
         spec.ControlIfSpec.Prefix.Addr.V4Addr = int(self.ifobj.prefix.ip)
         spec.ControlIfSpec.MACAddress = utils.getmac2num(
             self.ifobj.macaddr, reorder=False)
         if self.ifobj.gateway:
             spec.ControlIfSpec.Gateway.Af = types_pb2.IP_AF_INET
             spec.ControlIfSpec.Gateway.V4Addr = int(self.ifobj.gateway)
     elif self.iftype == interface_pb2.IF_TYPE_LOOPBACK:
         spec.LoopbackIfSpec.Prefix.Len = int(self.ifobj.prefix._prefixlen)
         spec.LoopbackIfSpec.Prefix.Addr.Af = types_pb2.IP_AF_INET
         spec.LoopbackIfSpec.Prefix.Addr.V4Addr = int(self.ifobj.prefix.ip)
     return grpcmsg
Beispiel #2
0
    def GetGrpcCreateMessage(self):
        grpcmsg = subnet_pb2.SubnetRequest()
        spec = grpcmsg.Request.add()
        spec.Id = self.uuid.GetUuid()
        spec.VPCId = utils.PdsUuid.GetUUIDfromId(self.vpcid,
                                                 objtype=api.ObjectTypes.VPC)
        if self.dhcp_policy_id:
            spec.DHCPPolicyId.append(
                utils.PdsUuid.GetUUIDfromId(
                    self.dhcp_policy_id, objtype=api.ObjectTypes.DHCP_POLICY))
        spec.V4Prefix.Len = self.v4prefix.prefixlen
        spec.V4Prefix.Addr = int(self.v4prefix.network_address)

        if re.search('VXLAN', self.fabricencap, re.I):
            spec.FabricEncap.type = types_pb2.ENCAP_TYPE_VXLAN
            spec.FabricEncap.value.Vnid = self.fabricencapid

        spec.IPv4VirtualRouterIP = int(self.v4virtualrouterip)
        spec.VirtualRouterMac = utils.getmac2num(self.virtualroutermac)
        if self.v4routetableid:
            spec.V4RouteTableId = utils.PdsUuid.GetUUIDfromId(
                self.v4routetableid, objtype=api.ObjectTypes.ROUTETABLE)
        for cur_hostifuuid in self.hostifuuid:
            spec.HostIf.append(cur_hostifuuid.GetUuid())

        if self.ingress_policy_id:
            spec.IngV4SecurityPolicyId.append(
                utils.PdsUuid.GetUUIDfromId(self.ingress_policy_id,
                                            objtype=api.ObjectTypes.POLICY))
        if self.egress_policy_id:
            spec.EgV4SecurityPolicyId.append(
                utils.PdsUuid.GetUUIDfromId(self.egress_policy_id,
                                            objtype=api.ObjectTypes.POLICY))
        return grpcmsg
Beispiel #3
0
 def __init__(self,
              id,
              vpcid,
              localip,
              remoteip,
              macaddr,
              tunneltype,
              encaptype,
              vnid,
              nhid=None,
              ipsec_enc_id=None,
              ipsec_dec_id=None):
     self.id = id
     self.uuid = utils.PdsUuid(self.id, objtype=api.ObjectTypes.TUNNEL)
     self.vpcid = vpcid
     self.localip = ipaddress.IPv4Address(localip)
     self.remoteip = ipaddress.IPv4Address(remoteip)
     if macaddr:
         self.macaddr = utils.getmac2num(macaddr, reorder=True)
     else:
         self.macaddr = None
     self.tunneltype = tunneltype
     self.encaptype = encaptype
     self.vnid = vnid
     self.nhid = nhid
     self.encrypt_id = ipsec_enc_id
     self.decrypt_id = ipsec_dec_id
     return
Beispiel #4
0
 def GetGrpcCreateMessage(self):
     grpcmsg = vnic_pb2.VnicRequest()
     spec = grpcmsg.Request.add()
     spec.Id = self.uuid.GetUuid()
     spec.Primary = self.primary
     spec.SubnetId = utils.PdsUuid.GetUUIDfromId(
         self.subnetid, objtype=api.ObjectTypes.SUBNET)
     spec.MACAddress = utils.getmac2num(self.macaddr)
     spec.SourceGuardEnable = self.sourceguard
     if re.search('VXLAN', self.fabricencap, re.I):
         spec.FabricEncap.type = types_pb2.ENCAP_TYPE_VXLAN
         spec.FabricEncap.value.Vnid = self.fabricencapid
     if self.hostifuuid is not None:
         spec.HostIf = self.hostifuuid.GetUuid()
     if self.rxmirrorid:
         spec.RxMirrorSessionId.extend(self.rxmirrorid)
     if self.txmirrorid:
         spec.TxMirrorSessionId.extend(self.txmirrorid)
     if re.search('DOT1Q', self.encap, re.I):
         spec.VnicEncap.type = types_pb2.ENCAP_TYPE_DOT1Q
         spec.VnicEncap.value.VlanId = self.vlan1
     elif re.search('QinQ', self.encap, re.I):
         spec.VnicEncap.type = types_pb2.ENCAP_TYPE_QINQ
         spec.VnicEncap.value.QinQ.STag = self.vlan1
         spec.VnicEncap.value.QinQ.CTag = self.vlan2
     spec.FlowLearnEn = self.flow_learn_en
     spec.HostName = self.hostname
     return grpcmsg
Beispiel #5
0
 def GetGrpcCreateMessage(self):
     grpcmsg = device_pb2.DeviceRequest()
     grpcmsg.Request.IPAddr.Af = types_pb2.IP_AF_INET
     grpcmsg.Request.IPAddr.V4Addr = int(self.ip)
     if self.gatewayip:
         grpcmsg.Request.GatewayIP.Af = types_pb2.IP_AF_INET
         grpcmsg.Request.GatewayIP.V4Addr = int(self.gatewayip)
     grpcmsg.Request.DevOperMode = self.deviceopermode
     grpcmsg.Request.DeviceProfile = self.deviceprofile
     grpcmsg.Request.SymmetricRoutingEn = True
     if self.mac:
         grpcmsg.Request.MACAddr = utils.getmac2num(self.mac)
     return grpcmsg
Beispiel #6
0
 def __init__(self,
              id,
              key_type,
              macaddr,
              ip,
              vpcid,
              subnetid=None,
              tunnelid=None,
              encaptype=None,
              encapslotid=None,
              nexthopgroupid=None,
              vnicid=None,
              public_ip=None,
              tags=[]):
     self.id = id
     self.uuid = utils.PdsUuid(self.id, objtype=api.ObjectTypes.MAPPING)
     self.keytype = key_type
     self.macaddr = utils.getmac2num(macaddr)
     if type(ip) is ipaddress.IPv4Address:
         self.af = types_pb2.IP_AF_INET
         self.ip = int(ip)
     elif type(ip) is ipaddress.IPv6Address:
         self.af = types_pb2.IP_AF_INET6
         self.ip = ip.packed
     self.nexthopgroupid = nexthopgroupid
     self.vpcid = vpcid
     self.subnetid = subnetid
     self.tunnelid = tunnelid
     self.encaptype = encaptype
     self.encapslotid = encapslotid
     self.vnicid = vnicid
     self.public_ip = None
     if public_ip:
         self.public_ip = int(public_ip)
     self.tags = tags
     return