Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
My Python Midonet Client scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomohiko KIMURA committed Apr 28, 2014
1 parent 68f27d0 commit b3c99ec
Show file tree
Hide file tree
Showing 21 changed files with 609 additions and 0 deletions.
24 changes: 24 additions & 0 deletions script/add-more-bridges.py
@@ -0,0 +1,24 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import sys

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()

if __name__ == '__main__':
main()
17 changes: 17 additions & 0 deletions script/add-tags.py
@@ -0,0 +1,17 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import sys

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()

if __name__ == '__main__':
main()
58 changes: 58 additions & 0 deletions script/add-vteps.py
@@ -0,0 +1,58 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import logging
import sys

logging.basicConfig(level=logging.DEBUG)

args = {
'base_uri': "http://127.0.0.1:8080/midonet-api",
'username': 'quantum',
'password': 'quantum',
'project_id': 'service',
}

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.'

#mgmt_ip = vtep_binding.get_management_ip()
#port_name = vtep_binding.get_port_name()
#vlan_id = vtep_binding.get_vlan_id()
#network_id = vtep_binding.get_network_id()
#print 'mgmt ip=%s, port name=%s, vlan id=%d, network id=%s' % (mgmt_ip, port_name, vlan_id, network_id)

# Add a new VTEP binding
#bindings = mc.get_bridge('SOME-BRIDGE-ID').get_vtep_bindings()


if __name__ == '__main__':
main()
23 changes: 23 additions & 0 deletions script/create-bridge.py
@@ -0,0 +1,23 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import logging
import sys

logging.basicConfig(level=logging.DEBUG)

args = {
'base_uri': "http://localhost:8080/midonet-api",
'username': 'quantum',
'password': 'quantum',
'project_id': 'service',
}

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

bridge = mc.add_bridge().name('DHCPv6BRIDGE').tenant_id(my_laptop).create()

if __name__ == '__main__':
main()
26 changes: 26 additions & 0 deletions script/delete-vteps.py
@@ -0,0 +1,26 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import logging
import sys

logging.basicConfig(level=logging.DEBUG)

args = {
'base_uri': "http://127.0.0.1:8080/midonet-api",
'username': 'quantum',
'password': 'quantum',
'project_id': 'service',
}

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.'


if __name__ == '__main__':
main()
31 changes: 31 additions & 0 deletions script/get-bridges.py
@@ -0,0 +1,31 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import logging
import sys
import time

logging.basicConfig(level=logging.DEBUG)

args = {
'base_uri': "http://127.0.0.1:8080/midonet-api",
'username': 'quantum',
'password': 'quantum',
'project_id': 'service',
}

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'})

if __name__ == '__main__':
main()
32 changes: 32 additions & 0 deletions script/get-tagged-resources.py
@@ -0,0 +1,32 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import sys

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

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

print '\n'

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')

if __name__ == '__main__':
main()
19 changes: 19 additions & 0 deletions script/get-tags.py
@@ -0,0 +1,19 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import sys

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())

if __name__ == '__main__':
main()
58 changes: 58 additions & 0 deletions script/get-vteps.py
@@ -0,0 +1,58 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import logging
import sys

logging.basicConfig(level=logging.DEBUG)

args = {
'base_uri': "http://127.0.0.1:8080/midonet-api",
'username': 'quantum',
'password': 'quantum',
'project_id': 'service',
}

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.'

#mgmt_ip = vtep_binding.get_management_ip()
#port_name = vtep_binding.get_port_name()
#vlan_id = vtep_binding.get_vlan_id()
#network_id = vtep_binding.get_network_id()
#print 'mgmt ip=%s, port name=%s, vlan id=%d, network id=%s' % (mgmt_ip, port_name, vlan_id, network_id)

# Add a new VTEP binding
#bindings = mc.get_bridge('SOME-BRIDGE-ID').get_vtep_bindings()


if __name__ == '__main__':
main()
33 changes: 33 additions & 0 deletions script/list-vteps.py
@@ -0,0 +1,33 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import logging
import sys

logging.basicConfig(level=logging.DEBUG)

args = {
'base_uri': "http://127.0.0.1:8080/midonet-api",
'username': 'quantum',
'password': 'quantum',
'project_id': 'service',
}

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)


if __name__ == '__main__':
main()
17 changes: 17 additions & 0 deletions script/remove-bridges.py
@@ -0,0 +1,17 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import sys

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()

if __name__ == '__main__':
main()
21 changes: 21 additions & 0 deletions script/remove-particular-tag.py
@@ -0,0 +1,21 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import sys

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]
for bridge in bridges:
print("Bridge %s" % bridge.get_id())
tags = bridge.get_tags()
for tag in tags:
print("Deleting tag: %s" % tag.get_tag())
tag.delete()

if __name__ == '__main__':
main()
20 changes: 20 additions & 0 deletions script/remove-tags.py
@@ -0,0 +1,20 @@
#!/usr/bin/env python

from midonetclient.api import MidonetApi
import sys

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("Deleting tag: %s" % tag.get_tag())
tag.delete()

if __name__ == '__main__':
main()

0 comments on commit b3c99ec

Please sign in to comment.