Skip to content

Commit

Permalink
OSP-278: Add OpenStack CLI for force-bcf-sync
Browse files Browse the repository at this point in the history
Also
- update doc
- remove py35 and use py36 to stay consistent with upstream

References:
- https://docs.openstack.org/python-openstackclient/latest/
- https://github.com/openstack/python-neutronclient/tree/master/neutronclient/osc
  • Loading branch information
Weifan Fu committed Jun 6, 2019
1 parent 777ab24 commit 215dbc1
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ ChangeLog

# Files created by releasenotes build
releasenotes/build

# intellij
.idea/
28 changes: 23 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
===============================
========================
python-bsn-neutronclient
===============================
========================

Python bindings for Big Switch Networks Neutron API

Expand All @@ -9,6 +9,24 @@ Python bindings for Big Switch Networks Neutron API
Features
--------

* Network Templates
* Reachability Tests - BCF test path extension
* Tenant Policies
- Network Templates
- Reachability Tests - BCF test path extension
- Tenant Policies
- Manually force BCF to sync network configuration

CLI Usage
---------
Currently only force-bcf-sync should be accessed via CLI, other features
should be accessed via Horizon GUI

OpenStack CLI:

- openstack force-bcf-sync
- Force BCF to sync network configuration
- No parameter

Neutron CLI (Deprecated):

- neutron force-bcf-sync 1
- Force BCF to sync network configuration
- Number 1 is required as parameter
Empty file.
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Copyright 2011 OpenStack Foundation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
# -*- coding: utf-8 -*-

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from neutronclient._i18n import _
from neutronclient.common import extension
Expand Down
Empty file.
54 changes: 54 additions & 0 deletions python_bsn_neutronclient/osc/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

"""OpenStackClient plugin for bsn neutron plugin."""

import logging
from osc_lib import utils

LOG = logging.getLogger(__name__)

DEFAULT_API_VERSION = '2.0'
API_VERSION_OPTION = 'os_network_api_version'
# NOTE(rtheis): API_NAME must NOT be set to 'network' since
# 'network' is owned by OSC! The OSC 'network' client uses
# the OpenStack SDK.
API_NAME = 'bsn_neutronclient'
API_VERSIONS = {
'2.0': 'python_bsn_neutronclient.v2_0.client.Client',
'2': 'python_bsn_neutronclient.v2_0.client.Client',
}


def make_client(instance):
"""Returns a bsn neutron client."""
bsn_neutron_client = utils.get_client_class(
API_NAME,
instance._api_version[API_NAME],
API_VERSIONS)
LOG.debug('Instantiating bsn neutron client: %s', bsn_neutron_client)

client = bsn_neutron_client(session=instance.session,
region_name=instance.region_name,
endpoint_type=instance.interface,
insecure=not instance.verify,
ca_cert=instance.cacert)

return client


def build_option_parser(parser):
"""Hook to add global options"""
# OSC itself has an option for Network API version # and we refer to it.
return parser
Empty file.
Empty file.
34 changes: 34 additions & 0 deletions python_bsn_neutronclient/osc/v2/topology/topology_sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from neutronclient._i18n import _
from osc_lib.command import command
from osc_lib import exceptions


class ForceBcfSync(command.Command):
_description = _("Force BCF to to sync network configuration")

def get_parser(self, prog_name):
parser = super(ForceBcfSync, self).get_parser(prog_name)
return parser

def take_action(self, parsed_args):
client = self.app.client_manager.bsn_neutronclient
result = client.force_bcf_sync()

try:
return result['forcesynctopology']['status']
except Exception as e:
raise exceptions.CommandError(e.message + '\n' + str(result))
19 changes: 19 additions & 0 deletions python_bsn_neutronclient/v2_0/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import pbr.version


__version__ = pbr.version.VersionInfo(
'python-bsn-neutronclient').version_string()
27 changes: 27 additions & 0 deletions python_bsn_neutronclient/v2_0/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from neutronclient.v2_0.client import Client as NeutronClientV2


class Client(NeutronClientV2):
force_bcf_sync_path = "/forcesynctopologies/%s"
force_bcf_sync_path_plural = "/forcesynctopologies"

def force_bcf_sync(self, topo_sync_id=None):
if not topo_sync_id:
topo_sync_id = 1

body = {'forcesynctopology': {'timestamp_ms': 'now'}}
return self.put(self.force_bcf_sync_path % topo_sync_id, body=body)
8 changes: 3 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.

pbr>=2.0 # Apache-2.0
python-neutronclient>=6.3.0 # Apache-2.0
osc_lib>=1.8.0 # Apache-2.0
oslo.i18n>=3.15.3 # Apache-2.0
python_neutronclient>=6.3.0 # Apache-2.0
4 changes: 3 additions & 1 deletion rhel/python-bsn-neutronclient.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%global rpm_prefix openstackclient-bigswitch

Name: %{pypi_name}
Version: 0.0.6
Version: 0.0.7
Release: 1%{?dist}
Epoch: 1
Summary: Python bindings for Big Switch Networks Neutron API
Expand Down Expand Up @@ -46,6 +46,8 @@ export SKIP_PIP_INSTALL=1
%postun

%changelog
* Tue Jun 6 2019 Weifan Fu <weifan.fu@bigswitch.com> - 0.0.7
- OSP-278: Transition from Neutron CLI to OpenStack CLi
* Tue Nov 20 2018 Weifan Fu <weifan.fu@bigswitch.com> - 0.0.6
- OSP-252: update tox for py3
* Mon Oct 08 2018 Aditya Vaja <wolverine.av@gmail.com> - 0.0.5
Expand Down
12 changes: 9 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = python-bsn-neutronclient
version = 0.0.6
version = 0.0.7
summary = Python bindings for Big Switch Networks Neutron API
description-file =
README.rst
Expand All @@ -18,15 +18,21 @@ classifier =
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6

[files]
packages =
python_bsn_neutronclient

[entry_points]
neutronclient.extension =
bsn_extensions = python_bsn_neutronclient.v2_0.bsn_plugin_client
bsn_extensions = python_bsn_neutronclient.neutron.bsn_plugin_client

openstack.cli.extension =
bsn_neutronclient = python_bsn_neutronclient.osc.plugin

openstack.bsn_neutronclient.v2 =
force-bcf-sync = python_bsn_neutronclient.osc.v2.topology.topology_sync:ForceBcfSync

[build_sphinx]
all-files = 1
Expand Down
7 changes: 1 addition & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 2.0
envlist = py35,py27,pep8
envlist = py36,py27,pep8
skipsdist = True

[testenv]
Expand All @@ -24,11 +24,6 @@ basepython = python2.7
commands =
{[testenv]commands}

[testenv:py35-dev]
basepython = python3.5
commands =
{[testenv]commands}

[testenv:py36-dev]
basepython = python3.6
commands =
Expand Down

0 comments on commit 215dbc1

Please sign in to comment.