diff --git a/requirements.txt b/requirements.txt index 212d1a0e2..714a13a5d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,6 +9,7 @@ python-ceilometerclient>=2.2.1 # Apache-2.0 python-cinderclient>=1.3.1 # Apache-2.0 python-dateutil>=2.4.2 python-keystoneclient!=1.8.0,!=2.1.0,>=1.6.0 # Apache-2.0 +python-neutronclient!=4.1.0,>=2.6.0 # Apache-2.0 python-novaclient>=2.26.0 networkx>=1.10 oslo.config>=2.7.0 # Apache-2.0 diff --git a/test-requirements.txt b/test-requirements.txt index 7defb6998..7a1e69841 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -10,6 +10,7 @@ lxml>=2.3 networkx>=1.10 python-ceilometerclient>=2.2.1 # Apache-2.0 python-cinderclient>=1.3.1 # Apache-2.0 +python-neutronclient!=4.1.0,>=2.6.0 # Apache-2.0 python-novaclient>=2.26.0 python-subunit>=0.0.18 sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 diff --git a/vitrage/clients.py b/vitrage/clients.py index 87aa8e57a..49d4de25d 100644 --- a/vitrage/clients.py +++ b/vitrage/clients.py @@ -17,6 +17,7 @@ from oslo_log import log from ceilometerclient import client as cm_client from cinderclient import client as cin_client +from neutronclient.v2_0 import client as ne_client from novaclient import client as n_client @@ -76,3 +77,18 @@ def cinder_client(conf): return client except Exception as e: LOG.exception('Create Cinder client - Got Exception: %s', e) + + +def neutron_client(conf): + """Get an instance of neutron client""" + auth_config = conf.service_credentials + try: + client = ne_client.Client( + session=keystone_client.get_session(conf), + region_name=auth_config.region_name, + interface=auth_config.interface, + ) + LOG.info('Neutron client created') + return client + except Exception as e: + LOG.exception('Create Neutron client - Got Exception: %s', e) diff --git a/vitrage/synchronizer/plugins/cinder/volume/transformer.py b/vitrage/synchronizer/plugins/cinder/volume/transformer.py index c35b133de..d80c015bd 100644 --- a/vitrage/synchronizer/plugins/cinder/volume/transformer.py +++ b/vitrage/synchronizer/plugins/cinder/volume/transformer.py @@ -26,8 +26,9 @@ from vitrage.synchronizer.plugins.base.resource.transformer import \ BaseResourceTransformer from vitrage.synchronizer.plugins.cinder.volume import CINDER_VOLUME_PLUGIN from vitrage.synchronizer.plugins.nova.instance import NOVA_INSTANCE_PLUGIN -from vitrage.synchronizer.plugins import transformer_base +from vitrage.synchronizer.plugins.transformer_base import build_key from vitrage.synchronizer.plugins.transformer_base import extract_field_value +from vitrage.synchronizer.plugins.transformer_base import Neighbor LOG = logging.getLogger(__name__) @@ -133,7 +134,7 @@ class CinderVolumeTransformer(BaseResourceTransformer): self.VOLUME_ID[entity_event[SyncProps.SYNC_MODE]]) key_fields = self._key_values(CINDER_VOLUME_PLUGIN, volume_id) - return transformer_base.build_key(key_fields) + return build_key(key_fields) def create_placeholder_vertex(self, **kwargs): if VProps.ID not in kwargs: @@ -143,7 +144,7 @@ class CinderVolumeTransformer(BaseResourceTransformer): key_fields = self._key_values(CINDER_VOLUME_PLUGIN, kwargs[VProps.ID]) return graph_utils.create_vertex( - transformer_base.build_key(key_fields), + build_key(key_fields), entity_id=kwargs[VProps.ID], entity_category=EntityCategory.RESOURCE, entity_type=CINDER_VOLUME_PLUGIN, @@ -184,4 +185,4 @@ class CinderVolumeTransformer(BaseResourceTransformer): target_id=instance_vertex.vertex_id, relationship_type=EdgeLabels.ATTACHED) - return transformer_base.Neighbor(instance_vertex, relationship_edge) + return Neighbor(instance_vertex, relationship_edge) diff --git a/vitrage/synchronizer/plugins/neutron/__init__.py b/vitrage/synchronizer/plugins/neutron/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/vitrage/synchronizer/plugins/neutron/base.py b/vitrage/synchronizer/plugins/neutron/base.py new file mode 100644 index 000000000..a2ccf0cb2 --- /dev/null +++ b/vitrage/synchronizer/plugins/neutron/base.py @@ -0,0 +1,27 @@ +# Copyright 2016 - Alcatel-Lucent +# +# 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 vitrage import clients +from vitrage.synchronizer.plugins.synchronizer_base import SynchronizerBase + + +class NeutronBase(SynchronizerBase): + def __init__(self, conf): + super(NeutronBase, self).__init__() + self.client = clients.neutron_client(conf) + self.conf = conf + + def get_client(self): + return self.client diff --git a/vitrage/synchronizer/plugins/neutron/network/__init__.py b/vitrage/synchronizer/plugins/neutron/network/__init__.py new file mode 100644 index 000000000..0982d8cc5 --- /dev/null +++ b/vitrage/synchronizer/plugins/neutron/network/__init__.py @@ -0,0 +1,30 @@ +# Copyright 2016 - Nokia +# +# 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 oslo_config import cfg + +NEUTRON_NETWORK_PLUGIN = 'neutron.network' + +OPTS = [ + cfg.StrOpt('transformer', + default='vitrage.synchronizer.plugins.neutron.network.' + 'transformer.NetworkTransformer', + help='Neutron network transformer class path', + required=True), + cfg.StrOpt('synchronizer', + default='vitrage.synchronizer.plugins.neutron.network.' + 'synchronizer.NetworkSynchronizer', + help='Neutron network synchronizer class path', + required=True), +] diff --git a/vitrage/synchronizer/plugins/neutron/network/synchronizer.py b/vitrage/synchronizer/plugins/neutron/network/synchronizer.py new file mode 100644 index 000000000..af39d69ed --- /dev/null +++ b/vitrage/synchronizer/plugins/neutron/network/synchronizer.py @@ -0,0 +1,41 @@ +# Copyright 2016 - Alcatel-Lucent +# +# 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 vitrage.synchronizer.plugins.neutron.base import NeutronBase +from vitrage.synchronizer.plugins.neutron.network import NEUTRON_NETWORK_PLUGIN + + +class NetworkSynchronizer(NeutronBase): + + @staticmethod + def get_topic(conf): + pass + + @staticmethod + def get_event_types(conf): + pass + + @staticmethod + def enrich_event(event, event_type): + pass + + @staticmethod + def extract(networks): + return [network.__dict__ for network in networks] + + def get_all(self, sync_mode): + return self.make_pickleable( + self.extract(self.client.list_networks()), + NEUTRON_NETWORK_PLUGIN, + sync_mode) diff --git a/vitrage/synchronizer/plugins/neutron/network/transformer.py b/vitrage/synchronizer/plugins/neutron/network/transformer.py new file mode 100644 index 000000000..f70a58420 --- /dev/null +++ b/vitrage/synchronizer/plugins/neutron/network/transformer.py @@ -0,0 +1,20 @@ +# Copyright 2016 - Alcatel-Lucent +# +# 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 vitrage.synchronizer.plugins.base.resource.transformer import \ + BaseResourceTransformer + + +class NetworkTransformer(BaseResourceTransformer): + pass diff --git a/vitrage/synchronizer/plugins/neutron/port/__init__.py b/vitrage/synchronizer/plugins/neutron/port/__init__.py new file mode 100644 index 000000000..0d67681c4 --- /dev/null +++ b/vitrage/synchronizer/plugins/neutron/port/__init__.py @@ -0,0 +1,30 @@ +# Copyright 2016 - Nokia +# +# 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 oslo_config import cfg + +NEUTRON_PORT_PLUGIN = 'neutron.port' + +OPTS = [ + cfg.StrOpt('transformer', + default='vitrage.synchronizer.plugins.neutron.port.' + 'transformer.PortTransformer', + help='Neutron port transformer class path', + required=True), + cfg.StrOpt('synchronizer', + default='vitrage.synchronizer.plugins.neutron.port.' + 'synchronizer.PortSynchronizer', + help='Neutron port synchronizer class path', + required=True), +] diff --git a/vitrage/synchronizer/plugins/neutron/port/synchronizer.py b/vitrage/synchronizer/plugins/neutron/port/synchronizer.py new file mode 100644 index 000000000..a8299bacf --- /dev/null +++ b/vitrage/synchronizer/plugins/neutron/port/synchronizer.py @@ -0,0 +1,41 @@ +# Copyright 2016 - Alcatel-Lucent +# +# 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 vitrage.synchronizer.plugins.neutron.base import NeutronBase +from vitrage.synchronizer.plugins.neutron.port import NEUTRON_PORT_PLUGIN + + +class PortSynchronizer(NeutronBase): + + @staticmethod + def get_topic(conf): + pass + + @staticmethod + def get_event_types(conf): + pass + + @staticmethod + def enrich_event(event, event_type): + pass + + @staticmethod + def extract(ports): + return [port.__dict__ for port in ports] + + def get_all(self, sync_mode): + return self.make_pickleable( + self.extract(self.client.list_ports()), + NEUTRON_PORT_PLUGIN, + sync_mode) diff --git a/vitrage/synchronizer/plugins/neutron/port/transformer.py b/vitrage/synchronizer/plugins/neutron/port/transformer.py new file mode 100644 index 000000000..afe6c70af --- /dev/null +++ b/vitrage/synchronizer/plugins/neutron/port/transformer.py @@ -0,0 +1,20 @@ +# Copyright 2016 - Alcatel-Lucent +# +# 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 vitrage.synchronizer.plugins.base.resource.transformer import \ + BaseResourceTransformer + + +class PortTransformer(BaseResourceTransformer): + pass