From 59145be07e5df52a7cc0fb84e8da10fe4de6e770 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 6 Feb 2020 10:32:33 +0000 Subject: [PATCH] Add support for port bindings The port bindings API has been around since Pike but has never been exposed via neutronclient. We still use this in nova so it would be nice to avoid having to create a KSA client manually for this stuff. We don't need to expose things via the UI, just the client itself, so do that. Change-Id: Ied1a057186f0819166df84725b09ded314930a1d Signed-off-by: Stephen Finucane Sem-Ver: feature --- neutronclient/v2_0/client.py | 25 +++++++++++++++++++ .../notes/port-bindings-c3f36bd76ece0a71.yaml | 5 ++++ 2 files changed, 30 insertions(+) create mode 100644 releasenotes/notes/port-bindings-c3f36bd76ece0a71.yaml diff --git a/neutronclient/v2_0/client.py b/neutronclient/v2_0/client.py index c338c316e..5fa869840 100644 --- a/neutronclient/v2_0/client.py +++ b/neutronclient/v2_0/client.py @@ -492,6 +492,9 @@ class Client(ClientBase): network_path = "/networks/%s" ports_path = "/ports" port_path = "/ports/%s" + port_bindings_path = "/ports/%s/bindings" + port_binding_path = "/ports/%s/bindings/%s" + port_binding_path_activate = "/ports/%s/bindings/%s/activate" subnets_path = "/subnets" subnet_path = "/subnets/%s" onboard_network_subnets_path = "/subnetpools/%s/onboard_network_subnets" @@ -811,6 +814,28 @@ class Client(ClientBase): """Deletes the specified port.""" return self.delete(self.port_path % (port)) + def create_port_binding(self, port_id, body=None): + """Creates a new port binding.""" + return self.post(self.port_bindings_path % port_id, body=body) + + def delete_port_binding(self, port_id, host_id): + """Deletes the specified port binding.""" + return self.delete(self.port_binding_path % (port_id, host_id)) + + def show_port_binding(self, port_id, host_id, **_params): + """Fetches information for a certain port binding.""" + return self.get(self.port_binding_path % (port_id, host_id), + params=_params) + + def list_port_bindings(self, port_id, retrieve_all=True, **_params): + """Fetches a list of all bindings for a certain port.""" + return self.list('port_bindings', self.port_bindings_path % port_id, + retrieve_all, **_params) + + def activate_port_binding(self, port_id, host_id): + """Activates a port binding.""" + return self.put(self.port_binding_path_activate % (port_id, host_id)) + def list_networks(self, retrieve_all=True, **_params): """Fetches a list of all networks for a project.""" # Pass filters in "params" argument to do_request diff --git a/releasenotes/notes/port-bindings-c3f36bd76ece0a71.yaml b/releasenotes/notes/port-bindings-c3f36bd76ece0a71.yaml new file mode 100644 index 000000000..7d2ef725e --- /dev/null +++ b/releasenotes/notes/port-bindings-c3f36bd76ece0a71.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + New client methods: ``create_port_binding``, ``delete_port_binding``, + ``show_port_binding``, ``list_port_bindings`` and ``activate_port_binding``.