def __init__(self, args_str=None):
        self._args = None
        if not args_str:
            args_str = ' '.join(sys.argv[1:])
        self._parse_args(args_str)

        self._vnc_lib = VncApi(
            self._args.user, self._args.password,
            self._args.tenant_name,
            self._args.api_server_ip,
            self._args.api_server_port, '/',
            api_server_use_ssl=self._args.api_server_use_ssl)
        
        prefix = self._args.prefix
        vmi_id_got = self._args.virtual_machine_interface_id
        route_table_name = self._args.route_table_name

        try:
            ip_nw = IPNetwork(prefix)
        except AddrFormatError:
            print 'Invalid ip address format'
            sys.exit(1)

        project_fq_name_str = 'default-domain:'+ self._args.tenant_name
        project_fq_name = project_fq_name_str.split(':')
        project_obj = self._vnc_lib.project_read(fq_name=project_fq_name)
        
        route_table = RouteTableType(route_table_name)
        route_table.set_route([])
        intf_route_table = InterfaceRouteTable(
                                interface_route_table_routes = route_table,
                                parent_obj=project_obj, 
                                name=route_table_name)
        try:
            route_table_obj = self._vnc_lib.interface_route_table_read(
                                    fq_name = intf_route_table.get_fq_name())
            intf_route_table_id = route_table_obj.uuid
        except NoIdError:
            if self._args.oper == 'del':
                print "Route table %s does not exist" %(route_table_name)
                sys.exit(1)
            print "Creating Route table"
            intf_route_table_id = self._vnc_lib.interface_route_table_create(
                                    intf_route_table)
        intf_route_table_obj = self._vnc_lib.interface_route_table_read(
                                    id = intf_route_table_id) 
        if self._args.oper == 'add':
            intf_route_table_obj = self.add_route(intf_route_table_obj, prefix)
        elif self._args.oper == 'del':
            intf_route_table_obj = self.del_route(intf_route_table_obj, prefix)
        self._vnc_lib.interface_route_table_update(intf_route_table_obj)
        
        #Update the VMI Object now
        vmi_obj = self._vnc_lib.virtual_machine_interface_read(id = vmi_id_got)
        if self._args.oper == 'add':
            vmi_obj.add_interface_route_table(intf_route_table_obj)
        elif self._args.oper == 'del':
            if self.is_route_table_empty(intf_route_table_obj):
                vmi_obj.del_interface_route_table(intf_route_table_obj)
        self._vnc_lib.virtual_machine_interface_update(vmi_obj)
Exemplo n.º 2
0
    def test_route_table_prefixes(self):
        """
        UT to verify CEM-22625.

        API server to allow applying two network routes (same prefix,
        different next-hops) to the same Virtual Network.
        """
        rt = RouteTable("rt1")
        routes = RouteTableType()
        route1 = RouteType(prefix="1.1.1.1/0",
                           next_hop="10.10.10.10",
                           next_hop_type="ip-address")
        route2 = RouteType(prefix="1.1.1.1/0",
                           next_hop="20.20.20.20",
                           next_hop_type="ip-address")
        routes.add_route(route1)
        routes.add_route(route2)
        rt.set_routes(routes)
        self._vnc_lib.route_table_create(rt)

        routes.delete_route(route2)
        route2 = RouteType(prefix="1.1.1.2/0",
                           next_hop="20.20.20.20",
                           next_hop_type="ip-address")
        routes.add_route(route2)
        rt.set_routes(routes)
        self._vnc_lib.route_table_update(rt)

        routes.delete_route(route1)
        routes.delete_route(route2)
Exemplo n.º 3
0
    def __init__(self, args_str=None):
        self._args = None
        if not args_str:
            args_str = ' '.join(sys.argv[1:])
        self._parse_args(args_str)

        self._vnc_lib = VncApi(
            self._args.user, self._args.password,
            self._args.tenant_name,
            self._args.api_server_ip,
            self._args.api_server_port, '/')
        
        prefix = self._args.prefix
        vmi_id_got = self._args.virtual_machine_interface_id
        route_table_name = self._args.route_table_name

        try:
            ip_nw = IPNetwork(prefix)
        except AddrFormatError:
            print 'Invalid ip address format'
            sys.exit(1)

        project_fq_name_str = 'default-domain:'+ self._args.tenant_name
        project_fq_name = project_fq_name_str.split(':')
        project_obj = self._vnc_lib.project_read(fq_name=project_fq_name)
        
        route_table = RouteTableType(route_table_name)
        route_table.set_route([])
        intf_route_table = InterfaceRouteTable(
                                interface_route_table_routes = route_table,
                                parent_obj=project_obj, 
                                name=route_table_name)
        try:
            route_table_obj = self._vnc_lib.interface_route_table_read(
                                    fq_name = intf_route_table.get_fq_name())
            intf_route_table_id = route_table_obj.uuid
        except NoIdError:
            if self._args.oper == 'del':
                print "Route table %s does not exist" %(route_table_name)
                sys.exit(1)
            print "Creating Route table"
            intf_route_table_id = self._vnc_lib.interface_route_table_create(
                                    intf_route_table)
        intf_route_table_obj = self._vnc_lib.interface_route_table_read(
                                    id = intf_route_table_id) 
        if self._args.oper == 'add':
            intf_route_table_obj = self.add_route(intf_route_table_obj, prefix)
        elif self._args.oper == 'del':
            intf_route_table_obj = self.del_route(intf_route_table_obj, prefix)
        self._vnc_lib.interface_route_table_update(intf_route_table_obj)
        
        #Update the VMI Object now
        vmi_obj = self._vnc_lib.virtual_machine_interface_read(id = vmi_id_got)
        if self._args.oper == 'add':
            vmi_obj.add_interface_route_table(intf_route_table_obj)
        elif self._args.oper == 'del':
            if self.is_route_table_empty(intf_route_table_obj):
                vmi_obj.del_interface_route_table(intf_route_table_obj)
        self._vnc_lib.virtual_machine_interface_update(vmi_obj)
Exemplo n.º 4
0
    def __init__(self, args_str=None):
        self._args = None
        if not args_str:
            args_str = ' '.join(sys.argv[1:])
        self._parse_args(args_str)

        self._vnc_lib = VncApi(self._args.admin_user,
                               self._args.admin_password,
                               self._args.admin_tenant_name,
                               self._args.api_server_ip,
                               self._args.api_server_port, '/')

        prefix = self._args.prefix
        nh = self._args.nh
        try:
            ip_nw = IPNetwork(prefix)
        except AddrFormatError:
            print 'Invalid ip address format'
            sys.exit(1)

        try:
            global_config = self._vnc_lib.global_vrouter_config_read(fq_name=[
                'default-global-system-config', 'default-global-vrouter-config'
            ])
        except Exception as e:
            print "Global vrouter config does not exist"
            sys.exit(1)

        if not global_config.get_global_static_routes():
            route_table = RouteTableType()
            route_table.set_route([])
            global_config.set_global_static_routes(route_table)

        if self._args.oper == 'add':
            global_config = self.add_route(global_config, prefix, nh)
        elif self._args.oper == 'del':
            global_config = self.del_route(global_config, prefix, nh)
        result = self._vnc_lib.global_vrouter_config_update(global_config)
        print 'Updated.%s' % (result)
Exemplo n.º 5
0
    def test_route_table_prefixes(self):
        rt = RouteTable("rt1")
        routes = RouteTableType()
        route1 = RouteType(prefix="1.1.1.1/0",
                           next_hop="10.10.10.10",
                           next_hop_type="ip-address")
        route2 = RouteType(prefix="1.1.1.1/0",
                           next_hop="20.20.20.20",
                           next_hop_type="ip-address")
        routes.add_route(route1)
        routes.add_route(route2)
        rt.set_routes(routes)
        try:
            self._vnc_lib.route_table_create(rt)
            self.fail("Create succeeded unexpectedly: duplicate prefixes "
                      "routes")
        except BadRequest:
            pass

        routes.delete_route(route2)
        route2 = RouteType(prefix="1.1.1.2/0",
                           next_hop="20.20.20.20",
                           next_hop_type="ip-address")
        routes.add_route(route2)
        rt.set_routes(routes)
        self._vnc_lib.route_table_create(rt)

        routes.delete_route(route2)
        route2 = RouteType(prefix="1.1.1.1/0",
                           next_hop="20.20.20.20",
                           next_hop_type="ip-address")
        routes.add_route(route2)
        rt.set_routes(routes)
        try:
            self._vnc_lib.route_table_update(rt)
            self.failt("Update succeeded unexpectedly - duplicate prefixe"
                       "routes")
        except BadRequest:
            pass
    def __init__(self, args_str=None):
        self._args = None
        if not args_str:
            args_str = ' '.join(sys.argv[1:])
        self._parse_args(args_str)

        self._vnc_lib = VncApi(
            self._args.user, self._args.password,
            self._args.tenant_name,
            self._args.api_server_ip,
            self._args.api_server_port, '/')
        
        prefix = self._args.prefix
        vm_id = self._args.virtual_machine_id
        vm_ip = self._args.virtual_machine_interface_ip
        vmi_id_got =None
        route_table_name = self._args.route_table_name
        
        project_fq_name_str = 'default-domain:'+ self._args.tenant_name
        project_fq_name = project_fq_name_str.split(':')
        project_obj = self._vnc_lib.project_read(fq_name=project_fq_name)
        
        route_table = RouteTableType(route_table_name)
        route_table.set_route([])
        intf_route_table = InterfaceRouteTable(
                                interface_route_table_routes = route_table,
                                parent_obj=project_obj, 
                                name=route_table_name)
        try:
            route_table_obj = self._vnc_lib.interface_route_table_read(
                                    fq_name = intf_route_table.get_fq_name())
            intf_route_table_id = route_table_obj.uuid
        except NoIdError:
            if self._args.oper == 'del':
                print "Route table %s does not exist" %(route_table_name)
                sys.exit(1)
            print "Creating Route table"
            intf_route_table_id = self._vnc_lib.interface_route_table_create(
                                    intf_route_table)
        intf_route_table_obj = self._vnc_lib.interface_route_table_read(
                                    id = intf_route_table_id) 
        if self._args.oper == 'add':
            intf_route_table_obj = self.add_route(intf_route_table_obj, prefix)
        elif self._args.oper == 'del':
            intf_route_table_obj = self.del_route(intf_route_table_obj, prefix)
        self._vnc_lib.interface_route_table_update(intf_route_table_obj)
        
        #Figure out VMI from VM IP
        vmi_list = self._vnc_lib.virtual_machine_interfaces_list( 
                        parent_id = vm_id)['virtual-machine-interfaces']
        vmi_id_list = [vmi['uuid'] for vmi in vmi_list]
        found = False
        for vmi_id in vmi_id_list:
            vmi_obj = self._vnc_lib.virtual_machine_interface_read(
                                id = vmi_id)
            ip_back_refs = vmi_obj.get_instance_ip_back_refs()
            for ip_back_ref in ip_back_refs:
                ip_obj = self._vnc_lib.instance_ip_read(
                                id = ip_back_ref['uuid'])
                if ip_obj.instance_ip_address == vm_ip:
                    found = True 
                    vmi_id_got = vmi_id
                    break
            if found:
                break
        #end for vmi_id
        if not found:
            print "No Virtual Machine interface found for IP %s" %(vm_ip)
            sys.exit(1)
        
        #Update the VMI Object now
        vmi_obj = self._vnc_lib.virtual_machine_interface_read(id = vmi_id_got)
        if self._args.oper == 'add':
            vmi_obj.set_interface_route_table(intf_route_table_obj)
        elif self._args.oper == 'del':
            if self.is_route_table_empty(intf_route_table_obj):
                vmi_obj.del_interface_route_table(intf_route_table_obj)
        self._vnc_lib.virtual_machine_interface_update(vmi_obj)
    def __init__(self, args_str=None):
        self._args = None
        if not args_str:
            args_str = ' '.join(sys.argv[1:])
        self._parse_args(args_str)

        self._vnc_lib = VncApi(self._args.user, self._args.password,
                               self._args.tenant_name,
                               self._args.api_server_ip,
                               self._args.api_server_port, '/')

        prefix = self._args.prefix
        vm_id = self._args.virtual_machine_id
        vm_ip = self._args.virtual_machine_interface_ip
        vmi_id_got = None
        route_table_name = self._args.route_table_name

        project_fq_name_str = 'default-domain:' + self._args.tenant_name
        project_fq_name = project_fq_name_str.split(':')
        project_obj = self._vnc_lib.project_read(fq_name=project_fq_name)

        route_table = RouteTableType(route_table_name)
        route_table.set_route([])
        intf_route_table = InterfaceRouteTable(
            interface_route_table_routes=route_table,
            parent_obj=project_obj,
            name=route_table_name)
        try:
            route_table_obj = self._vnc_lib.interface_route_table_read(
                fq_name=intf_route_table.get_fq_name())
            intf_route_table_id = route_table_obj.uuid
        except NoIdError:
            if self._args.oper == 'del':
                print "Route table %s does not exist" % (route_table_name)
                sys.exit(1)
            print "Creating Route table"
            intf_route_table_id = self._vnc_lib.interface_route_table_create(
                intf_route_table)
        intf_route_table_obj = self._vnc_lib.interface_route_table_read(
            id=intf_route_table_id)
        if self._args.oper == 'add':
            intf_route_table_obj = self.add_route(intf_route_table_obj, prefix)
        elif self._args.oper == 'del':
            intf_route_table_obj = self.del_route(intf_route_table_obj, prefix)
        self._vnc_lib.interface_route_table_update(intf_route_table_obj)

        #Figure out VMI from VM IP
        vmi_list = self._vnc_lib.virtual_machine_interfaces_list(
            parent_id=vm_id)['virtual-machine-interfaces']
        vmi_id_list = [vmi['uuid'] for vmi in vmi_list]
        found = False
        for vmi_id in vmi_id_list:
            vmi_obj = self._vnc_lib.virtual_machine_interface_read(id=vmi_id)
            ip_back_refs = vmi_obj.get_instance_ip_back_refs()
            for ip_back_ref in ip_back_refs:
                ip_obj = self._vnc_lib.instance_ip_read(id=ip_back_ref['uuid'])
                if ip_obj.instance_ip_address == vm_ip:
                    found = True
                    vmi_id_got = vmi_id
                    break
            if found:
                break
        #end for vmi_id
        if not found:
            print "No Virtual Machine interface found for IP %s" % (vm_ip)
            sys.exit(1)

        #Update the VMI Object now
        vmi_obj = self._vnc_lib.virtual_machine_interface_read(id=vmi_id_got)
        vmi_obj.set_interface_route_table(intf_route_table_obj)
        self._vnc_lib.virtual_machine_interface_update(vmi_obj)