diff options
author | 2017-11-01 15:05:30 +0800 | |
---|---|---|
committer | 2017-11-03 14:59:22 +0800 | |
commit | 8120b2583c459c85116d69211038e0110d71e5b7 (patch) | |
tree | 886448deb230ba530fe8814cd5d224e0f2a6299d /compass-tasks/hdsdiscovery/vendors | |
parent | 3656ab7b5e3f2f26f7c98f9dcc97b3c461fa2a76 (diff) |
Add compass-tasks
Registered tasks and MQ modules for Compass
Change-Id: Id1569a61fe53357d53448478d5ba42cb1f386bc6
Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
Diffstat (limited to 'compass-tasks/hdsdiscovery/vendors')
25 files changed, 654 insertions, 0 deletions
diff --git a/compass-tasks/hdsdiscovery/vendors/__init__.py b/compass-tasks/hdsdiscovery/vendors/__init__.py new file mode 100644 index 0000000..4ee55a4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. diff --git a/compass-tasks/hdsdiscovery/vendors/appliance/__init__.py b/compass-tasks/hdsdiscovery/vendors/appliance/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/appliance/__init__.py diff --git a/compass-tasks/hdsdiscovery/vendors/appliance/appliance.py b/compass-tasks/hdsdiscovery/vendors/appliance/appliance.py new file mode 100644 index 0000000..3d66f4e --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/appliance/appliance.py @@ -0,0 +1,34 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + + +"""Vendor: Compass Appliance""" +from compass.hdsdiscovery import base + + +# Vendor_loader will load vendor instance by CLASS_NAME +CLASS_NAME = 'Appliance' + + +class Appliance(base.BaseSnmpVendor): + """Fake SNMP object for compass appliance.""" + + def __init__(self): + base.BaseSnmpVendor.__init__(self, ['appliance']) + self.__name = 'appliance' + + @property + def name(self): + """Get 'name' proptery.""" + return self.__name diff --git a/compass-tasks/hdsdiscovery/vendors/appliance/plugins/__init__.py b/compass-tasks/hdsdiscovery/vendors/appliance/plugins/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/appliance/plugins/__init__.py diff --git a/compass-tasks/hdsdiscovery/vendors/appliance/plugins/mac.py b/compass-tasks/hdsdiscovery/vendors/appliance/plugins/mac.py new file mode 100644 index 0000000..cc14881 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/appliance/plugins/mac.py @@ -0,0 +1,48 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + +"""Compass Appliance Mac module.""" +from compass.hdsdiscovery import base +from compass.utils import setting_wrapper as setting +from compass.utils import util + +import logging + + +CLASS_NAME = "Mac" + + +class Mac(base.BaseSnmpMacPlugin): + """Processes MAC address.""" + + def __init__(self, host, credential): + self.host = host + # self.credential = credential + # return + + def scan(self): + """Implemnets the scan method in BasePlugin class. + + .. note:: + Dummy scan function for compass appliance. + Returns fixed mac addresses. + """ + mac_list = None + machine_lists = util.load_configs(setting.MACHINE_LIST_DIR) + for items in machine_lists: + for item in items['MACHINE_LIST']: + for k, v in item.items(): + if k == self.host: + mac_list = v + return mac_list diff --git a/compass-tasks/hdsdiscovery/vendors/arista/__init__.py b/compass-tasks/hdsdiscovery/vendors/arista/__init__.py new file mode 100644 index 0000000..4ee55a4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/arista/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. diff --git a/compass-tasks/hdsdiscovery/vendors/arista/arista.py b/compass-tasks/hdsdiscovery/vendors/arista/arista.py new file mode 100644 index 0000000..5eacea1 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/arista/arista.py @@ -0,0 +1,33 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + +"""Vendor: Arista.""" +from compass.hdsdiscovery import base + + +# Vendor_loader will load vendor instance by CLASS_NAME +CLASS_NAME = 'Arista' + + +class Arista(base.BaseSnmpVendor): + """Arista Network switch object.""" + + def __init__(self): + base.BaseSnmpVendor.__init__(self, ['arista']) + self._name = 'arista' + + @property + def name(self): + """Get 'name' proptery.""" + return self._name diff --git a/compass-tasks/hdsdiscovery/vendors/arista/plugins/__init__.py b/compass-tasks/hdsdiscovery/vendors/arista/plugins/__init__.py new file mode 100644 index 0000000..4ee55a4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/arista/plugins/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. diff --git a/compass-tasks/hdsdiscovery/vendors/arista/plugins/mac.py b/compass-tasks/hdsdiscovery/vendors/arista/plugins/mac.py new file mode 100644 index 0000000..ed2f331 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/arista/plugins/mac.py @@ -0,0 +1,24 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + +"""Pica8 Switch Mac module.""" +from compass.hdsdiscovery.base import BaseSnmpMacPlugin + + +CLASS_NAME = 'Mac' + + +class Mac(BaseSnmpMacPlugin): + """Process MAC address by Arista switch.""" + pass diff --git a/compass-tasks/hdsdiscovery/vendors/hp/__init__.py b/compass-tasks/hdsdiscovery/vendors/hp/__init__.py new file mode 100644 index 0000000..4ee55a4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/hp/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. diff --git a/compass-tasks/hdsdiscovery/vendors/hp/hp.py b/compass-tasks/hdsdiscovery/vendors/hp/hp.py new file mode 100644 index 0000000..7ddc5e9 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/hp/hp.py @@ -0,0 +1,33 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + +"""Vendor: HP.""" +from compass.hdsdiscovery import base + + +# Vendor_loader will load vendor instance by CLASS_NAME +CLASS_NAME = 'Hp' + + +class Hp(base.BaseSnmpVendor): + """Hp switch object.""" + + def __init__(self): + base.BaseSnmpVendor.__init__(self, ['hp', 'procurve']) + self.names = ['hp', 'procurve'] + + @property + def name(self): + """Get 'name' proptery.""" + return self.names[0] diff --git a/compass-tasks/hdsdiscovery/vendors/hp/plugins/__init__.py b/compass-tasks/hdsdiscovery/vendors/hp/plugins/__init__.py new file mode 100644 index 0000000..4ee55a4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/hp/plugins/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. diff --git a/compass-tasks/hdsdiscovery/vendors/hp/plugins/mac.py b/compass-tasks/hdsdiscovery/vendors/hp/plugins/mac.py new file mode 100644 index 0000000..3bc81f4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/hp/plugins/mac.py @@ -0,0 +1,23 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + +"""HP Switch Mac module.""" +from compass.hdsdiscovery.base import BaseSnmpMacPlugin + +CLASS_NAME = 'Mac' + + +class Mac(BaseSnmpMacPlugin): + """Process MAC address by HP switch.""" + pass diff --git a/compass-tasks/hdsdiscovery/vendors/huawei/__init__.py b/compass-tasks/hdsdiscovery/vendors/huawei/__init__.py new file mode 100644 index 0000000..4ee55a4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/huawei/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. diff --git a/compass-tasks/hdsdiscovery/vendors/huawei/huawei.py b/compass-tasks/hdsdiscovery/vendors/huawei/huawei.py new file mode 100644 index 0000000..19fd043 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/huawei/huawei.py @@ -0,0 +1,33 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + +"""Huawei Switch.""" +from compass.hdsdiscovery import base + + +# Vendor_loader will load vendor instance by CLASS_NAME +CLASS_NAME = "Huawei" + + +class Huawei(base.BaseSnmpVendor): + """Huawei switch.""" + + def __init__(self): + base.BaseSnmpVendor.__init__(self, ["huawei"]) + self.__name = "huawei" + + @property + def name(self): + """Return switch name.""" + return self.__name diff --git a/compass-tasks/hdsdiscovery/vendors/huawei/plugins/__init__.py b/compass-tasks/hdsdiscovery/vendors/huawei/plugins/__init__.py new file mode 100644 index 0000000..4ee55a4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/huawei/plugins/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. diff --git a/compass-tasks/hdsdiscovery/vendors/huawei/plugins/mac.py b/compass-tasks/hdsdiscovery/vendors/huawei/plugins/mac.py new file mode 100644 index 0000000..49d3863 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/huawei/plugins/mac.py @@ -0,0 +1,63 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + +"""Huawei Switch Mac module.""" +import logging + +from compass.hdsdiscovery.base import BaseSnmpMacPlugin +from compass.hdsdiscovery import utils + + +CLASS_NAME = "Mac" + + +class Mac(BaseSnmpMacPlugin): + """Processes MAC address.""" + + def __init__(self, host, credential): + super(Mac, self).__init__( + host, credential, + 'HUAWEI-L2MAM-MIB::hwDynFdbPort') + + def scan(self): + """Implemnets the scan method in BasePlugin class. + + .. note:: + In this mac module, mac addesses were retrieved by + snmpwalk commandline. + """ + results = utils.snmpwalk_by_cl(self.host, self.credential, self.oid) + + if not results: + logging.info("[Huawei][mac] No results returned from SNMP walk!") + return None + + mac_list = [] + + for entity in results: + # The format of 'iid' is like '248.192.1.214.34.15.31.1.48' + # The first 6 numbers will be the MAC address + # The 7th number is its vlan ID + numbers = entity['iid'].split('.') + mac = self.get_mac_address(numbers[:6]) + vlan = numbers[6] + port = self.get_port(entity['value']) + + tmp = {} + tmp['port'] = port + tmp['mac'] = mac + tmp['vlan'] = vlan + mac_list.append(tmp) + + return mac_list diff --git a/compass-tasks/hdsdiscovery/vendors/ovswitch/__init__.py b/compass-tasks/hdsdiscovery/vendors/ovswitch/__init__.py new file mode 100644 index 0000000..4ee55a4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/ovswitch/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. diff --git a/compass-tasks/hdsdiscovery/vendors/ovswitch/ovswitch.py b/compass-tasks/hdsdiscovery/vendors/ovswitch/ovswitch.py new file mode 100644 index 0000000..4d03328 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/ovswitch/ovswitch.py @@ -0,0 +1,76 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + +"""Open Vswitch module.""" +import logging +import re + +from compass.hdsdiscovery import base +from compass.hdsdiscovery import utils + + +# Vendor_loader will load vendor instance by CLASS_NAME +CLASS_NAME = "OVSwitch" + + +class OVSwitch(base.BaseVendor): + """Open Vswitch.""" + def __init__(self): + self.__name = "Open vSwitch" + + def is_this_vendor(self, sys_info, host=None, credential=None, **kwargs): + """Determine if the hostname is accociated witH this vendor. + + :param host: swtich's IP address + :param credential: credential to access switch + """ + result = sys_info + if host and credential: + if utils.is_valid_ssh_credential(credential): + user = credential['username'] + pwd = credential['password'] + + else: + msg = ("[OVSwitch]The format of credential %r is not for SSH " + "or incorrect Keywords! " % credential) + logging.info(msg) + return False + + cmd = "ovs-vsctl -V" + result = None + try: + result = utils.ssh_remote_execute(host, user, pwd, cmd) + logging.debug('%s result for %s is %s', cmd, host, result) + if not result: + return False + except Exception as exc: + logging.error("No vendor or connection failed to run %s", cmd) + logging.exception(exc) + return False + + if isinstance(result, str): + result = [result] + + for line in result: + if not line: + continue + if re.search(r"\b" + re.escape(self.__name) + r"\b", line): + return True + + return False + + @property + def name(self): + """Open Vswitch name.""" + return self.__name diff --git a/compass-tasks/hdsdiscovery/vendors/ovswitch/plugins/__init__.py b/compass-tasks/hdsdiscovery/vendors/ovswitch/plugins/__init__.py new file mode 100644 index 0000000..4ee55a4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/ovswitch/plugins/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. diff --git a/compass-tasks/hdsdiscovery/vendors/ovswitch/plugins/mac.py b/compass-tasks/hdsdiscovery/vendors/ovswitch/plugins/mac.py new file mode 100644 index 0000000..5f497a0 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/ovswitch/plugins/mac.py @@ -0,0 +1,87 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + +"""Open Vswitch Mac address module.""" +import logging + +from compass.hdsdiscovery import base +from compass.hdsdiscovery import utils + + +CLASS_NAME = "Mac" + + +class Mac(base.BasePlugin): + """Open Vswitch MAC address module.""" + def __init__(self, host, credential): + self.host = host + self.credential = credential + + def process_data(self, oper="SCAN", **kwargs): + """Dynamically call the function according 'oper' + + :param oper: operation of data processing + """ + func_name = oper.lower() + return getattr(self, func_name)(**kwargs) + + def scan(self, **kwargs): + """Implemnets the scan method in BasePlugin class. + + .. note:: + In this module, mac addesses were retrieved by ssh. + """ + try: + user = self.credential['username'] + pwd = self.credential['password'] + except KeyError: + logging.error("Cannot find username and password in credential") + return None + + cmd = ("BRIDGES=$(ovs-vsctl show |grep Bridge |cut -f 2 -d '\"');" + "for br in $BRIDGES; do" + "PORTS=$(ovs-ofctl show $br |grep addr |cut -f 1 -d ':' " + "|egrep -v 'eth|wlan|LOCAL'|awk -F '(' '{print $1}');" + "for port in $PORTS; do" + "RESULT=$(ovs-appctl fdb/show $br |" + "awk '$1 == '$port' {print $1" "$2" "$3}');" + "echo '$RESULT'" + "done;" + "done;") + output = None + try: + output = utils.ssh_remote_execute(self.host, user, pwd, cmd) + except Exception as error: + logging.exception(error) + return None + + logging.debug("[scan][output] output is %s", output) + if not output: + return None + + fields_arr = ['port', 'vlan', 'mac'] + + result = [] + for line in output: + if not line or line == '\n': + continue + + values_arr = line.split() + temp = {} + for field, value in zip(fields_arr, values_arr): + temp[field] = value + + result.append(temp.copy()) + + return result diff --git a/compass-tasks/hdsdiscovery/vendors/pica8/__init__.py b/compass-tasks/hdsdiscovery/vendors/pica8/__init__.py new file mode 100644 index 0000000..4ee55a4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/pica8/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. diff --git a/compass-tasks/hdsdiscovery/vendors/pica8/pica8.py b/compass-tasks/hdsdiscovery/vendors/pica8/pica8.py new file mode 100644 index 0000000..856817e --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/pica8/pica8.py @@ -0,0 +1,33 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + +"""Vendor: Pica8.""" +from compass.hdsdiscovery import base + + +# Vendor_loader will load vendor instance by CLASS_NAME +CLASS_NAME = 'Pica8' + + +class Pica8(base.BaseSnmpVendor): + """Pica8 switch object.""" + + def __init__(self): + base.BaseSnmpVendor.__init__(self, ['pica8']) + self._name = 'pica8' + + @property + def name(self): + """Get 'name' proptery.""" + return self._name diff --git a/compass-tasks/hdsdiscovery/vendors/pica8/plugins/__init__.py b/compass-tasks/hdsdiscovery/vendors/pica8/plugins/__init__.py new file mode 100644 index 0000000..4ee55a4 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/pica8/plugins/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. diff --git a/compass-tasks/hdsdiscovery/vendors/pica8/plugins/mac.py b/compass-tasks/hdsdiscovery/vendors/pica8/plugins/mac.py new file mode 100644 index 0000000..d5ccfc0 --- /dev/null +++ b/compass-tasks/hdsdiscovery/vendors/pica8/plugins/mac.py @@ -0,0 +1,24 @@ +# Copyright 2014 Huawei Technologies Co. Ltd +# +# 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. + +"""Pica8 Switch Mac module.""" +from compass.hdsdiscovery.base import BaseSnmpMacPlugin + + +CLASS_NAME = 'Mac' + + +class Mac(BaseSnmpMacPlugin): + """Process MAC address by Pica8 switch.""" + pass |