Add port to router using python

Bino Oetomo bino at jogjacamp.co.id
Mon Dec 10 05:13:34 UTC 2018


Dear All.

My openstack installation version is 'rocky'.

I tried to create a new port and add it to existing router.
Got no error messages, but the port status always 'DOWN'.

--------------------------------------
>>> myrouter
{'status': 'ACTIVE', 'external_gateway_info': {'network_id':
'd10dd06a-0425-49eb-a8ba-85abf55ac0f5', 'enable_snat': True,
'external_fixed_ips': [{'subnet_id':
'4639e018-1cc1-49cc-89d4-4cad49bd4b89', 'ip_address': '10.10.10.2'}]},
'availability_zone_hints': [], 'availability_zones': ['nova'],
'description': '', 'tags': [], 'tenant_id':
'c0b89f614b5a457cb5acef8fe8c2b320', 'created_at': '2018-12-07T07:24:41Z',
'admin_state_up': True, 'distributed': False, 'updated_at':
'2018-12-07T07:58:02Z', 'project_id': 'c0b89f614b5a457cb5acef8fe8c2b320',
'flavor_id': None, 'revision_number': 10, 'routes': [], 'ha': False, 'id':
'a616dcc0-1f72-4424-9494-4d13b42445ee', 'name': 'Bino-rtr-01'}

```>>> mynetworks=[n for n in netlist['networks'] if
n['name'].startswith('Bino')]
>>> mynetworks
[{'provider:physical_network': 'viavlan', 'ipv6_address_scope': None,
'revision_number': 7, 'port_security_enabled': True, 'mtu': 1500, 'id':
'942675f6-fd5e-4bb2-ba43-487be992ff4e', 'router:external': False,
'availability_zone_hints': [], 'availability_zones': ['nova'],
'ipv4_address_scope': None, 'shared': False, 'project_id':
'c0b89f614b5a457cb5acef8fe8c2b320', 'status': 'ACTIVE', 'subnets':
['5373bc35-a90f-4793-a912-801920e47769'], 'description': '', 'tags': [],
'updated_at': '2018-12-07T07:50:27Z', 'provider:segmentation_id': 2037,
'name': 'Bino-net-01', 'admin_state_up': True, 'tenant_id':
'c0b89f614b5a457cb5acef8fe8c2b320', 'created_at': '2018-12-07T07:28:00Z',
'provider:network_type': 'vlan'}, {'provider:physical_network': 'viavlan',
'ipv6_address_scope': None, 'revision_number': 6, 'port_security_enabled':
True, 'mtu': 1500, 'id': 'dfc8ed54-106d-48d0-8b45-cbd3cf0fbb79',
'router:external': False, 'availability_zone_hints': [],
'availability_zones': ['nova'], 'ipv4_address_scope': None, 'shared':
False, 'project_id': 'c0b89f614b5a457cb5acef8fe8c2b320', 'status':
'ACTIVE', 'subnets': ['c71a86a3-f9a8-4e60-828e-5d6f87e58ac9'],
'description': '', 'tags': [], 'updated_at': '2018-12-07T07:49:59Z',
'provider:segmentation_id': 2002, 'name': 'Bino-net-02', 'admin_state_up':
True, 'tenant_id': 'c0b89f614b5a457cb5acef8fe8c2b320', 'created_at':
'2018-12-07T07:29:52Z', 'provider:network_type': 'vlan'}]
>>> print([n['name'] for n in mynetworks])
['Bino-net-01', 'Bino-net-02']
>>> mynetwork=mynetworks[1]
>>> mynetwork['name']
'Bino-net-02'
>>> body_value = {
...    'port': {
...        'admin_state_up': True,
...        'device_id': myrouter['id'],
...        'name': 'Bino-rtr-01-02',
...        'network_id': mynetwork['id'],
...    }
... }
>>> response = nt.create_port(body=body_value)
>>> response
{'port': {'allowed_address_pairs': [], 'extra_dhcp_opts': [], 'updated_at':
'2018-12-10T01:44:10Z', 'device_owner': '', 'revision_number': 1,
'binding:profile': {}, 'port_security_enabled': True, 'fixed_ips':
[{'subnet_id': 'c71a86a3-f9a8-4e60-828e-5d6f87e58ac9', 'ip_address':
'192.168.202.6'}], 'id': 'a2a337af-3a37-4a9a-a4f1-ffaacdf9f881',
'security_groups': ['4bed540c-266d-4cc2-8225-3e02ccd89ff1'],
'binding:vif_details': {}, 'binding:vif_type': 'unbound', 'mac_address':
'fa:16:3e:05:aa:b5', 'project_id': 'c0b89f614b5a457cb5acef8fe8c2b320',
'status': 'DOWN', 'binding:host_id': '', 'description': '', 'tags': [],
'device_id': 'a616dcc0-1f72-4424-9494-4d13b42445ee', 'name':
'Bino-rtr-01-02', 'admin_state_up': True, 'network_id':
'dfc8ed54-106d-48d0-8b45-cbd3cf0fbb79', 'tenant_id':
'c0b89f614b5a457cb5acef8fe8c2b320', 'created_at': '2018-12-10T01:44:10Z',
'binding:vnic_type': 'normal'}}
>>> response['port']['status']
'DOWN'

--------------------------------------

Kindly please give me some clues to fic this problem

Sincerely
-bino-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-discuss/attachments/20181210/b92c294d/attachment.html>


More information about the openstack-discuss mailing list