|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +### |
| 3 | +# (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in |
| 13 | +# all copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | +# THE SOFTWARE. |
| 22 | +### |
| 23 | + |
| 24 | +from pprint import pprint |
| 25 | +from hpOneView.oneview_client import OneViewClient |
| 26 | +from config_loader import try_load_from_file |
| 27 | + |
| 28 | +config = { |
| 29 | + "ip": "<oneview_ip>", |
| 30 | + "credentials": { |
| 31 | + "userName": "<username>", |
| 32 | + "password": "<password>" |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +options = { |
| 37 | + "destination": "1.1.1.1", |
| 38 | + "communityString": "testOne", |
| 39 | + "port": 162 |
| 40 | +} |
| 41 | + |
| 42 | +# Try load config from a file (if there is a config file) |
| 43 | +config = try_load_from_file(config) |
| 44 | + |
| 45 | +oneview_client = OneViewClient(config) |
| 46 | + |
| 47 | +# Add appliance device SNMP v1 Trap Destination |
| 48 | +snmp_v1_trap = oneview_client.appliance_device_snmp_v1_trap_destinations.create(options) |
| 49 | +snmp_v1_trap_uri = snmp_v1_trap['uri'] |
| 50 | +print("\n## Create appliance SNMP v1 trap destination successfully!") |
| 51 | +pprint(snmp_v1_trap) |
| 52 | + |
| 53 | +# Add appliance device SNMP v1 Trap Destination with ID |
| 54 | +trap_id = 9 |
| 55 | +snmp_v1_trap = oneview_client.appliance_device_snmp_v1_trap_destinations.create(options, trap_id) |
| 56 | +print("\n## Create appliance SNMP v1 trap destination successfully!") |
| 57 | +pprint(snmp_v1_trap) |
| 58 | + |
| 59 | +# Lists the appliance device SNMP v1 Trap Destination |
| 60 | +snmp_v1_trap = oneview_client.appliance_device_snmp_v1_trap_destinations.get_all() |
| 61 | +print("\n## Got appliance SNMP v1 trap destination successfully!") |
| 62 | +pprint(snmp_v1_trap) |
| 63 | + |
| 64 | +# Lists the appliance device SNMP v1 Trap Destination by destination (unique) |
| 65 | +snmp_v1_trap = oneview_client.appliance_device_snmp_v1_trap_destinations.get_by('destination', '1.1.1.1') |
| 66 | +print("\n## Got appliance SNMP v1 trap by destination successfully!") |
| 67 | +pprint(snmp_v1_trap) |
| 68 | + |
| 69 | +# Get by URI |
| 70 | +print("Find an SNMP v1 trap destination by URI") |
| 71 | +snmp_v1_trap = oneview_client.appliance_device_snmp_v1_trap_destinations.get(snmp_v1_trap_uri) |
| 72 | +pprint(snmp_v1_trap) |
| 73 | + |
| 74 | +# Change appliance device SNMP v1 Trap Destination - Only Community String and Port can be changed |
| 75 | +snmp_v1_trap['communityString'] = 'testTwo' |
| 76 | +snmp_v1_trap = oneview_client.appliance_device_snmp_v1_trap_destinations.update(snmp_v1_trap) |
| 77 | +print("\n## Update appliance SNMP v1 trap destination successfully!") |
| 78 | +pprint(snmp_v1_trap) |
| 79 | + |
| 80 | +# Delete Created Entry |
| 81 | +del_result = oneview_client.appliance_device_snmp_v1_trap_destinations.delete(snmp_v1_trap) |
| 82 | +print("\n## Delete appliance SNMP v1 trap destination successfully!") |
| 83 | +pprint(del_result) |
0 commit comments