예제 #1
0
def main():
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(**args)

    bridge = mc.add_bridge().name('DHCPv6BRIDGE').tenant_id(my_laptop).create()
    port_left = bridge.add_exterior_port().create()
    port_right = bridge.add_exterior_port().create()
def main():
    mc = MidonetApi(**args)
    vtep_management_ip = '119.15.112.22'

    # Delete a new VTEP
    vtep = mc.delete_vtep(vtep_management_ip)
    print 'Deleted a VTEP.'
def main():
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(**args)

    bridge = mc.add_bridge().name('DHCPv6BRIDGE').tenant_id(my_laptop).create()
    port_left = bridge.add_exterior_port().create()
    port_right = bridge.add_exterior_port().create()
def main():
    mc = MidonetApi(**args)
    vtep_management_ip = '119.15.112.22'

    # Delete a new VTEP
    vtep = mc.delete_vtep(vtep_management_ip)
    print 'Deleted a VTEP.'
def main():
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(**args)

    vtep_management_ip = '119.15.112.22'
    vtep_management_port = '6633'

    # Preparation
    bridge_name = 'DHCPv6BRIDGE NO2'
    bridge_exists = False
    bridges = mc.get_bridges({'tenant_id': my_laptop})
    for b in bridges: 
        if b.get_name() == bridge_name:
            bridge_exists = True
            bridge = b 

    if not bridge_exists: 
        bridge = mc.add_bridge().name(bridge_name).tenant_id(my_laptop).create()

    bridge_id = bridge.get_id()
    print 'Bridge ID for %s: %s' % (bridge_name, bridge_id)

    # Create a new VTEP
    vtep = mc.add_vtep().name('My VTEP').management_ip(vtep_management_ip).management_port(vtep_management_port).create()
    print 'Created a VTEP.'

    # Add a new VTEP binding.
    #vtep_binding = vtep.add_binding().port_name('in1').network_id(bridge_id).create()
    vtep_binding = vtep.add_binding().port_name('in1').vlan_id(124).network_id(bridge_id).create()
    print 'Added a new VTEP binding.'
예제 #6
0
def main():
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(**args)

    port_group = mc.add_port_group().name('tomohiko-port-group').tenant_id(
        my_laptop).create()
    port_group.add_port_group_port().port_id(
        '3e7c31c5-64d9-4184-a27a-3f985d83a71b').create()
예제 #7
0
def main():
    mn_uri = 'http://localhost:8081'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(mn_uri, 'admin', 'password')

    bridges = mc.get_bridges({'tenant_id': my_laptop})
    bridge = bridges[0]
    tag = bridge.add_tag().tag("tomohiko_tag1").create()
    tag = bridge.add_tag().tag("tomohiko_tag2").create()
예제 #8
0
def main():
    mn_uri = 'http://localhost:8081'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(mn_uri, 'admin', 'password')

    bridges = mc.get_bridges({'tenant_id': my_laptop})
    for bridge in bridges:
        print("Removing Bridge %s" % bridge.get_id())
        bridge.delete()
예제 #9
0
def main():
    mn_uri = 'http://localhost:8081'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(mn_uri, 'admin', 'password')

    bridges = mc.get_bridges({'tenant_id': my_laptop})
    bridge = bridges[0]
    tag = bridge.add_tag().tag("tomohiko_tag1").create()
    tag = bridge.add_tag().tag("tomohiko_tag2").create()
def main():
    mn_uri = 'http://localhost:8081'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(mn_uri, 'admin', 'password')

    bridges = mc.get_bridges({'tenant_id': my_laptop})
    for bridge in bridges:
      print("Removing Bridge %s" % bridge.get_id())
      bridge.delete()
def main():
    # mn_uri = 'http://localhost:8081'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    # mc = MidonetApi(mn_uri, 'admin', 'password')
    mc = MidonetApi(**args)

    tz1 = mc.add_tunnel_zone()
    tz1.name('tomohiko')
    tz1.type('gre')
    tz1.create()
def main():
    # mn_uri = 'http://localhost:8081'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    # mc = MidonetApi(mn_uri, 'admin', 'password')
    mc = MidonetApi(**args)

    hosts = mc.get_host_versions()
    for host in hosts:
        print('host: %s, host_id: %s, version: %s' % (host.get_host(),
                                                      host.get_host_id(),
                                                      host.get_version()))
예제 #13
0
def main():
    mn_uri = 'http://localhost:8081'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(mn_uri, 'admin', 'password')

    bridges = mc.get_bridges({'tenant_id': my_laptop})
    for bridge in bridges:
        print("Bridge %s" % bridge.get_id())
        tags = bridge.get_tags()
        for tag in tags:
            print("tag: %s" % tag.get_tag())
예제 #14
0
def main():
    mn_uri = 'http://localhost:8081'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(mn_uri, 'admin', 'password')

    bridges = mc.get_bridges({'tenant_id': my_laptop})
    for bridge in bridges:
      print("Bridge %s" % bridge.get_id())
      tags = bridge.get_tags()
      for tag in tags:
        print("tag: %s" % tag.get_tag())
def main():
    # mn_uri = 'http://localhost:8081'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    # mc = MidonetApi(mn_uri, 'admin', 'password')
    mc = MidonetApi(**args)

    mc.get_bridges({'tenant_id': 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'})

    print('Sleep for 2 secs.')
    time.sleep(3)
    #mc.get_bridges({'tenant_id': my_laptop})
    mc.get_port_groups({'tenant_id': 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'})
예제 #16
0
def main():
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(**args)

    vtep_management_ip = '119.15.112.22'
    vtep_management_port = '6633'

    # Create a new VTEP
    # vtep = mc.add_vtep().name('My VTEP').management_ip(vtep_management_ip).management_port(vtep_management_port).create()
    # print 'Created a VTEP.'

    # list VTEPs
    vteps = mc.get_vteps()
    print 'Retrieved a list of %d VTEPs.' % len(vteps)
def main():
    mn_uri = 'http://localhost:8081'
    mc = MidonetApi(mn_uri, 'admin', 'password')

    lookup_tagged_resources(mc, 'tomohiko_tag1')
    lookup_tagged_resources(mc, 'tomohiko_tag2')
    lookup_tagged_resources(mc, 'tomohiko_tag3')
예제 #18
0
def main():
    mn_uri = 'http://localhost:8081'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(mn_uri, 'admin', 'password')

    bridge = mc.add_bridge().name('DHCPv6BRIDGE NO2').tenant_id(my_laptop).create()
    port_left = bridge.add_exterior_port().create()
    port_right = bridge.add_exterior_port().create()
    tag = bridge.add_tag().tag("tomohiko_tag1").create()
    tag = bridge.add_tag().tag("tomohiko_tag3").create()

    bridge = mc.add_bridge().name('DHCPv6BRIDGE NO3').tenant_id(my_laptop).create()
    port_left = bridge.add_exterior_port().create()
    port_right = bridge.add_exterior_port().create()
    tag = bridge.add_tag().tag("tomohiko_tag1").create()
    tag = bridge.add_tag().tag("tomohiko_tag2").create()
def main():
    mn_uri = 'http://localhost:8080/midonet-api'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(mn_uri, 'admin', 'password')

    bridge = mc.add_bridge().name('DHCPv6BRIDGE').tenant_id(my_laptop).create()
    port_left = bridge.add_exterior_port().create()
    port_right = bridge.add_exterior_port().create()
    tag = bridge.add_tag().tag("tomohiko_tag1").create()
    tag = bridge.add_tag().tag("tomohiko_tag2").create()

    ## Test deleting a bridge.
    bridge_delete = mc.add_bridge().name('BRIDGE_DELETE_TEST').tenant_id(my_laptop).create()
    tag = bridge_delete.add_tag().tag("bridge_delete_tag1").create()
    tag = bridge_delete.add_tag().tag("bridge_delete_tag2").create()
    bridge_delete.delete()

    tags = bridge.get_tags()
    for tag in tags:
      print("%s\n", tag.get_tag())
예제 #20
0
def main():
    mn_uri = 'http://localhost:8080/midonet-api'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(mn_uri, 'admin', 'password')

    bridge = mc.add_bridge().name('DHCPv6BRIDGE').tenant_id(my_laptop).create()
    port_left = bridge.add_exterior_port().create()
    port_right = bridge.add_exterior_port().create()
    tag = bridge.add_tag().tag("tomohiko_tag1").create()
    tag = bridge.add_tag().tag("tomohiko_tag2").create()

    ## Test deleting a bridge.
    bridge_delete = mc.add_bridge().name('BRIDGE_DELETE_TEST').tenant_id(
        my_laptop).create()
    tag = bridge_delete.add_tag().tag("bridge_delete_tag1").create()
    tag = bridge_delete.add_tag().tag("bridge_delete_tag2").create()
    bridge_delete.delete()

    tags = bridge.get_tags()
    for tag in tags:
        print("%s\n", tag.get_tag())
예제 #21
0
 def get_midonet_api(self, timeout=120):
     # FIXME: Make sure the API is able to get topology information from ZK
     # ROOT CAUSE: the api does not retry when connected to a ZK instance
     # which just failed
     # WORKAROUND: retry in here, should be FIXED in python-midonetclient?
     wait_time = 1
     while True:
         if timeout == 0:
             raise RuntimeError("Timeout waiting for midonet_api")
         try:
             api = MidonetApi(
                 "http://%s:%d/midonet-api" %
                 (self.get_ip_address(), self.port), self.username,
                 self.password)
             # We need to actually ask something to the api to make sure
             # that the compat api is actually talking to the NSDB
             api.get_hosts()
             return api
         except:
             time.sleep(wait_time)
             timeout -= wait_time
예제 #22
0
 def get_midonet_api(self, timeout=120):
     # FIXME: Make sure the API is able to get topology information from ZK
     # ROOT CAUSE: the api does not retry when connected to a ZK instance
     # which just failed
     # WORKAROUND: retry in here, should be FIXED in python-midonetclient?
     wait_time = 1
     while True:
         if timeout == 0:
             raise RuntimeError("Timeout waiting for midonet_api")
         try:
             api = MidonetApi(
                 "http://%s:%d/midonet-api" % (self.get_ip_address(),
                                               self.port),
                 self.username,
                 self.password)
             # We need to actually ask something to the api to make sure
             # that the compat api is actually talking to the NSDB
             api.get_hosts()
             return api
         except:
             time.sleep(wait_time)
             timeout -= wait_time
def main():
    # mn_uri = 'http://localhost:8081'
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    # mc = MidonetApi(mn_uri, 'admin', 'password')
    mc = MidonetApi(**args)

    chain = mc.add_chain().name('tomohiko_11th_chain').tenant_id(my_laptop).create()
    print('*** 5th chain id: ' + chain.get_id())
    rule = chain.add_rule()
    rule.type('snat')
    rule.flow_action('accept')
    rule.nw_src_address('172.16.1.1')
    rule.nw_src_length(24)
    rule.nw_dst_address('172.16.1.2')
    rule.nw_dst_length(24)
    rule.out_ports(['3e7c31c5-64d9-4184-a27a-3f985d83a71b'])
    rule.nat_targets([{'addressFrom': '200.11.11.11',
                       'addressTo': '200.11.11.12',
                       'portFrom': 8888,
                       'portTo': 9999}])
    rule.create()
    print('*** rule id: ' + rule.get_id())
예제 #24
0
    def get_midonet_api(self):
        # FIXME: Make sure the API is able to get topology information from ZK
        # ROOT CAUSE: the api does not retry when connected to a ZK instance
        # which just failed
        # WORKAROUND: retry in here, should be FIXED in python-midonetclient
        timeout = 60
        wait_time = 1
        while True:
            if timeout == 0:
                raise RuntimeError("Timeout waiting for midonet_api")
            try:
                api = MidonetApi(
                    "http://%s:8080/midonet-api" % self.get_ip_address(),
                    self.username,
                    self.password)
                api.get_hosts()
            except:
                time.sleep(wait_time)
                timeout -= wait_time
            else:
                break

        return api
예제 #25
0
    def __init__(self, run_method='runTest'):
        upgrade_underlay_base.UpgradeUnderlayBase.__init__(self)
        self.migrate_provider_router = True
        self.migrate_anti_spoof = True
        self.migrate_extra_routes = True

        lbaas_test_utils.LBaaSTestCase.__init__(self, run_method)

        self.vm_lbaas_member_pool_a_b = None
        """ :type: zephyr.tsm.neutron_test_data.GuestData """
        self.vm_lbaas_member_pool_a = None
        """ :type: zephyr.tsm.neutron_test_data.GuestData """
        self.vm_lbaas_pinger = None
        """ :type: zephyr.tsm.neutron_test_data.GuestData """
        self.vm_mn_lbaas_member_pool_mn_neutron_c = None
        """ :type: zephyr.tsm.neutron_test_data.GuestData """
        self.vm_mn_lbaas_member_pool_mn = None
        """ :type: zephyr.tsm.neutron_test_data.GuestData """

        self.vm_main_net_with_fip = None
        """ :type: zephyr.vtm.guest.Guest """
        self.vm_main_net_private = None
        """ :type: zephyr.vtm.guest.Guest """
        self.vm_new1_net_with_fip = None
        """ :type: zephyr.vtm.guest.Guest """
        self.vm_new1_net_private = None
        """ :type: zephyr.vtm.guest.Guest """
        self.vm_new2_net_with_fip = None
        """ :type: zephyr.vtm.guest.Guest """
        self.vm_new2_net_private = None
        """ :type: zephyr.vtm.guest.Guest """

        self.neutron_lbaas_vip_a = None
        self.neutron_lbaas_vip_b = None
        self.midonet_lbaas_vip = None

        self.neutron_bridge_to_modify = None
        self.neutron_router_to_modify = None
        self.neutron_port_to_modify = None
        self.neutron_sg_to_modify = None

        self.mn_uri = vc.ConfigMap.get_configured_parameter(
            'param_midonet_api_url')
        self.mn_api = MidonetApi(self.mn_uri, 'admin', 'cat', 'admin')
        """ :type: midonetclient.api.MidonetApi """

        self.ports_to_start = []
예제 #26
0
def main():
    global provider_tenant_id
    global mido_api

    base_parser = argparse.ArgumentParser()
    base_parser.add_argument('midonet_uri', help='Midonet API URI',
            type=str, default='http://localhost:8080/midonet-api')
    base_parser.add_argument('username', help='Midonet admin username',
                             type=str)
    base_parser.add_argument('password', help='Midonet admin password',
                             type=str)
    base_parser.add_argument('provider_tenant_id',
                             help='tenant_id of the provider',
                             type=str)

    subparsers = base_parser.add_subparsers(help='sub-command help')

    # parser for setup_provider_devices subcommand
    parser_pv_devices = subparsers.add_parser('provider_devices',
                                              help='set up provider devices')
    parser_pv_devices.set_defaults(func=setup_provider_devices)

    parser_fake_uplink = subparsers.add_parser('fake_uplink',
                                              help='set up fake uplink')
    parser_fake_uplink.set_defaults(func=setup_fake_uplink)


    args = base_parser.parse_args()

    midonet_uri = args.midonet_uri
    username = args.username
    password = args.password
    provider_tenant_id = args.provider_tenant_id

    mido_api = MidonetApi(midonet_uri, username, password, provider_tenant_id)

    args.func(args)
예제 #27
0
    if not all(tenants):
        print "not all tenants are found"
        sys.exit(1)
    tenantIds = map(lambda tenant: tenant.id, tenants)

    hosts = [
        '00000000-0000-0000-0000-000000000001',
        '00000000-0000-0000-0000-000000000002',
        '00000000-0000-0000-0000-000000000003'
    ]
    addresses = ['10.0.0.8', '10.0.0.9', '10.0.0.10']
    if not all(hosts):
        print "host uuid file(s) is not found"
        sys.exit(1)

    api = MidonetApi('http://127.0.0.1:8080/midonet-api', 'admin', '*')
    tx = Transaction()
    try:
        zone = TunnelZone({'name': 'zone0', 'type': 'gre'})
        zone.add(
            api, tx,
            map(lambda h, a: TunnelZoneHost({
                'hostId': h,
                'ipAddress': a
            }), hosts, addresses))
        bridge = Bridge({'name': 'bridge0', 'tenantId': tenantIds[0]})
        bridge.add(
            api, tx,
            map(lambda h: HostInterface({
                'hostId': h,
                'name': 'veth0'
예제 #28
0
 def __init__(self, filename=None, data=None, midonet_api=None):
     self._data = self._get_data(filename, data)
     if not midonet_api:
         midonet_api = MidonetApi(
             'http://127.0.0.1:8080/midonet-api','admin','*')
     self._api = midonet_api
예제 #29
0
def get_midonet_api():
    return MidonetApi(MIDONET_API_URL, 'admin', '*')
예제 #30
0
class UnderlayStandardPTM(upgrade_underlay_base.UpgradeUnderlayBase,
                          lbaas_test_utils.LBaaSTestCase):
    def __init__(self, run_method='runTest'):
        upgrade_underlay_base.UpgradeUnderlayBase.__init__(self)
        self.migrate_provider_router = True
        self.migrate_anti_spoof = True
        self.migrate_extra_routes = True

        lbaas_test_utils.LBaaSTestCase.__init__(self, run_method)

        self.vm_lbaas_member_pool_a_b = None
        """ :type: zephyr.tsm.neutron_test_data.GuestData """
        self.vm_lbaas_member_pool_a = None
        """ :type: zephyr.tsm.neutron_test_data.GuestData """
        self.vm_lbaas_pinger = None
        """ :type: zephyr.tsm.neutron_test_data.GuestData """
        self.vm_mn_lbaas_member_pool_mn_neutron_c = None
        """ :type: zephyr.tsm.neutron_test_data.GuestData """
        self.vm_mn_lbaas_member_pool_mn = None
        """ :type: zephyr.tsm.neutron_test_data.GuestData """

        self.vm_main_net_with_fip = None
        """ :type: zephyr.vtm.guest.Guest """
        self.vm_main_net_private = None
        """ :type: zephyr.vtm.guest.Guest """
        self.vm_new1_net_with_fip = None
        """ :type: zephyr.vtm.guest.Guest """
        self.vm_new1_net_private = None
        """ :type: zephyr.vtm.guest.Guest """
        self.vm_new2_net_with_fip = None
        """ :type: zephyr.vtm.guest.Guest """
        self.vm_new2_net_private = None
        """ :type: zephyr.vtm.guest.Guest """

        self.neutron_lbaas_vip_a = None
        self.neutron_lbaas_vip_b = None
        self.midonet_lbaas_vip = None

        self.neutron_bridge_to_modify = None
        self.neutron_router_to_modify = None
        self.neutron_port_to_modify = None
        self.neutron_sg_to_modify = None

        self.mn_uri = vc.ConfigMap.get_configured_parameter(
            'param_midonet_api_url')
        self.mn_api = MidonetApi(self.mn_uri, 'admin', 'cat', 'admin')
        """ :type: midonetclient.api.MidonetApi """

        self.ports_to_start = []

    def do_topo_prep(self):
        self.setup_basic_neutron_topology()
        self.setup_neutron_lbaas()
        self.setup_midonet_topology()
        self.setup_midonet_lbaas()
        self.setup_edge_rotuer_and_bgp()

    def do_migration(self, upgrader):
        upgrader.migrate()
        upgrader.provider_router_to_edge_router()
        upgrader.midonet_antispoof_to_allowed_address_pairs()
        upgrader.midonet_routes_to_extra_routes()

    def start_vms(self):
        pass

    def do_communication_test_pre(self):
        repliesa = self.send_packets_to_vip(
            member_list=[self.vm_lbaas_member_pool_a,
                         self.vm_lbaas_member_pool_a_b],
            pinger=self.vm_lbaas_pinger,
            vip=self.neutron_lbaas_vip_a,
            num_packets=PACKETS_TO_SEND)
        self.check_host_replies_against_rr_baseline(
            member_list=[self.vm_lbaas_member_pool_a,
                         self.vm_lbaas_member_pool_a_b],
            host_replies=repliesa,
            total_expected=PACKETS_TO_SEND,
            identifier="poolA")

        repliesb = self.send_packets_to_vip(
            member_list=[self.vm_lbaas_member_pool_a_b],
            pinger=self.vm_lbaas_pinger,
            vip=self.neutron_lbaas_vip_b,
            num_packets=PACKETS_TO_SEND)
        self.check_host_replies_against_rr_baseline(
            member_list=[self.vm_lbaas_member_pool_a_b],
            host_replies=repliesb,
            total_expected=PACKETS_TO_SEND,
            identifier="poolB")

        self.assertTrue(
            self.vm_new1_net_with_fip.verify_connection_to_host(
                far_host=self.vm_new2_net_with_fip))
        self.assertTrue(
            self.vm_new1_net_private.verify_connection_to_host(
                far_host=self.vm_new2_net_private))
        self.assertFalse(
            self.vm_main_net_private.verify_connection_to_host(
                far_host=self.vm_new2_net_private))

    def do_communication_test_post(self):
        self.do_communication_test_pre()

    def do_topo_verify_post(self):
        self.check_neutron_topology()
        self.check_midonet_topology()
        self.check_neutron_lbaas()
        self.check_midonet_lbaas()
        self.check_bgp()
        self.check_neutron_vm_communication()
        self.check_midonet_vm_communication()

    def setup_basic_neutron_topology(self):
        self.neutron_sg_to_modify = self.create_security_group(
            name='test_sg')

        self.create_port('sg_port_test',
                         self.main_network['id'],
                         sg_ids=[self.neutron_sg_to_modify['id']])

        net1 = self.create_network(name='new1_net')
        sub1 = self.create_subnet(name='new1_sub', net_id=net1['id'],
                                  cidr='10.100.100.0/24')

        self.neutron_bridge_to_modify = self.create_network(
            name='new2_net')
        sub2 = self.create_subnet(
            name='new2_sub',
            net_id=self.neutron_bridge_to_modify['id'],
            cidr='10.100.101.0/24')

        self.neutron_router_to_modify = self.create_router(
            name='new1_new2_router',
            pub_net_id=self.pub_network['id'],
            priv_sub_ids=[sub1['id'], sub2['id']])

        port1, self.vm_main_net_with_fip, _ = self.create_vm_server(
            'vm_main1', net_id=self.main_network['id'])

        _, self.vm_main_net_private, _ = self.create_vm_server(
            'vm_main2', net_id=self.main_network['id'])

        port3, self.vm_new1_net_with_fip, _ = self.create_vm_server(
            'vm_new1a', net_id=net1['id'])

        _, self.vm_new1_net_private, _ = self.create_vm_server(
            'vm_new1b', net_id=net1['id'])

        port5, self.vm_new2_net_with_fip, _ = self.create_vm_server(
            'vm_new2a', net_id=self.neutron_bridge_to_modify['id'])

        self.neutron_port_to_modify, self.vm_new2_net_private, _ = (
            self.create_vm_server(
                'vm_new2b', net_id=self.neutron_bridge_to_modify['id']))

        self.create_floating_ip(self.pub_network['id'], port_id=port1['id'])
        self.create_floating_ip(self.pub_network['id'], port_id=port3['id'])
        self.create_floating_ip(self.pub_network['id'], port_id=port5['id'])

    def setup_midonet_topology(self):
        # Create a new MidoNet bridge to upgrade
        new_br = (self.mn_api.add_bridge()
                  .tenant_id('admin')
                  .name('mn_br_test')
                  .disable_anti_spoof(True)
                  .create())
        """ :type: midonetclient.bridge.Bridge"""

        # Create a new MidoNet DHCP to upgrade
        (new_br.add_dhcp_subnet()
         .default_gateway('10.200.200.1')
         .subnet_prefix('10.200.200.0')
         .subnet_length(24)
         .enabled(True)
         .create())
        """ :type: midonetclient.dhcp_subnet.DhcpSubnet"""

        # Create a new MidoNet bridge port to upgrade
        br_port = (new_br.add_port()
                   .create())
        """ :type: midonetclient.port.Port"""

        new_br.disable_anti_spoof(True)

        # Create a new MidoNet router to upgrade
        new_rtr = (self.mn_api.add_router()
                   .name('mn_rtr_test')
                   .tenant_id('admin')
                   .create())
        """ :type: midonetclient.router.Router"""

        # Create a new MidoNet router port to upgrade (and link to bridge)
        rtr_port = (new_rtr.add_port()
                    .port_address('10.200.200.1')
                    .network_address('10.200.200.0')
                    .network_length(24)
                    .port_mac("AA:BB:CC:DD:EE:FF")
                    .create())
        """ :type: midonetclient.port.Port"""

        br_port.link(rtr_port.get_id())

        # Create MidoNet port groups to upgrade
        pg = (self.mn_api.add_port_group()
              .tenant_id('admin')
              .name('pg-test')
              .stateful(True)
              .create())
        """ :type: midonetclient.port_group.PortGroup"""

        (pg.add_port_group_port()
         .port_id(br_port.get_id())
         .create())

        # Create MidoNet chains to upgrade
        new_chain_obj = (self.mn_api.add_chain()
                         .tenant_id('admin')
                         .name("test_chain")
                         .create())
        """ :type: midonetclient.chain.Chain"""

        new_chain2_obj = (self.mn_api.add_chain()
                          .tenant_id('admin')
                          .name("test2_chain")
                          .create())
        """ :type: midonetclient.chain.Chain"""

        new_chain2_obj.add_rule().type("accept").create()
        new_chain_obj.add_rule().type("accept").create()
        new_chain_obj.add_rule().type("jump").create()

    def setup_neutron_lbaas(self):
        if 'lbaas' not in self.api_extension_map:
            return

        self.create_member_net(name='main')
        self.create_lbaas_net(name='main')
        self.create_pinger_net(name='main')
        self.create_lb_router(name='main',
                              gw_net_id=self.pub_network['id'])

        self.create_lbaas_net(name='main2',
                              cidr='192.168.122.0/24')
        self.create_lb_router(name='main2',
                              gw_net_id=self.pub_network['id'])

        poola = self.create_pool(
            subnet_id=self.topos['main']['lbaas']['subnet']['id'])
        poolb = self.create_pool(
            subnet_id=self.topos['main2']['lbaas']['subnet']['id'])

        self.neutron_lbaas_vip_a = self.create_vip(
            subnet_id=self.pub_subnet['id'],
            protocol_port=lbaas_test_utils.DEFAULT_POOL_PORT,
            name='poola-vip1',
            pool_id=poola['id'])['address']

        self.neutron_lbaas_vip_b = self.create_vip(
            subnet_id=self.pub_subnet['id'],
            protocol_port=lbaas_test_utils.DEFAULT_POOL_PORT + 1,
            name='poolb-vip1',
            pool_id=poolb['id'])['address']

        vms = self.create_member_vms(num_members=2)
        self.vm_lbaas_member_pool_a = vms[0]
        self.vm_lbaas_member_pool_a_b = vms[1]

        self.vm_lbaas_pinger = self.create_pinger_vm()

        self.create_member(pool_id=poola['id'],
                           ip_addr=self.vm_lbaas_member_pool_a.ip)
        self.create_member(pool_id=poola['id'],
                           ip_addr=self.vm_lbaas_member_pool_a_b.ip)

        self.create_member(pool_id=poolb['id'],
                           ip_addr=self.vm_lbaas_member_pool_a_b.ip)

        self.create_health_monitor()

        hm1 = self.create_health_monitor()
        self.associate_health_monitor(hm1['id'], poola['id'])

        hm2 = self.create_health_monitor()
        self.associate_health_monitor(hm2['id'], poolb['id'])

        self.create_floating_ip(
            pub_net_id=self.pub_network['id'],
            port_id=self.vm_lbaas_pinger.port['id'])

    def setup_midonet_lbaas(self):

        lbaas_rtr = (self.mn_api
                     .add_router()
                     .name('mn_lbaas_test')
                     .tenant_id('admin')
                     .create())
        """ :type: midonetclient.router.Router"""

        lb_obj = (self.mn_api.add_load_balancer()
                  .create())
        """ :type: midonetclient.load_balancer.LoadBalancer"""

        lbaas_rtr.load_balancer_id(lb_obj.get_id()).update()

        pool_obj = (lb_obj.add_pool()
                    .lb_method("ROUND_ROBIN")
                    .protocol("TCP")
                    .create())
        """ :type: midonetclient.pool.Pool"""

        vms = self.create_member_vms(num_members=2)
        self.vm_mn_lbaas_member_pool_mn = vms[0]
        self.vm_mn_lbaas_member_pool_mn_neutron_c = vms[1]

        (pool_obj.add_pool_member()
         .address(self.vm_mn_lbaas_member_pool_mn.ip)
         .protocol_port(5081)
         .create())
        (pool_obj.add_pool_member()
         .address(self.vm_mn_lbaas_member_pool_mn_neutron_c.ip)
         .protocol_port(5081)
         .create())
        (pool_obj.add_vip()
         .address("200.200.0.59")
         .protocol_port(5081)
         .create())
        self.midonet_lbaas_vip = "200.200.0.59"

    def setup_edge_rotuer_and_bgp(self):
        rtrs = self.mn_api.get_routers(query=None)
        pr = next(r
                  for r in rtrs
                  if r.get_name() == "MidoNet Provider Router")
        """ :type: midonetclient.router.Router """
        rport = (pr.add_port()
                 .port_address('172.16.2.2')
                 .network_address('172.16.2.0')
                 .network_length(24)
                 .create())
        """ :type: midonetclient.port.Port """

        hosts = self.mn_api.get_hosts()
        edge_host = next(h
                         for h in hosts
                         if h.get_name() == "edge1")
        """ :type: midonetclient.host.Host """

        self.mn_api.add_host_interface_port(edge_host, rport.get_id(), 'eth1')

        (pr.add_route()
         .type('normal')
         .weight(100)
         .next_hop_gateway('172.16.2.1')
         .next_hop_port(rport.get_id())
         .dst_network_addr('0.0.0.0')
         .dst_network_length(0)
         .src_network_addr('0.0.0.0')
         .src_network_length(0)
         .create())

        pr_bgp = (rport.add_bgp()
                  .peer_addr('172.16.2.1')
                  .peer_as('54321')
                  .local_as('12345')
                  .create())

        (pr_bgp.add_ad_route()
         .nw_prefix('200.200.0.0')
         .nw_prefix_length(24)
         .create())

        rtr_bgp_port1 = (pr.add_port()
                         .port_address('10.200.200.5')
                         .network_address('10.200.200.0')
                         .network_length(24)
                         .port_mac("BB:CC:DD:EE:FF:00")
                         .create())
        """ :type: midonetclient.port.Port"""

        rtr_bgp_port2 = (pr.add_port()
                         .port_address('10.200.200.6')
                         .network_address('10.200.200.0')
                         .network_length(24)
                         .port_mac("CC:DD:EE:FF:00:11")
                         .create())
        """ :type: midonetclient.port.Port"""

        tr_bgp1 = (rtr_bgp_port1.add_bgp()
                   .peer_addr('172.16.2.1')
                   .peer_as('23456')
                   .local_as('65432')
                   .create())
        (tr_bgp1.add_ad_route()
         .nw_prefix('10.200.200.0')
         .nw_prefix_length(24)
         .create())

        tr_bgp2 = (rtr_bgp_port1.add_bgp()
                   .peer_addr('172.16.3.1')
                   .peer_as('34567')
                   .local_as('76543')
                   .create())
        (tr_bgp2.add_ad_route()
         .nw_prefix('10.200.201.0')
         .nw_prefix_length(24)
         .create())

        tr_bgp3 = (rtr_bgp_port2.add_bgp()
                   .peer_addr('172.16.3.1')
                   .peer_as('34567')
                   .local_as('76543')
                   .create())
        (tr_bgp3.add_ad_route()
         .nw_prefix('10.200.201.0')
         .nw_prefix_length(24)
         .create())

    def modify_neutron_topology_with_midonet(self):
        # Create a Midonet bridge port on a Neutron network
        bridges = self.mn_api.get_bridges(query=None)
        neutron_br = next(b
                          for b in bridges
                          if b.get_name() == "new2_net")
        """ :type: midonetclient.bridge.Bridge"""

        if neutron_br:
            (neutron_br.add_port()
             .create())
            neutron_br.disable_anti_spoof(True).update()

        # Create a MidoNet router port on a Neutron router
        tr = next(r
                  for r in self.mn_api.get_routers(query=None)
                  if r.get_name() == "new1_new2_router")
        """ :type: midonetclient.router.Router"""

        (tr.add_port()
         .port_address('10.155.155.5')
         .network_address('10.155.155.0')
         .network_length(24)
         .port_mac("00:11:22:AA:BB:CC")
         .create())

        # Modify a Neutron network with MidoNet API
        # Modify a Neutron router with MidoNet API
        # Modify a Neutron port with MidoNet API
        # Modify a Neutron SG (chains) with MidoNet API

        # Modify a Netron LBAAS with MidoNet API
        neutron_lb_rtr_id = self.topos['main']['router']['id']
        neutron_lb_rtr = self.mn_api.get_router(neutron_lb_rtr_id)
        neutron_lb = self.mn_api.get_load_balancer(
            neutron_lb_rtr.get_load_balancer_id())
        neutron_c_pool = (neutron_lb
                          .add_pool()
                          .lb_method("ROUND_ROBIN")
                          .protocol("TCP")
                          .create())
        """ :type: midonetclient.pool.Pool"""

        (neutron_c_pool.add_pool_member()
         .address(self.vm_mn_lbaas_member_pool_mn_neutron_c.ip)
         .protocol_port(5082)
         .create())
        (neutron_c_pool.add_vip()
         .address("200.200.0.61")
         .protocol_port(5082)
         .create())

    def check_neutron_topology(self):
        pass

    def check_midonet_topology(self):
        pass

    def check_bgp(self):
        pass

    def check_midonet_vm_communication(self):
        pass

    def check_neutron_vm_communication(self):
        pass

    def check_neutron_lbaas(self):
        pass

    def check_midonet_lbaas(self):
        pass
예제 #31
0
            try:
                bridge = api.get_bridge(device_id)
                if bridge:
                    delete_bridge(api,tx,bridge,peer.get_peer_id())
            except webob.exc.HTTPNotFound:
                router = api.get_router(device_id)
                if router:
                    delete_router(api,tx,router,peer.get_peer_id())

def delete_chain(api,tx,chain):
    tx.append(DeleteChain(api,chain))

if __name__ == '__main__':
    tenantIds = map(lambda tenant: tenant.id, list_tenants())

    api = MidonetApi('http://127.0.0.1:8080/midonet-api','admin','*')

    for tenantId in tenantIds:
        # router and its children (routers and bridges)
        tx = Transaction()
        for router in api.get_routers({'tenant_id': tenantId}):
            delete_router(api,tx,router)
        tx.rollback() # commit actually

        # dangling bridge
        tx = Transaction()
        for bridge in api.get_bridges({'tenant_id': tenantId}):
            delete_bridge(api,tx,bridge)
        tx.rollback()

        tx = Transaction()
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import sys

_MN_URI = 'http://localhost:8081'
_MC = MidonetApi(_MN_URI, 'admin', 'password')


def lookup_tagged_bridges(tag):
    print 'Looking up bridges with tag: %s' % tag
    bridges = _MC.get_tagged_resources(tag)
    if bridges:
        print '-Found %d resources.' % len(bridges)
    else:
        print '-No resources found.\n'
        return

    for bridge in bridges:
        print('-Bridge')
        print('    Name: %s' % bridge.get_name())
        print('    id: %s' % bridge.get_id())
        print('    tenant id: %s' % bridge.get_tenant_id())

    print '\n'
def main():
    my_laptop = 'c1b9eb8a-c83b-43d3-b7b8-8613f921dbe7'
    mc = MidonetApi(**args)

    port_group = mc.add_port_group().name('tomohiko-port-group').tenant_id(my_laptop).create()
    port_group.add_port_group_port().port_id('3e7c31c5-64d9-4184-a27a-3f985d83a71b').create()
예제 #34
0
 def connect(self):
     auth = None
     return MidonetApi(self.api_url, self.username, self.password,
                       self.project_id)
예제 #35
0
파일: api.py 프로젝트: ruo91/midonet
# Copyright 2014 Midokura SARL
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from midonetclient.api import MidonetApi
import sys
import pdb

if __name__ == '__main__':
    api = MidonetApi("http://127.0.0.1:8080/midonet-api","admin","*")
    pdb.set_trace()
예제 #36
0
                if bridge:
                    delete_bridge(api, tx, bridge, peer.get_peer_id())
            except webob.exc.HTTPNotFound:
                router = api.get_router(device_id)
                if router:
                    delete_router(api, tx, router, peer.get_peer_id())


def delete_chain(api, tx, chain):
    tx.append(DeleteChain(api, chain))


if __name__ == '__main__':
    tenantIds = map(lambda tenant: tenant.id, list_tenants())

    api = MidonetApi('http://127.0.0.1:8080/midonet-api', 'admin', '*')

    for tenantId in tenantIds:
        # router and its children (routers and bridges)
        tx = Transaction()
        for router in api.get_routers({'tenant_id': tenantId}):
            delete_router(api, tx, router)
        tx.rollback()  # commit actually

        # dangling bridge
        tx = Transaction()
        for bridge in api.get_bridges({'tenant_id': tenantId}):
            delete_bridge(api, tx, bridge)
        tx.rollback()

        tx = Transaction()