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.'
Ejemplo n.º 2
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():
    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')
Ejemplo n.º 4
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()
Ejemplo n.º 5
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()
Ejemplo n.º 6
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')
    mc = MidonetApi(**args)

    tz1 = mc.add_tunnel_zone()
    tz1.name('tomohiko')
    tz1.type('gre')
    tz1.create()
Ejemplo n.º 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("Bridge %s" % bridge.get_id())
        tags = bridge.get_tags()
        for tag in tags:
            print("tag: %s" % tag.get_tag())
Ejemplo n.º 9
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)
Ejemplo n.º 10
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()
Ejemplo n.º 11
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())
Ejemplo n.º 12
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
Ejemplo n.º 13
0
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())
Ejemplo n.º 14
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)
Ejemplo n.º 15
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'
Ejemplo n.º 16
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
Ejemplo n.º 17
0
def get_midonet_api():
    return MidonetApi(MIDONET_API_URL, 'admin', '*')
#!/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'
Ejemplo n.º 19
0
 def connect(self):
     auth = None
     return MidonetApi(self.api_url, self.username, self.password,
                       self.project_id)
Ejemplo n.º 20
0
Archivo: api.py Proyecto: 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()