pyhpecw7.comware module

Manage connections to HPCOM7 devices.

(c) Copyright 2016 Hewlett Packard Enterprise Development LP 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.

class pyhpecw7.comware.HPCOM7(**kvargs)[source]

Bases: object

This class manages the NETCONF connection to an HP Comware switch, and provides methods to execute various NETCONF operations.

Parameters:
  • host – REQUIRED - hostname or IP address of the HP Comware Switch
  • username – REQUIRED - username used to login to the switch. Requires network-admin access
  • password – REQUIRED - password used to login to the switch. Requires network-admin access
  • port – OPTIONAL - integer that represents the NETCONF port being used on the switch. Default is 830.
  • timeout – OPTIONAL - How long a single RPC rquest should wait before timing out.
  • ssh_config – OPTIONAL - enables parsing of a OpenSSH configuration file, either file in string, or defaults to ~/.ssh/config if True
staged

Dictionary that stores XML objects prior to being sent to the device. It is a “holding” area. The stage_config method is are used to build this attribute. Keys are user defined to make it possible to recall/view the specified object if more than one are being prepared to send.

staged_cli

Dictionary that stores XML objects when pushing raw CLI commands via NETCONF. It is a “holding” area. The stage_cli_display and stage_cli_config methods are used to build this attribute. Keys are user defined to make it possible to recall/view the specified object if more than one are being prepared to send.

action(element)[source]

Wrapper for ncclient.manger.action

Parameters:element – etree.Element sent to ncclient.manager.action
Returns:The etree.Element returned from ncclient.manager.action
cli_config(command)[source]

Immediately push config commands to the device and returns text.

Parameters:command (list or string) – config commands
Returns:raw text CLI output
cli_display(command)[source]

Immediately push display commands to the device and returns text.

Parameters:command (list or string) – display commands
Returns:raw text CLI output
close()[source]

Close the NETCONF connection to the HP switch.

connected

True if the NETCONF session to the device is open else it is False.

edit_config(config, target='running')[source]

Send a NETCONF edit_config XML object to the device.

Parameters:
  • config – etree.Element sent to ncclient.manager.edit_config
  • target – Name of configuration on the remote device. Defaults to ‘running’
Returns:

The etree.Element returned from ncclient.manager.edit_config

execute(run_cmd_func, args=[], kwargs={})[source]

Safely execute the supplied function with args and kwargs.

Parameters:

run_cmd_func (executable) – Function to be run.

Returns:

The return value of the supplied function.

Raises:
execute_staged(target='running')[source]

Execute/Push the XML object(s) or CLI strings in the staging area (self.staged) to the device.

Parameters:target (str) – must be set to running. It could change in the future if HP supports candidate configurations, etc. Only used for ‘edit_config’ API calls. Defaults to ‘running’.
Returns:A list of responses received from the device. Responses with CLI information are extracted from the XML response.
facts

A dictionary of a facts about the device. None if not connected.

get(get_tuple=None)[source]

Wrapper for ncclient.manger.get

Parameters:get_tuple – The tuple sent to ncclient.manager.get, e.g: (‘subtree’, <etree.Element>)
Returns:The etree.Element returned from ncclient.manager.get
lock(target='running')[source]

Attempt to lock the NETCONF connection.

Raises:
  • NCError – if there is an error in the NETCONF protocol.
  • LockConflictError – if another process hold the NETCONF lock.
open(hostkey_verify=False, allow_agent=True, look_for_keys=False)[source]

Open the NETCONF connection to the HP switch.

Parameters:
  • hostkey_verify (bool) – OPTIONAL - enables hostkey verification from ~/.ssh/known_hosts
  • allow_agent (bool) – OPTIONAL - enables querying SSH agent (if found) for keys
  • look_for_keys (bool) – OPTIONAL - enables looking in the usual locations for ssh keys (e.g. ~/.ssh/id_*)
Returns:

Connection to the device using ncclient’s connect method.

Raises:
reboot()[source]

Attempt an immediate reboot of the device.

rollback(filename)[source]

Wrapper for ncclient.manger.rollback

Parameters:element – etree.Element sent to ncclient.manager.rollback
Returns:The etree.Element returned from ncclient.manager.rollback
save(filename=None)[source]

Wrapper for ncclient.manger.save

Parameters:element – etree.Element sent to ncclient.manager.save
Returns:The etree.Element returned from ncclient.manager.save
stage_config(config, cfg_type)[source]

Append config object to the staging area.

Parameters:
  • config – The config payload. Could be a partial etree.Element XML object or raw text if using a CLI config type
  • cfg_type (string) – The type of config payload. Permitted options: “edit_config”, “action”, “cli_config”, “cli_display”, “save”, “rollback”
Returns:

True if config object was successfully staged.

Raises:

ValueError – if an invalid config type is supplied.

staged_to_string()[source]

Convert the staging area to a list of strings.

Returns:A list of string representing the configuration in the staging area.
unlock(target='running')[source]

Attempt to unlock the NETCONF connection.

Raises:
  • NCError – if there is an error in the NETCONF protocol.
  • LockConflictError – if another process hold the NETCONF lock.