Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pylint fix for CICD #182

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 34 additions & 32 deletions examples/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,74 +15,76 @@
# limitations under the License.
###

from hpeOneView.oneview_client import OneViewClient
from pprint import pprint
from config_loader import try_load_from_file
from hpeOneView.resources.resource import extract_id_from_uri
from pprint import pprint
from hpeOneView.oneview_client import OneViewClient

config = {
CONFIG = {
"ip": "172.16.102.59",
"credentials": {
"userName": "administrator",
"password": ""
}
}

# Try load config from a file (if there is a config file)
config = try_load_from_file(config)
# Try load CONFIG from a file (if there is a CONFIG file)
CONFIG = try_load_from_file(CONFIG)

_client = OneViewClient(config)
_CLIENT = OneViewClient(CONFIG)

# Getting the first 5 alerts
print("\nGetting the first 5 alerts")
alerts = _client.alerts.get_all(0, 5)
for alert in alerts:
# Getting the first 5 ALERTS
print("\nGetting the first 5 ALERTS")
ALERTS = _CLIENT.alerts.get_all(0, 5)
for alert in ALERTS:
print("uri: '{uri}' | type: '{type}' | alertState: '{alertState}'".format(**alert))

# Get a specific alert (first of the list that was obtained in previous item)
print("\nGet a specific alert")
id_alert_by_id = extract_id_from_uri(alerts[0]['uri'])
print("Find id == %s" % id_alert_by_id)
alert_by_id = _client.alerts.get(id_alert_by_id)
print("uri: '%s' | alertState: '%s'" % (alert_by_id['uri'], alert_by_id['alertState']))
ID_ALERT_BY_ID = extract_id_from_uri(ALERTS[0]['uri'])
print("Find id == %s" % ID_ALERT_BY_ID)
ALERT_BY_ID = _CLIENT.alerts.get(ID_ALERT_BY_ID)
print("uri: '%s' | alertState: '%s'" % (ALERT_BY_ID['uri'], ALERT_BY_ID['alertState']))

# Get by Uri
print("Find uri == %s" % (alert['uri']))
alert_by_uri = _client.alerts.get(alert['uri'])
print("uri: '%s' | alertState: '%s'" % (alert_by_uri['uri'], alert_by_uri['alertState']))
ALERT_BY_URI = _CLIENT.alerts.get(alert['uri'])
print("uri: '%s' | alertState: '%s'" % (ALERT_BY_URI['uri'], ALERT_BY_URI['alertState']))

# Find first alert by state
print("\nGet first alert by state: Cleared")
alert_by_state = _client.alerts.get_by('alertState', 'Cleared')[0]
print("Found alert by state: '%s' | uri: '%s'" % (alert_by_state['alertState'], alert_by_state['uri']))
ALERT_BY_STATE = _CLIENT.alerts.get_by('alertState', 'Cleared')[0]
print("Found alert by state: '%s' | uri: '%s'" % (ALERT_BY_STATE['alertState'],\
ALERT_BY_STATE['uri']))

# Updates state alert and add note
print("\nUpdate state alert and add a note")
alert_to_update = {
'uri': alert_by_state['uri'],
ALERT_TO_UPDATE = {
'uri': ALERT_BY_STATE['uri'],
'alertState': 'Active',
'notes': 'A note to delete!'
}
alert_updated = _client.alerts.update(alert_to_update)
print("uri = '%s' | alertState = '%s'" % (alert_by_state['uri'], alert_by_state['alertState']))
ALERT_UPDATED = _CLIENT.alerts.update(ALERT_TO_UPDATE)
print("uri = '%s' | alertState = '%s'" % (ALERT_BY_STATE['uri'], ALERT_BY_STATE['alertState']))
print("Update alert successfully.")
pprint(alert_updated)
pprint(ALERT_UPDATED)

# Filter by state
print("\nGet all alerts filtering by alertState")
alerts = _client.alerts.get_all(filter="\"alertState='Locked'\"", view="day", count=10)
for alert in alerts:
print("'%s' | type: '%s' | alertState: '%s'" % (alert['uri'], alert['type'], alert['alertState']))
print("\nGet all ALERTS filtering by alertState")
ALERTS = _CLIENT.alerts.get_all(filter="\"alertState='Locked'\"", view="day", count=10)
for alert in ALERTS:
print("'%s' | type: '%s' | alertState: '%s'" % (alert['uri'], alert['type'],\
alert['alertState']))

# Deletes the alert
print("\nDelete an alert")
_client.alerts.delete(alert_by_id)
_CLIENT.alerts.delete(ALERT_BY_ID)
print("Successfully deleted alert")

# Deletes the AlertChangeLog item identified by URI
print("\nDelete alert change log by URI")
# filter by user entered logs
list_change_logs = [x for x in alert_updated['changeLog'] if x['userEntered'] is True]
uri_note = list_change_logs[-1]['uri']
_client.alerts.delete_alert_change_log(uri_note)
print("Note with URI '%s' deleted" % uri_note)
LIST_CHANGE_LOGS = [x for x in ALERT_UPDATED['changeLog'] if x['userEntered'] is True]
URI_NOTE = LIST_CHANGE_LOGS[-1]['uri']
_CLIENT.alerts.delete_alert_change_log(URI_NOTE)
print("Note with URI '%s' deleted" % URI_NOTE)
14 changes: 7 additions & 7 deletions examples/appliance_configuration_timeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
from hpeOneView.oneview_client import OneViewClient
from config_loader import try_load_from_file

config = {
CONFIG = {
"ip": "<oneview_ip>",
"credentials": {
"userName": "<username>",
"password": "<password>"
}
}
# Try load config from a file (if there is a config file)
config = try_load_from_file(config)
oneview_client = OneViewClient(config)
time_config = oneview_client.appliance_configuration_timeconfig
# Try load CONFIG from a file (if there is a CONFIG file)
CONFIG = try_load_from_file(CONFIG)
oneview_client = OneViewClient(CONFIG)
TIME_CONFIG = oneview_client.appliance_configuration_timeconfig

# Get all the supported locales
timeconfig = time_config.get_all()
TIMECONFIG = TIME_CONFIG.get_all()
print("\nGot appliance supported locales successfully!")
for timeandlocale in timeconfig:
for timeandlocale in TIMECONFIG:
print("\nLocale = {}".format(timeandlocale['locale']))
30 changes: 15 additions & 15 deletions examples/appliance_device_read_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,41 @@
from hpeOneView.oneview_client import OneViewClient
from config_loader import try_load_from_file

config = {
CONFIG = {
"ip": "<oneview_ip>",
"credentials": {
"userName": "<username>",
"password": "<password>"
}
}

options = {
OPTIONS = {
"communityString": "public"
}

# Try load config from a file (if there is a config file)
config = try_load_from_file(config)
# Try load CONFIG from a file (if there is a CONFIG file)
CONFIG = try_load_from_file(CONFIG)

oneview_client = OneViewClient(config)
oneview_client = OneViewClient(CONFIG)

# Lists the appliance device read community
read_community = oneview_client.appliance_device_read_community.get()
READ_COMMUNITY = oneview_client.appliance_device_read_community.get()
print("\n## Got appliance device read community successfully!")
pprint(read_community)
pprint(READ_COMMUNITY)

# Backup original values
bkp = {}
bkp['communityString'] = read_community['communityString']
BKP = {}
BKP['communityString'] = READ_COMMUNITY['communityString']

# Update Read Community
# Set to use appliance device read community
read_community['communityString'] = options['communityString']
read_community = oneview_client.appliance_device_read_community.update(read_community)
READ_COMMUNITY['communityString'] = OPTIONS['communityString']
READ_COMMUNITY = oneview_client.appliance_device_read_community.update(READ_COMMUNITY)
print("\n## Updated appliance device read community string successfully!")
pprint(read_community)
pprint(READ_COMMUNITY)

# Revert the changes made
read_community['communityString'] = bkp['communityString']
read_community = oneview_client.appliance_device_read_community.update(read_community)
READ_COMMUNITY['communityString'] = BKP['communityString']
READ_COMMUNITY = oneview_client.appliance_device_read_community.update(READ_COMMUNITY)
print("\n## Reverted appliance device read community string successfully!")
pprint(read_community)
pprint(READ_COMMUNITY)
59 changes: 31 additions & 28 deletions examples/appliance_device_snmp_v1_trap_destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,73 +19,76 @@
from hpeOneView.oneview_client import OneViewClient
from config_loader import try_load_from_file

config = {
CONFIG = {
"ip": "<oneview_ip>",
"credentials": {
"userName": "<username>",
"password": "<password>"
}
}

options = {
OPTIONS = {
"destination": "1.1.1.2",
"communityString": "testOne",
"port": 162
}

destination_ip = '2.2.2.2'
DESTINATION_IP = '2.2.2.2'

# Try load config from a file (if there is a config file)
config = try_load_from_file(config)
oneview_client = OneViewClient(config)
appliance_device_snmp_v1_trap_destinations = oneview_client.appliance_device_snmp_v1_trap_destinations
# Try load CONFIG from a file (if there is a CONFIG file)
CONFIG = try_load_from_file(CONFIG)
oneview_client = OneViewClient(CONFIG)
APPLIANCE_DEVICE_SNMP_V1_TRAP_DESTINATIONS = oneview_client.\
appliance_device_snmp_v1_trap_destinations

# Lists the appliance device SNMP v1 Trap Destination
print("\n Get list of appliance SNMP v1 trap destination")
snmp_v1_trap_all = appliance_device_snmp_v1_trap_destinations.get_all()
for snmp_trap in snmp_v1_trap_all:
SNMP_V1_TRAP_ALL = APPLIANCE_DEVICE_SNMP_V1_TRAP_DESTINATIONS.get_all()
for snmp_trap in SNMP_V1_TRAP_ALL:
print(' - {}: {}'.format(snmp_trap['destination'], snmp_trap['uri']))

# Add appliance device SNMP v1 Trap Destination
snmp_v1_trap = appliance_device_snmp_v1_trap_destinations.create(options)
SNMP_V1_TRAP = APPLIANCE_DEVICE_SNMP_V1_TRAP_DESTINATIONS.create(OPTIONS)
print("\n Created appliance SNMP v1 trap destination successfully!")
pprint(snmp_v1_trap.data)
pprint(SNMP_V1_TRAP.data)

# Get by name
print("\n## Find an SNMPv1 trap destination by name")
snmp_v1_trap = appliance_device_snmp_v1_trap_destinations.get_by_name(snmp_v1_trap.data['destination'])
pprint(snmp_v1_trap.data)
SNMP_V1_TRAP = APPLIANCE_DEVICE_SNMP_V1_TRAP_DESTINATIONS.\
get_by_name(SNMP_V1_TRAP.data['destination'])
pprint(SNMP_V1_TRAP.data)

# Add appliance device SNMP v1 Trap Destination with ID
trap_id = 9
options['destination'] = destination_ip
snmp_v1_trap_id = appliance_device_snmp_v1_trap_destinations.create(options, trap_id)
TRAP_ID = 9
OPTIONS['destination'] = DESTINATION_IP
SNMP_V1_TRAP_ID = APPLIANCE_DEVICE_SNMP_V1_TRAP_DESTINATIONS.create(OPTIONS, TRAP_ID)
print("\n Created appliance SNMP v1 trap destination by id successfully!")
pprint(snmp_v1_trap_id.data)
pprint(SNMP_V1_TRAP_ID.data)

# Get the appliance device SNMP v1 Trap Destination by id
print("\n Get appliance SNMP v1 trap destination by id")
snmp_v1_trap_by_id = appliance_device_snmp_v1_trap_destinations.get_by_id(1)
pprint(snmp_v1_trap_by_id.data)
SNMP_V1_TRAP_BY_ID = APPLIANCE_DEVICE_SNMP_V1_TRAP_DESTINATIONS.get_by_id(1)
pprint(SNMP_V1_TRAP_BY_ID.data)

# Lists the appliance device SNMP v1 Trap Destination by destination (unique)
print("\n## Get appliance SNMP v1 trap by destination..")
snmp_v1_traps = appliance_device_snmp_v1_trap_destinations.get_by('destination', options['destination'])
for snmp_trap in snmp_v1_traps:
SNMP_V1_TRAPS = APPLIANCE_DEVICE_SNMP_V1_TRAP_DESTINATIONS.get_by('destination',\
OPTIONS['destination'])
for snmp_trap in SNMP_V1_TRAPS:
print(' - {} : {}'.format(snmp_trap['destination'], snmp_trap['communityString']))

# Get by URI
print("\n Find an SNMP v1 trap destination by URI")
snmp_v1_trap = appliance_device_snmp_v1_trap_destinations.get_by_uri(snmp_v1_trap.data['uri'])
pprint(snmp_v1_trap.data)
SNMP_V1_TRAP = APPLIANCE_DEVICE_SNMP_V1_TRAP_DESTINATIONS.get_by_uri(SNMP_V1_TRAP.data['uri'])
pprint(SNMP_V1_TRAP.data)

# Change appliance device SNMP v1 Trap Destination - Only Community String and Port can be changed
data = {'communityString': 'testTwo'}
snmp_v1_trap = snmp_v1_trap.update(data)
DATA = {'communityString': 'testTwo'}
SNMP_V1_TRAP = SNMP_V1_TRAP.update(DATA)
print("\n## Update appliance SNMP v1 trap destination successfully!")
pprint(snmp_v1_trap.data)
pprint(SNMP_V1_TRAP.data)

# Delete Created Entry
snmp_v1_trap.delete()
snmp_v1_trap_id.delete()
SNMP_V1_TRAP.delete()
SNMP_V1_TRAP_ID.delete()
print("\n## Delete appliance SNMP v1 trap destination successfully!")
48 changes: 25 additions & 23 deletions examples/appliance_device_snmp_v3_trap_destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,64 @@
from hpeOneView.oneview_client import OneViewClient
from config_loader import try_load_from_file

config = {
CONFIG = {
"ip": "<oneview_ip>",
"credentials": {
"userName": "<username>",
"password": "<password>"
}
}

options = {
OPTIONS = {
"type": "Destination",
"destinationAddress": "1.1.1.1",
"port": 162,
"existingDestinations": ['2.3.2.3']
}

# Try load config from a file (if there is a config file)
config = try_load_from_file(config)
oneview_client = OneViewClient(config)
appliance_device_snmp_v3_trap_destinations = oneview_client.appliance_device_snmp_v3_trap_destinations
appliance_device_snmp_v3_users = oneview_client.appliance_device_snmp_v3_users
# Try load CONFIG from a file (if there is a CONFIG file)
CONFIG = try_load_from_file(CONFIG)
oneview_client = OneViewClient(CONFIG)
APPLIANCE_DEVICE_SNMP_V3_TRAP_DESTINATIONS = oneview_client.\
appliance_device_snmp_v3_trap_destinations
APPLIANCE_DEVICE_SNMP_V3_USERS = oneview_client.appliance_device_snmp_v3_users

# Get all snmpv3 users
# snmp v3 user must be there to create this
snmp_users = appliance_device_snmp_v3_users.get_all()
if snmp_users:
snmp_userId = snmp_users[0]['id']
SNMP_USERS = APPLIANCE_DEVICE_SNMP_V3_USERS.get_all()
if SNMP_USERS:
SNMP_USERID = SNMP_USERS[0]['id']
# Adding userId to snmpv3 users payload
options['userId'] = snmp_userId
OPTIONS['userId'] = SNMP_USERID
# Add appliance device SNMP v3 Trap Destination
snmp_v3_trap = appliance_device_snmp_v3_trap_destinations.create(options)
SNMP_V3_TRAP = APPLIANCE_DEVICE_SNMP_V3_TRAP_DESTINATIONS.create(OPTIONS)
print("\n## Created appliance SNMPv3 trap destination successfully!")
pprint(snmp_v3_trap.data)
pprint(SNMP_V3_TRAP.data)


# Lists the appliance device SNMP v3 Trap Destination
print("\n## Get list of appliance SNMPv3 trap destination")
snmp_v3_trap_all = appliance_device_snmp_v3_trap_destinations.get_all()
for snmp_trap in snmp_v3_trap_all:
SNMP_V3_TRAP_ALL = APPLIANCE_DEVICE_SNMP_V3_TRAP_DESTINATIONS.get_all()
for snmp_trap in SNMP_V3_TRAP_ALL:
print(' - {}: {}'.format(snmp_trap['destinationAddress'], snmp_trap['uri']))

# Get by name
print("\n## Find an SNMPv3 trap destination by name")
snmp_v3_trap = appliance_device_snmp_v3_trap_destinations.get_by_name(snmp_v3_trap.data['destinationAddress'])
pprint(snmp_v3_trap.data)
SNMP_V3_TRAP = APPLIANCE_DEVICE_SNMP_V3_TRAP_DESTINATIONS.get_by_name\
(SNMP_V3_TRAP.data['destinationAddress'])
pprint(SNMP_V3_TRAP.data)

# Get by URI
print("\n## Find an SNMPv3 trap destination by URI")
snmp_v3_trap = appliance_device_snmp_v3_trap_destinations.get_by_uri(snmp_v3_trap.data['uri'])
pprint(snmp_v3_trap.data)
SNMP_V3_TRAP = APPLIANCE_DEVICE_SNMP_V3_TRAP_DESTINATIONS.get_by_uri(SNMP_V3_TRAP.data['uri'])
pprint(SNMP_V3_TRAP.data)

# Change appliance device SNMP v3 Trap Destination - Only Community String and Port can be changed
snmpv3_data = {"port": 170}
snmp_v3_trap = snmp_v3_trap.update(snmpv3_data)
SNMPV3_DATA = {"port": 170}
SNMP_V3_TRAP = SNMP_V3_TRAP.update(SNMPV3_DATA)
print("\n## Update appliance SNMPv3 trap destination successfully!")
pprint(snmp_v3_trap.data)
pprint(SNMP_V3_TRAP.data)

# Delete Created Entry
snmp_v3_trap.delete(snmp_v3_trap)
SNMP_V3_TRAP.delete(SNMP_V3_TRAP)
print("\n## Delete appliance SNMPv3 trap destination successfully!")
Loading