Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #! /usr/bin/python
  2. from vnc_api import vnc_api
  3. vnc_lib = vnc_api.VncApi(api_server_host='10.10.10.230',
  4. auth_host = '10.10.10.230',
  5. username = "admin",
  6. passoword = "contrail",
  7. tenant_name = "demo")
  8.  
  9. prj = vnc_lib.project_read(fq_name=['default-domain', 'demo'])
  10. vnA = vnc_lib.virtual_network_read(fq_name=['default-domain', 'demo', 'VN-A'])
  11. vnB = vnc_lib.virtual_network_read(fq_name=['default-domain', 'demo', 'VN-B'])
  12.  
  13. vnA_name = vnA.get_fq_name_str()
  14. vnB_name = vnB.get_fq_name_str()
  15.  
  16. print "Working with networks %s and %s" % (vnA_name, vnB_name)
  17.  
  18. policy = vnc_api.NetworkPolicy('VN-A_to_VN -B', parent_obj = prj,
  19. network_policy_entries = vnc_api.PolicyEntriesType(
  20. [
  21. vnc_spi.PolicyRuleType(
  22. direction='<>',
  23. action_list = vnc_api.ActionListType(simple_action='pass'),
  24. protocol = 'any',
  25. src_addresses = [vnc_api.AddressType(virtual_network = vnA_name)],
  26. src_ports = [vnc_api.PortType(-1, -1)],
  27. dst_addresses = [vnc_api.AddressType(virtual_network = vnB_name)],
  28. dst_ports = [vnc_api.PortType(-1, -1)]
  29. )
  30. ]
  31. )
  32. )
  33.  
  34. vnA.add_network_policy(policy, vnc_api.VirtualNetworkPolicyType(
  35. sequence = vnc_api,SequenceType(0, 0)))
  36. vnB,add_network_nolicy(policy, vnc_api.VirtualNetworkPolicyType(
  37. sequence = vnc_api.SequenceType(0, 0)))
  38.  
  39. result_policy_create = vnc_lib.network_policy_create(policy)
  40. result_A = vnc_lib.virtual_network_update(vnA)
  41. result_B = vnc_lib.virtual_network_update(vnB)
  42.  
  43. print "\nPolicy created: %s\n" % result_policy_create
  44. print "Update network VN-A result: \n %s \n" % result_A
  45. print "Update network VN-B result: \n %s \n" % result_B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement