Use vnc_api to create VPGs - ganeshahv/Contrail_SRE GitHub Wiki
1]. Login to the config_api docker on the controller
[root@r2ru5 contrail]# docker exec -it config_api_1 bash
2]. Invoke the Python Interpreter
(config-api)[root@r2ru5 /usr/lib/python2.7/site-packages/vnc_api/gen/heat/resources]$ python
3]. Connect to the API server
from vnc_api.vnc_api import *
from vnc_api import vnc_api
vh=VncApi(username='admin',password='<pwd>',tenant_name='admin',api_server_host='<api_server_ip>',api_server_port='8082')
4]. Get a list of the Projects, VNs, Fabrics, Physical Interfaces and Security Groups. This will help us get the UUID of the required Project, VN, Fabric, PI and SG.
vh.virtual_networks_list()
vh.physical_interfaces_list()
vh.projects_list()
vh.fabrics_list()
vh.security_groups_list()
my_sg=vh.security_group_read(id=<sg_uuid>)
my_proj=vh.project_read(id=<proj_uuid>)
my_vn=vh.virtual_network_read(id=<vn_uuid>)
my_fab=vh.fabric_read(id=<fab_uuid>)
my_pi = vh.physical_interface_read(id=<pi_uuid>)
5]. Create a VMI and add a IIP to it. Majority of the properties of the VPG are to be configured here.
my_vmi=vnc_api.VirtualMachineInterface(name=<vmi-name>,parent_obj=my_proj)
my_vmi.add_virtual_network(my_vn)
vh.virtual_machine_interface_create(my_vmi)
my_vmi=vh.virtual_machine_interface_read(id=<vmi_uuid>)
my_iip=vnc_api.InstanceIp(name=<iip-name>)
my_iip.add_virtual_network(my_vn)
my_iip.add_virtual_machine_interface(my_vmi)
vh.instance_ip_create(my_iip)
6]. Create a VPG
my_vpg=vnc_api.VirtualPortGroup(name=<vpg-name>,parent_obj=my_fab)`
my_vpg.set_virtual_port_group_type('access')
obj_1 = vnc_api.VpgInterfaceParametersType()
my_vpg.add_physical_interface(my_pi, obj_1)
my_vpg.add_virtual_machine_interface(my_vmi)
vh.virtual_port_group_create(my_vpg)
7]. Update the properties of the VMI which will be reflected in the VPG.
kvps = vnc_api.KeyValuePairs()
kvp = vnc_api.KeyValuePair()
kvp.set_key("profile")
kvp.set_value('{"local_link_information":[{"port_id":"ge-0/0/2","switch_id":"ge-0/0/2","switch_info":"r2ru39-qfx5100-leaf-2","fabric":"fabric1"}]}') `<<<< Replace values accordingly.
kvps.add_key_value_pair(kvp)
kvp = vnc_api.KeyValuePair()
kvp.set_key("vpg")
kvp.set_value(<vpg-name>)
kvps.add_key_value_pair(kvp)
kvp = vnc_api.KeyValuePair()
kvp.set_key("vnic_type")
kvp.set_value("baremetal")
kvps.add_key_value_pair(kvp)
kvp = vnc_api.KeyValuePair()
kvp.set_key("vif_type”)
kvp.set_value("vrouter")
kvps.add_key_value_pair(kvp)
my_vmi.set_virtual_machine_interface_bindings(kvps)
my_vmi.add_security_group(my_sg)
obj_1 = vnc_api.VirtualMachineInterfacePropertiesType()
obj_1.set_sub_interface_vlan_tag(111)
my_vmi.set_virtual_machine_interface_properties(obj_1)
vh.virtual_machine_interface_update(my_vmi)
8]. Multiple vLANs in a VPG map to multiple VMI. Create new VMI, update the VPG and later the VMI info.