GitHub user vdloo opened a pull request:
https://github.com/apache/libcloud/pull/1225
implement OpenStackv2 port attaching/detaching
## Implement OpenStackv2 port attaching/detaching
### Description
Adds Port Interface calls for the OpenStack v2 driver. Similar in
functionality to a floating IPs (can be attached / detached from a
compute instance to move IPs between instances) but a bit different.
> A port is a connection point for attaching a single device, such as the
> NIC of a server, to a network. The port also describes the associated
> network configuration, such as the MAC and IP addresses to be used on
> that port.
https://docs.openstack.org/python-openstackclient/pike/cli/command-objects/port.html
Also see:
https://developer.openstack.org/api-ref/compute/#port-interfaces-servers-os-interface
This commit adds:
- a connection to the neutron network API for functionality that is not
exposed through
the nova compute api
- an OpenStack_2_PortInterface object
- an OpenStack_2_PortInterfaceState object for port interface states
- an ex_list_ports method (via the neutron api)
- an ex_delete_port method (via the neutron api)
- an ex_detach_port_interface method (via the nova api)
- an ex_attach_port_interface method (via the nova api)
looks like:
listing and deleting a port
```
In [2]: conn.ex_list_ports()
Out[2]:
[<OpenStack_2_PortInterface: id=586da55e-cfcb-41c8-ae39-a26cb8a7e723,
state=build, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=a8f3ddbe-9b29-41ac-9c0a-9ea7cc02fdfb,
state=build, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=bad9af6a-921d-4772-9ae0-7d587b758f5d,
state=down, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=c29f97ca-4e68-4384-badf-10903cd2cbb0,
state=down, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=ca335147-273c-4c72-9fab-11f070a95ce1,
state=down, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=f018dec6-4f3a-45c4-a89c-678f69a72022,
state=down, driver=OpenStack ...>]
In [3]: myport = conn.ex_list_ports()[4]
In [4]: myport
Out[4]: <OpenStack_2_PortInterface:
id=ca335147-273c-4c72-9fab-11f070a95ce1, state=down, driver=OpenStack ...>
In [5]: myport.extra
Out[5]:
{'allowed_address_pairs': [],
'binding_vnic_type': u'normal',
'description': u'test1234',
'device_id': u'',
'device_owner': u'',
'fixed_ips': [{u'ip_address': u'12.123.12.12',
u'subnet_id': u'1231236a-123b-1239-a3c5-358ea86a7577'}],
'mac_address': u'ab:21:12:12:12:ba',
'name': test123',
'network_id': u'123c8a8c-1237-123f-1235-2035365f4d43',
'port_security_enabled': True,
'project_id': u'b1232c85bee34bb0a44123255e123fbd',
'revision_number': 3,
'security_groups': [u'1231230f-123c-123b-123f-123ee123f220'],
'tags': [],
'tenant_id': u'12352123bee31230a44123255e123fbd',
'updated': u'2018-07-05T11:57:00Z'}
In [6]: myport.delete()
Out[6]: True
In [7]: conn.ex_list_ports()
Out[7]:
[<OpenStack_2_PortInterface: id=586da55e-cfcb-41c8-ae39-a26cb8a7e723,
state=active, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=a8f3ddbe-9b29-41ac-9c0a-9ea7cc02fdfb,
state=active, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=bad9af6a-921d-4772-9ae0-7d587b758f5d,
state=down, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=c29f97ca-4e68-4384-badf-10903cd2cbb0,
state=down, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=f018dec6-4f3a-45c4-a89c-678f69a72022,
state=down, driver=OpenStack ...>]
````
attaching and detaching an IP using a port
```
In [34]: conn.list_nodes()
Out[34]:
[<Node: uuid=5f4ea5486ef59454e5a70ed092c52148d71d7a6e, name=test-magweb,
state=RUNNING, public_ips=[], private_ips=[], provider=OpenStack ...>,
...
In [35]: conn.ex_list_ports()
Out[35]:
[<OpenStack_2_PortInterface: id=586da55e-cfcb-41c8-ae39-a26cb8a7e723,
state=active, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=a8f3ddbe-9b29-41ac-9c0a-9ea7cc02fdfb,
state=active, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=bad9af6a-921d-4772-9ae0-7d587b758f5d,
state=down, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=c29f97ca-4e68-4384-badf-10903cd2cbb0,
state=down, driver=OpenStack ...>,
<OpenStack_2_PortInterface: id=f018dec6-4f3a-45c4-a89c-678f69a72022,
state=down, driver=OpenStack ...>]
In [38]: conn.ex_attach_port_interface(conn.list_nodes()[0],
conn.ex_list_ports()[3])
Out[38]: True
In [39]: conn.list_nodes()
Out[39]:
[<Node: uuid=5f4ea5486ef59454e5a70ed092c52148d71d7a6e,
name=pumbojet-magweb, state=RUNNING, public_ips=[u'12.123.12.43'],
private_ips=[], provider=OpenStack ...>,
...
In [40]: conn.ex_detach_port_interface(conn.list_nodes()[0],
conn.ex_list_ports()[3])
Out[40]: True
In [41]: conn.list_nodes()
Out[41]:
[<Node: uuid=5f4ea5486ef59454e5a70ed092c52148d71d7a6e,
name=pumbojet-magweb, state=RUNNING, public_ips=[], private_ips=[],
provider=OpenStack ...>,
...
```
### Status
- done, ready for review
cc @AlexanderGrooff
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/vdloo/libcloud
implement-openstack-v2-1-neutron-network-api
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/libcloud/pull/1225.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1225
----
commit 50851eb74f7424fabcb7573fc007a3b02343c1a6
Author: Rick van de Loo <rickvandeloo@...>
Date: 2018-07-05T15:18:27Z
implement OpenStackv2 port attaching/detaching
Adds Port Interface calls for the OpenStack v2 driver. Similar in
functionality to a floating IPs (can be attached / detached from a
compute instance to move IPs between instances) but a bit different.
> A port is a connection point for attaching a single device, such as the
> NIC of a server, to a network. The port also describes the associated
> network configuration, such as the MAC and IP addresses to be used on
> that port.
https://docs.openstack.org/python-openstackclient/pike/cli/command-objects/port.html
Also see:
https://developer.openstack.org/api-ref/compute/#port-interfaces-servers-os-interface
This commit adds:
- a connection to the neutron network API for functionality that is not
exposed through
the nova compute api
- an OpenStack_2_PortInterface object
- an OpenStack_2_PortInterfaceState object for port interface states
- an ex_list_ports method (via the neutron api)
- an ex_delete_port method (via the neutron api)
- an ex_detach_port_interface method (via the nova api)
- an ex_attach_port_interface method (via the nova api)
----
---