示例#1
0
    def get_vtn_config(self, o, attrs):

        privateGatewayMac = None
        localManagementIp = None
        ovsdbPort = None
        sshPort = None
        sshUser = None
        sshKeyFile = None
        mgmtSubnetBits = None
        xosEndpoint = None
        xosUser = None
        xosPassword = None

        # VTN-specific configuration from the VTN Service
        vtns = VTNService.get_service_objects().all()
        if vtns:
            vtn = vtns[0]
            privateGatewayMac = vtn.privateGatewayMac
            localManagementIp = vtn.localManagementIp
            ovsdbPort = vtn.ovsdbPort
            sshPort = vtn.sshPort
            sshUser = vtn.sshUser
            sshKeyFile = vtn.sshKeyFile
            mgmtSubnetBits = vtn.mgmtSubnetBits
            xosEndpoint = vtn.xosEndpoint
            xosUser = vtn.xosUser
            xosPassword = vtn.xosPassword

        # OpenStack endpoints and credentials
        keystone_server = "http://keystone:5000/v2.0/"
        user_name = "admin"
        password = "******"
        controllers = Controller.objects.all()
        if controllers:
            controller = controllers[0]
            keystone_server = controller.auth_url
            user_name = controller.admin_user
            tenant_name = controller.admin_tenant
            password = controller.admin_password

        data = {
            "apps": {
                "org.onosproject.cordvtn": {
                    "cordvtn": {
                        "privateGatewayMac": privateGatewayMac,
                        "localManagementIp": localManagementIp,
                        "ovsdbPort": ovsdbPort,
                        "ssh": {
                            "sshPort": sshPort,
                            "sshUser": sshUser,
                            "sshKeyFile": sshKeyFile
                        },
                        "openstack": {
                            "endpoint": keystone_server,
                            "tenant": tenant_name,
                            "user": user_name,
                            "password": password
                        },
                        "xos": {
                            "endpoint": xosEndpoint,
                            "user": xosUser,
                            "password": xosPassword
                        },
                        "publicGateways": [],
                        "nodes": []
                    }
                }
            }
        }

        # Generate apps->org.onosproject.cordvtn->cordvtn->nodes
        nodes = Node.objects.all()
        for node in nodes:
            nodeip = socket.gethostbyname(node.name)

            try:
                bridgeId = self.get_node_tag(o, node, "bridgeId")
                dataPlaneIntf = self.get_node_tag(o, node, "dataPlaneIntf")
                dataPlaneIp = self.get_node_tag(o, node, "dataPlaneIp")
            except:
                logger.error("not adding node %s to the VTN configuration" %
                             node.name)
                continue

            node_dict = {
                "hostname": node.name,
                "hostManagementIp": "%s/%s" % (nodeip, mgmtSubnetBits),
                "bridgeId": bridgeId,
                "dataPlaneIntf": dataPlaneIntf,
                "dataPlaneIp": dataPlaneIp
            }
            data["apps"]["org.onosproject.cordvtn"]["cordvtn"]["nodes"].append(
                node_dict)

        # Generate apps->org.onosproject.cordvtn->cordvtn->publicGateways
        # Pull the gateway information from vRouter
        vrouters = VRouterService.get_service_objects().all()
        if vrouters:
            for gateway in vrouters[0].get_gateways():
                gatewayIp = gateway['gateway_ip'].split('/', 1)[0]
                gatewayMac = gateway['gateway_mac']
                gateway_dict = {
                    "gatewayIp": gatewayIp,
                    "gatewayMac": gatewayMac
                }
                data["apps"]["org.onosproject.cordvtn"]["cordvtn"][
                    "publicGateways"].append(gateway_dict)

        return json.dumps(data, indent=4, sort_keys=True)
示例#2
0
    def get_onos_netcfg(self, vtn):
        privateGatewayMac = vtn.privateGatewayMac
        localManagementIp = vtn.localManagementIp
        ovsdbPort = vtn.ovsdbPort
        sshPort = vtn.sshPort
        sshUser = vtn.sshUser
        sshKeyFile = vtn.sshKeyFile
        mgmtSubnetBits = vtn.mgmtSubnetBits
        xosEndpoint = vtn.xosEndpoint
        xosUser = vtn.xosUser
        xosPassword = vtn.xosPassword

        controllerPort = vtn.controllerPort
        if ":" in controllerPort:
            (c_hostname, c_port) = controllerPort.split(":", 1)
            controllerPort = socket.gethostbyname(c_hostname) + ":" + c_port
        else:
            controllerPort = ":" + controllerPort

        data = {
            "apps": {
                "org.opencord.vtn": {
                    "cordvtn": {
                        "privateGatewayMac": privateGatewayMac,
                        "localManagementIp": localManagementIp,
                        "ovsdbPort": ovsdbPort,
                        "ssh": {
                            "sshPort": sshPort,
                            "sshUser": sshUser,
                            "sshKeyFile": sshKeyFile
                        },
                        "xos": {
                            "endpoint": xosEndpoint,
                            "user": xosUser,
                            "password": xosPassword
                        },
                        "publicGateways": [],
                        "nodes": [],
                        "controllers": [controllerPort]
                    }
                }
            }
        }

        # Generate apps->org.opencord.vtn->cordvtn->openstack
        controllers = Controller.objects.all()
        if controllers:
            controller = controllers[0]
            keystone_server = controller.auth_url
            user_name = controller.admin_user
            tenant_name = controller.admin_tenant
            password = controller.admin_password
            openstack = {
                "endpoint": keystone_server,
                "tenant": tenant_name,
                "user": user_name,
                "password": password
            }
            data["apps"]["org.opencord.vtn"]["cordvtn"][
                "openstack"] = openstack

        # Generate apps->org.opencord.vtn->cordvtn->nodes
        nodes = Node.objects.all()
        for node in nodes:
            nodeip = socket.gethostbyname(node.name)

            try:
                bridgeId = self.get_node_tag(node, "bridgeId")
                dataPlaneIntf = self.get_node_tag(node, "dataPlaneIntf")
                dataPlaneIp = self.get_node_tag(node, "dataPlaneIp")
            except:
                logger.error("not adding node %s to the VTN configuration" %
                             node.name)
                continue

            node_dict = {
                "hostname": node.name,
                "hostManagementIp": "%s/%s" % (nodeip, mgmtSubnetBits),
                "bridgeId": bridgeId,
                "dataPlaneIntf": dataPlaneIntf,
                "dataPlaneIp": dataPlaneIp
            }

            # this one is optional
            try:
                node_dict["hostManagementIface"] = self.get_node_tag(
                    node, "hostManagementIface")
            except IndexError:
                pass

            data["apps"]["org.opencord.vtn"]["cordvtn"]["nodes"].append(
                node_dict)

        # Generate apps->org.onosproject.cordvtn->cordvtn->publicGateways
        # Pull the gateway information from vRouter
        try:
            from services.vrouter.models import VRouterService

            vrouters = VRouterService.get_service_objects().all()
            if vrouters:
                for gateway in vrouters[0].get_gateways():
                    gatewayIp = gateway['gateway_ip'].split('/', 1)[0]
                    gatewayMac = gateway['gateway_mac']
                    gateway_dict = {
                        "gatewayIp": gatewayIp,
                        "gatewayMac": gatewayMac
                    }
                    data["apps"]["org.opencord.vtn"]["cordvtn"][
                        "publicGateways"].append(gateway_dict)
        except:
            logger.info(
                "No VRouter service present, not adding publicGateways to config"
            )

        return json.dumps(data, indent=4, sort_keys=True)
示例#3
0
    def get_vtn_config(self, o, attrs):

        privateGatewayMac = None
        localManagementIp = None
        ovsdbPort = None
        sshPort = None
        sshUser = None
        sshKeyFile = None
        mgmtSubnetBits = None

        # VTN-specific configuration from the VTN Service
        vtns = VTNService.get_service_objects().all()
        if vtns:
            vtn = vtns[0]
            privateGatewayMac = vtn.privateGatewayMac
            localManagementIp = vtn.localManagementIp
            ovsdbPort = vtn.ovsdbPort
            sshPort = vtn.sshPort
            sshUser = vtn.sshUser
            sshKeyFile = vtn.sshKeyFile
            mgmtSubnetBits = vtn.mgmtSubnetBits

        # OpenStack endpoints and credentials
        keystone_server = "http://keystone:5000/v2.0/"
        user_name = "admin"
        password = "******"
        controllers = Controller.objects.all()
        if controllers:
            controller = controllers[0]
            keystone_server = controller.auth_url
            user_name = controller.admin_user
            tenant_name = controller.admin_tenant
            password = controller.admin_password

        data = {
            "apps" : {
                "org.onosproject.cordvtn" : {
                    "cordvtn" : {
                        "privateGatewayMac" : privateGatewayMac,
                        "localManagementIp": localManagementIp,
                        "ovsdbPort": ovsdbPort,
                        "ssh": {
                            "sshPort": sshPort,
                            "sshUser": sshUser,
                            "sshKeyFile": sshKeyFile
                        },
                        "openstack": {
                            "endpoint": keystone_server,
                            "tenant": tenant_name,
                            "user": user_name,
                            "password": password
                        },
                        "publicGateways": [],
                        "nodes" : []
                    }
                }
            }
        }

        # Generate apps->org.onosproject.cordvtn->cordvtn->nodes
        nodes = Node.objects.all()
        for node in nodes:
            nodeip = socket.gethostbyname(node.name)

            try:
                bridgeId = self.node_tag_default(o, node, "bridgeId", "of:0000000000000001")
                dataPlaneIntf = self.node_tag_default(o, node, "dataPlaneIntf", "veth1")
                # This should be generated from the AddressPool if not present
                dataPlaneIp = self.node_tag_default(o, node, "dataPlaneIp", "192.168.199.1/24")
            except:
                logger.error("not adding node %s to the VTN configuration" % node.name)
                continue

            node_dict = {
                "hostname": node.name,
                "hostManagementIp": "%s/%s" % (nodeip, mgmtSubnetBits),
                "bridgeId": bridgeId,
                "dataPlaneIntf": dataPlaneIntf,
                "dataPlaneIp": dataPlaneIp
            }
            data["apps"]["org.onosproject.cordvtn"]["cordvtn"]["nodes"].append(node_dict)

        # Generate apps->org.onosproject.cordvtn->cordvtn->publicGateways
        # Pull the gateway information from vRouter
        vrouters = VRouterService.get_service_objects().all()
        if vrouters:
            for gateway in vrouters[0].get_gateways():
                gatewayIp = gateway['gateway_ip'].split('/',1)[0]
                gatewayMac = gateway['gateway_mac']
                gateway_dict = {
                    "gatewayIp": gatewayIp,
                    "gatewayMac": gatewayMac
                }
                data["apps"]["org.onosproject.cordvtn"]["cordvtn"]["publicGateways"].append(gateway_dict)

        return json.dumps(data, indent=4, sort_keys=True)
示例#4
0
 def get_vrouter_service(self):
     vrouterServices = VRouterService.get_service_objects().all()
     if not vrouterServices:
         raise XOSConfigurationError("No VROUTER Services available")
     return vrouterServices[0]
示例#5
0
文件: models.py 项目: girishgc/vsg
 def get_vrouter_service(self):
     vrouterServices = VRouterService.get_service_objects().all()
     if not vrouterServices:
         raise XOSConfigurationError("No VROUTER Services available")
     return vrouterServices[0]