├── .coveragerc ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .nojekyll ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── deploy.sh ├── deploy_key.enc ├── docs └── source │ ├── conf.py │ └── index.rst ├── endpoints-support.md ├── examples ├── README.md ├── __init__.py ├── alert_util.py ├── alerts.py ├── appliance_device_read_community.py ├── appliance_device_snmp_v1_trap_destinations.py ├── appliance_device_snmp_v3_trap_destinations.py ├── appliance_device_snmp_v3_users.py ├── appliance_node_information.py ├── appliance_time_and_locale_configuration.py ├── backups.py ├── certificate_authority.py ├── certificate_rabbitmq.py ├── config-rename.json ├── config_loader.py ├── connection_templates.py ├── connections.py ├── datacenters.py ├── drive_enclosures.py ├── enclosure_groups.py ├── enclosures.py ├── endpoints.py ├── ethernet_networks.py ├── events.py ├── fabrics.py ├── fc_networks.py ├── fcoe_networks.py ├── firmware_bundles.py ├── firmware_drivers.py ├── id_pools.py ├── id_pools_ipv4_ranges.py ├── id_pools_ipv4_subnets.py ├── id_pools_vmac_ranges.py ├── id_pools_vsn_ranges.py ├── id_pools_vwwn_ranges.py ├── image_streamer │ ├── __init__.py │ ├── artifact_bundles.py │ ├── build_plans.py │ ├── deployment_groups.py │ ├── deployment_plans.py │ ├── golden_images.py │ ├── os_volumes.py │ └── plan_scripts.py ├── index_resources.py ├── interconnect_link_topologies.py ├── interconnect_types.py ├── interconnects.py ├── internal_link_sets.py ├── labels.py ├── licenses.py ├── logger.py ├── logical_downlinks.py ├── logical_enclosures.py ├── logical_interconnect_groups.py ├── logical_interconnects.py ├── logical_switch_groups.py ├── logical_switches.py ├── login_details.py ├── managed_sans.py ├── metric_streaming.py ├── migratable_vc_domains.py ├── network_sets.py ├── os_deployment_plans.py ├── os_deployment_servers.py ├── power_devices.py ├── racks.py ├── restores.py ├── roles.py ├── san_managers.py ├── sas_interconnect_types.py ├── sas_interconnects.py ├── sas_logical_interconnect_groups.py ├── sas_logical_interconnects.py ├── sas_logical_jbod_attachments.py ├── sas_logical_jbods.py ├── scmb │ ├── README │ ├── ov_to_sm.py │ └── scmb.py ├── scopes.py ├── server_hardware.py ├── server_hardware_types.py ├── server_profile_os_deployment.py ├── server_profile_templates.py ├── server_profiles.py ├── storage_pools.py ├── storage_pools_store_serv.py ├── storage_systems.py ├── storage_systems_API300.py ├── storage_volume_attachments.py ├── storage_volume_templates.py ├── storage_volume_templates_store_serv.py ├── switch_types.py ├── switches.py ├── tasks.py ├── unmanaged_devices.py ├── uplink_sets.py ├── user.py ├── versions.py ├── volumes.py └── volumes_store_serv.py ├── hpOneView ├── __init__.py ├── connection.py ├── exceptions.py ├── image_streamer │ ├── __init__.py │ ├── image_streamer_client.py │ └── resources │ │ ├── __init__.py │ │ ├── artifact_bundles.py │ │ ├── build_plans.py │ │ ├── deployment_groups.py │ │ ├── deployment_plans.py │ │ ├── golden_images.py │ │ ├── os_volumes.py │ │ └── plan_scripts.py ├── oneview_client.py └── resources │ ├── __init__.py │ ├── activity │ ├── __init__.py │ ├── alerts.py │ ├── events.py │ └── tasks.py │ ├── data_services │ ├── __init__.py │ └── metric_streaming.py │ ├── facilities │ ├── __init__.py │ ├── datacenters.py │ ├── power_devices.py │ └── racks.py │ ├── fc_sans │ ├── __init__.py │ ├── endpoints.py │ ├── managed_sans.py │ └── san_managers.py │ ├── networking │ ├── __init__.py │ ├── connection_templates.py │ ├── ethernet_networks.py │ ├── fabrics.py │ ├── fc_networks.py │ ├── fcoe_networks.py │ ├── interconnect_link_topologies.py │ ├── interconnect_types.py │ ├── interconnects.py │ ├── internal_link_sets.py │ ├── logical_downlinks.py │ ├── logical_interconnect_groups.py │ ├── logical_interconnects.py │ ├── logical_switch_groups.py │ ├── logical_switches.py │ ├── network_sets.py │ ├── sas_interconnect_types.py │ ├── sas_interconnects.py │ ├── sas_logical_interconnect_groups.py │ ├── sas_logical_interconnects.py │ ├── switch_types.py │ ├── switches.py │ └── uplink_sets.py │ ├── resource.py │ ├── search │ ├── __init__.py │ ├── index_resources.py │ └── labels.py │ ├── security │ ├── __init__.py │ ├── certificate_authority.py │ ├── certificate_rabbitmq.py │ ├── login_details.py │ ├── roles.py │ └── users.py │ ├── servers │ ├── __init__.py │ ├── connections.py │ ├── enclosure_groups.py │ ├── enclosures.py │ ├── id_pools.py │ ├── id_pools_ipv4_ranges.py │ ├── id_pools_ipv4_subnets.py │ ├── id_pools_ranges.py │ ├── logical_enclosures.py │ ├── migratable_vc_domains.py │ ├── server_hardware.py │ ├── server_hardware_types.py │ ├── server_profile_templates.py │ └── server_profiles.py │ ├── settings │ ├── __init__.py │ ├── appliance_device_read_community.py │ ├── appliance_device_snmp_v1_trap_destinations.py │ ├── appliance_device_snmp_v3_trap_destinations.py │ ├── appliance_device_snmp_v3_users.py │ ├── appliance_node_information.py │ ├── appliance_time_and_locale_configuration.py │ ├── backups.py │ ├── firmware_bundles.py │ ├── firmware_drivers.py │ ├── licenses.py │ ├── restores.py │ ├── scopes.py │ └── versions.py │ ├── storage │ ├── __init__.py │ ├── drive_enclosures.py │ ├── sas_logical_jbod_attachments.py │ ├── sas_logical_jbods.py │ ├── storage_pools.py │ ├── storage_systems.py │ ├── storage_volume_attachments.py │ ├── storage_volume_templates.py │ └── volumes.py │ ├── task_monitor.py │ └── uncategorized │ ├── __init__.py │ ├── os_deployment_plans.py │ ├── os_deployment_servers.py │ └── unmanaged_devices.py ├── requirements.txt ├── setup.cfg ├── setup.py ├── test_requirements.txt ├── tests ├── __init__.py ├── test_utils.py └── unit │ ├── __init__.py │ ├── image_streamer │ ├── __init__.py │ ├── resources │ │ ├── __init__.py │ │ ├── test_artifact_bundles.py │ │ ├── test_build_plans.py │ │ ├── test_deployment_groups.py │ │ ├── test_deployment_plans.py │ │ ├── test_golden_images.py │ │ ├── test_os_volumes.py │ │ └── test_plan_scripts.py │ └── test_image_streamer_client.py │ ├── resources │ ├── __init__.py │ ├── activity │ │ ├── __init__.py │ │ ├── test_alerts.py │ │ ├── test_events.py │ │ └── test_tasks.py │ ├── data_services │ │ ├── __init__.py │ │ └── test_metric_streaming.py │ ├── facilities │ │ ├── __init__.py │ │ ├── test_datacenters.py │ │ ├── test_power_devices.py │ │ └── test_racks.py │ ├── fc_sans │ │ ├── __init__.py │ │ ├── test_endpoints.py │ │ ├── test_managed_sans.py │ │ └── test_san_managers.py │ ├── networking │ │ ├── __init__.py │ │ ├── test_connection_templates.py │ │ ├── test_ethernet_networks.py │ │ ├── test_fabrics.py │ │ ├── test_fc_networks.py │ │ ├── test_fcoe_networks.py │ │ ├── test_interconnect_link_topologies.py │ │ ├── test_interconnect_types.py │ │ ├── test_interconnects.py │ │ ├── test_internal_link_sets.py │ │ ├── test_logical_downlinks.py │ │ ├── test_logical_interconnect_groups.py │ │ ├── test_logical_interconnects.py │ │ ├── test_logical_switch_groups.py │ │ ├── test_logical_switches.py │ │ ├── test_network_sets.py │ │ ├── test_sas_interconnect_types.py │ │ ├── test_sas_interconnects.py │ │ ├── test_sas_logical_interconnect_groups.py │ │ ├── test_sas_logical_interconnects.py │ │ ├── test_switch_types.py │ │ ├── test_switches.py │ │ └── test_uplink_sets.py │ ├── search │ │ ├── __init__.py │ │ ├── test_index_resources.py │ │ └── test_labels.py │ ├── security │ │ ├── __init__.py │ │ ├── test_certificate_authority.py │ │ ├── test_certificate_rabbitmq.py │ │ ├── test_login_details.py │ │ ├── test_roles.py │ │ └── test_users.py │ ├── servers │ │ ├── __init__.py │ │ ├── test_connections.py │ │ ├── test_enclosure_groups.py │ │ ├── test_enclosures.py │ │ ├── test_id_pools.py │ │ ├── test_id_pools_ipv4_ranges.py │ │ ├── test_id_pools_ipv4_subnets.py │ │ ├── test_id_pools_ranges.py │ │ ├── test_logical_enclosures.py │ │ ├── test_migratable_vc_domains.py │ │ ├── test_server_hardware.py │ │ ├── test_server_hardware_types.py │ │ ├── test_server_profile_templates.py │ │ └── test_server_profiles.py │ ├── settings │ │ ├── __init__.py │ │ ├── test_appliance_device_read_community.py │ │ ├── test_appliance_device_snmp_v1_trap_destinations.py │ │ ├── test_appliance_device_snmp_v3_trap_destinations.py │ │ ├── test_appliance_device_snmp_v3_users.py │ │ ├── test_appliance_node_information.py │ │ ├── test_appliance_time_and_locale_configuration.py │ │ ├── test_backups.py │ │ ├── test_firmware_bundles.py │ │ ├── test_firmware_drivers.py │ │ ├── test_licenses.py │ │ ├── test_restores.py │ │ ├── test_scopes.py │ │ └── test_versions.py │ ├── storage │ │ ├── __init__.py │ │ ├── test_drive_enclosures.py │ │ ├── test_sas_logical_jbod_attachments.py │ │ ├── test_sas_logical_jbods.py │ │ ├── test_storage_pools.py │ │ ├── test_storage_systems.py │ │ ├── test_storage_volume_attachments.py │ │ ├── test_storage_volume_templates.py │ │ └── test_volumes.py │ ├── test_resource.py │ ├── test_task_monitor.py │ └── uncategorized │ │ ├── __init__.py │ │ ├── test_os_deployment_plans.py │ │ ├── test_os_deployment_servers.py │ │ └── test_unmanaged_devices.py │ ├── test_connection.py │ ├── test_exceptions.py │ └── test_oneview_client.py └── tox.ini /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = *test* 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.py text eol=lf 2 | *.sh text eol=lf -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Scenario/Intent 2 | [What you are trying to achieve but can't?] 3 | 4 | ### Environment Details 5 | - **OneView SDK Version:** [Version of this SDK for which you are encountering the issue] 6 | - **OneView Appliance Version:** [Version of the OneView appliance you're interacting with] 7 | - **OneView Client API Version:** [API version listed in your configuration file or dictionary] 8 | - **Python Version:** [Version of Python in your environment] 9 | - **Platform:** [OS distribution and release version] 10 | 11 | ### Steps to Reproduce 12 | [What are the complete steps needed to do in order to reproduce your problem?] 13 | 14 | ### Expected Result 15 | [What do you *expect* to happen after taking the steps above?] 16 | 17 | ### Actual Result 18 | [What *actually* happens after the steps above? Include error output or a link to a gist.] 19 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Description 2 | [Describe what this change achieves] 3 | 4 | ### Issues Resolved 5 | [List any issues this PR will resolve. e.g., Fixes #01] 6 | 7 | ### Check List 8 | - [ ] New functionality includes testing. 9 | - [ ] All tests pass for Python 2.7+ & 3.4+(`$ tox`). 10 | - [ ] New functionality has been documented in the README if applicable. 11 | - [ ] New functionality has been thoroughly documented in the examples (please include helpful comments). 12 | - [ ] New endpoints supported are updated in the endpoints-support.md file. 13 | - [ ] Changes are documented in the CHANGELOG. 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Local Certificates 7 | *.pem 8 | 9 | # Packages 10 | *.egg 11 | *.egg-info 12 | dist 13 | build/* 14 | eggs 15 | parts 16 | bin 17 | var 18 | sdist 19 | develop-eggs 20 | .installed.cfg 21 | lib 22 | lib64 23 | __pycache__ 24 | 25 | # Rope 26 | .ropeproject/ 27 | 28 | 29 | # Installer logs 30 | pip-log.txt 31 | 32 | # Unit test / coverage reports 33 | .coverage 34 | .tox 35 | nosetests.xml 36 | htmlcov 37 | 38 | # Translations 39 | *.mo 40 | 41 | # Mr Developer 42 | .mr.developer.cfg 43 | .project 44 | .pydevproject 45 | 46 | #coverage 47 | coverage.xml 48 | .coverage 49 | htmlcov 50 | 51 | #virtualenv 52 | env 53 | 54 | #pycharm 55 | .idea 56 | .idea/ 57 | 58 | #Global configuration to run examples 59 | examples/config.json 60 | 61 | #sphinx generated files 62 | docs/build/* 63 | docs/source/* 64 | !docs/source/conf.py 65 | !docs/source/index.rst 66 | .vscode 67 | 68 | #certificate files 69 | *.crt 70 | -------------------------------------------------------------------------------- /.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/.nojekyll -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - 2.7 4 | - 3.6 5 | install: 6 | - pip install tox 7 | script: 8 | - tox 9 | - "./deploy.sh" 10 | 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 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 of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e # Exit with nonzero exit code if anything fails 3 | 4 | SOURCE_BRANCH="master" 5 | TARGET_BRANCH="gh-pages" 6 | 7 | # Pull requests and commits to other branches shouldn't try to deploy, just build to verify 8 | if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then 9 | echo "Skipping deploy; just doing a build." 10 | exit 0 11 | fi 12 | 13 | # Save some useful information 14 | REPO=`git config remote.origin.url` 15 | SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:} 16 | SHA=`git rev-parse --verify HEAD` 17 | 18 | # Clone the existing gh-pages for this repo into out/ 19 | # Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply) 20 | rm -rf out || exit 0 21 | 22 | git clone $REPO out 23 | cd out 24 | git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH 25 | cd .. 26 | 27 | 28 | # Clean out existing contents 29 | rm -rf out/**/* || exit 0 30 | 31 | # Copy generated documentation to the new directory 32 | cp -a docs/build/html/. out/ 33 | 34 | 35 | cd out 36 | git config user.name "Travis CI" 37 | git config user.email "oneview-pythonsdk@hpe.com" 38 | 39 | # If there are no changes (e.g. this is a README update) then just bail. 40 | if [ $(git status --porcelain | wc -l) -lt 1 ]; then 41 | echo "No changes to the spec on this push; exiting." 42 | exit 0 43 | fi 44 | 45 | # Commit the "changes", i.e. the new version. 46 | # The delta will show diffs between new and old versions. 47 | git add -A . 48 | git commit -m "Deploy to GitHub Pages: ${SHA}" 49 | 50 | 51 | ## Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc 52 | openssl aes-256-cbc -K $encrypted_207a3e71573a_key -iv $encrypted_207a3e71573a_iv -in deploy_key.enc -out deploy_key -d 53 | 54 | 55 | chmod 600 deploy_key 56 | 57 | eval `ssh-agent -s` 58 | 59 | ssh-add deploy_key 60 | 61 | 62 | ## Now that we're all set up, we can push. 63 | git push $SSH_REPO $TARGET_BRANCH 64 | 65 | echo "Documentation pushed to gh-pages ................................" 66 | cd .. 67 | rm -rf out || exit 0 68 | 69 | echo "Documentation deploy finished ..................................." 70 | -------------------------------------------------------------------------------- /deploy_key.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/deploy_key.enc -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. HPE OneView documentation master file, created by 2 | sphinx-quickstart on Wed Aug 10 09:44:28 2016. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | HPE OneView Python SDK Reference 7 | ======================================= 8 | 9 | The table of contents links to the SDK API specification for each resource type in the HPE OneView resource model. 10 | These API specifications are intended to provide all the details needed to call the HP OneView Python SDK APIs. 11 | 12 | * :ref:`modindex` 13 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | hpOneView - Examples 2 | ===================== 3 | 4 | 5 | You can use example files to see how to use the API and test 6 | functionality of individual resources. 7 | 8 | 9 | ### Prerequisites 10 | 11 | - hpOneView must be installed 12 | 13 | 14 | ### Configuration 15 | To use a common config for all examples, the file `config-rename.json` 16 | should be renamed to `config.json`. Otherwise you can set the connection 17 | config inside the example. 18 | 19 | :lock: Tip: Check the file permissions because the password is stored in clear-text. 20 | 21 | 22 | ### Running 23 | 24 | To run these examples follow the steps: 25 | 26 | - enter in the examples folder 27 | - run `python .py` 28 | -------------------------------------------------------------------------------- /examples/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/examples/__init__.py -------------------------------------------------------------------------------- /examples/appliance_device_read_community.py: -------------------------------------------------------------------------------- 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": "", 30 | "credentials": { 31 | "userName": "", 32 | "password": "" 33 | } 34 | } 35 | 36 | options = { 37 | "communityString": "public" 38 | } 39 | 40 | # Try load config from a file (if there is a config file) 41 | config = try_load_from_file(config) 42 | 43 | oneview_client = OneViewClient(config) 44 | 45 | # Lists the appliance device read community 46 | read_community = oneview_client.appliance_device_read_community.get() 47 | print("\n## Got appliance device read community successfully!") 48 | pprint(read_community) 49 | 50 | # Backup original values 51 | bkp = {} 52 | bkp['communityString'] = read_community['communityString'] 53 | 54 | # Update Read Community 55 | # Set to use appliance device read community 56 | read_community['communityString'] = options['communityString'] 57 | read_community = oneview_client.appliance_device_read_community.update(read_community) 58 | print("\n## Updated appliance device read community string successfully!") 59 | pprint(read_community) 60 | 61 | # Revert the changes made 62 | read_community['communityString'] = bkp['communityString'] 63 | read_community = oneview_client.appliance_device_read_community.update(read_community) 64 | print("\n## Reverted appliance device read community string successfully!") 65 | pprint(read_community) 66 | -------------------------------------------------------------------------------- /examples/appliance_device_snmp_v3_trap_destinations.py: -------------------------------------------------------------------------------- 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 | # Set api_version to 600, default is 300 and this API has been introduced since API 600. 29 | config = { 30 | "ip": "", 31 | "credentials": { 32 | "userName": "", 33 | "password": "" 34 | }, 35 | "api_version": 600 36 | } 37 | 38 | options = { 39 | "type": "Destination", 40 | "destinationAddress": "1.1.1.1", 41 | "userId": "a8cda396-584b-4b68-98a2-4ff9f4d3c01a", 42 | "port": 162 43 | } 44 | 45 | # Try load config from a file (if there is a config file) 46 | config = try_load_from_file(config) 47 | 48 | oneview_client = OneViewClient(config) 49 | 50 | # Add appliance device SNMP v3 Trap Destination 51 | snmp_v3_trap = oneview_client.appliance_device_snmp_v3_trap_destinations.create(options) 52 | snmp_v3_trap_uri = snmp_v3_trap['uri'] 53 | print("\n## Crate appliance SNMP v3 trap destination successfully!") 54 | pprint(snmp_v3_trap) 55 | 56 | # Lists the appliance device read community 57 | snmp_v3_trap_list = oneview_client.appliance_device_snmp_v3_trap_destinations.get_all() 58 | print("\n## Got appliance SNMP v3 trap destination successfully!") 59 | pprint(snmp_v3_trap_list) 60 | 61 | # Get first element of the List 62 | snmp_v3_trap = snmp_v3_trap_list.pop() 63 | 64 | # Get by URI 65 | print("Find an SNMP v3 trap destination by URI") 66 | snmp_v3_trap = oneview_client.appliance_device_snmp_v3_trap_destinations.get(snmp_v3_trap_uri) 67 | pprint(snmp_v3_trap) 68 | 69 | # Change appliance device SNMP v3 Trap Destination - Only Community String and Port can be changed 70 | snmp_v3_trap['destinationAddress'] = "1.1.9.9" 71 | snmp_v3_trap = oneview_client.appliance_device_snmp_v3_trap_destinations.update(snmp_v3_trap) 72 | print("\n## Update appliance SNMP v3 trap destination successfully!") 73 | pprint(snmp_v3_trap) 74 | 75 | # Delete Created Entry 76 | del_result = oneview_client.appliance_device_snmp_v1_trap_destinations.delete(snmp_v3_trap) 77 | print("\n## Delete appliance SNMP v3 trap destination successfully!") 78 | pprint(del_result) 79 | -------------------------------------------------------------------------------- /examples/appliance_device_snmp_v3_users.py: -------------------------------------------------------------------------------- 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 | # Set api_version to 600, default is 300 and this API has been introduced since API 600. 29 | config = { 30 | "ip": "", 31 | "credentials": { 32 | "userName": "", 33 | "password": "" 34 | }, 35 | "api_version": 600 36 | } 37 | 38 | options = { 39 | "type": "Users", 40 | "userName": "user1", 41 | "securityLevel": "Authentication and privacy", 42 | "authenticationProtocol": "SHA512", 43 | "authenticationPassphrase": "authPass", 44 | "privacyProtocol": "AES-256", 45 | "privacyPassphrase": "1234567812345678" 46 | } 47 | 48 | # Try load config from a file (if there is a config file) 49 | config = try_load_from_file(config) 50 | 51 | oneview_client = OneViewClient(config) 52 | 53 | # Add appliance device SNMP v3 users 54 | snmp_v3_user = oneview_client.appliance_device_snmp_v3_users.create(options) 55 | snmp_v3_user_uri = snmp_v3_user['uri'] 56 | print("\n## Create appliance SNMP v3 user successfully!") 57 | pprint(snmp_v3_user) 58 | 59 | # Lists the appliance SNMPv3 users 60 | snmp_v3_users_list = oneview_client.appliance_device_snmp_v3_users.get_all() 61 | print("\n## Got appliance SNMP v3 users successfully!") 62 | pprint(snmp_v3_users_list) 63 | 64 | # Get first element of the List 65 | snmp_v3_users = snmp_v3_users_list.pop() 66 | 67 | # Get by URI 68 | print("Find an SNMP v3 user by URI") 69 | snmp_v3_user = oneview_client.appliance_device_snmp_v3_users.get(snmp_v3_user_uri) 70 | pprint(snmp_v3_user) 71 | 72 | # Change appliance device SNMP v3 users 73 | snmp_v3_user['authenticationPassphrase'] = "newAuthPass" 74 | snmp_v3_user['privacyPassphrase'] = "8765432187654321" 75 | snmp_v3_user = oneview_client.appliance_device_snmp_v3_users.update(snmp_v3_user) 76 | print("\n## Update appliance SNMP v3 user successfully!") 77 | pprint(snmp_v3_user) 78 | 79 | # Delete Created Entry 80 | del_result = oneview_client.appliance_device_snmp_v3_users.delete(snmp_v3_user) 81 | print("\n## Delete appliance SNMP v3 user successfully!") 82 | pprint(del_result) 83 | -------------------------------------------------------------------------------- /examples/appliance_node_information.py: -------------------------------------------------------------------------------- 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": "", 30 | "credentials": { 31 | "userName": "", 32 | "password": "" 33 | } 34 | } 35 | 36 | # Try load config from a file (if there is a config file) 37 | config = try_load_from_file(config) 38 | 39 | oneview_client = OneViewClient(config) 40 | 41 | # Get node status information from appliance 42 | print("\nGet node status information from appliance:\n ") 43 | node_status = oneview_client.appliance_node_information.get_status() 44 | pprint(node_status) 45 | 46 | # Get node version information from appliance 47 | print("\nGet node version information from appliance\n") 48 | node_version = oneview_client.appliance_node_information.get_version() 49 | pprint(node_version) 50 | -------------------------------------------------------------------------------- /examples/appliance_time_and_locale_configuration.py: -------------------------------------------------------------------------------- 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": "", 30 | "credentials": { 31 | "userName": "", 32 | "password": "" 33 | } 34 | } 35 | 36 | # Try load config from a file (if there is a config file) 37 | config = try_load_from_file(config) 38 | 39 | oneview_client = OneViewClient(config) 40 | 41 | # Lists the appliance time and locale configuration 42 | time_and_locale = oneview_client.appliance_time_and_locale_configuration.get() 43 | print("\n## Got appliance time and locale configurations successfully!") 44 | pprint(time_and_locale) 45 | 46 | # Backup original values 47 | bkp = {} 48 | bkp['ntpServers'] = time_and_locale['ntpServers'] 49 | bkp['locale'] = time_and_locale['locale'] 50 | 51 | # Update NTP servers and locale 52 | # Set to use appliance local time and date server 53 | time_and_locale['ntpServers'] = ['127.0.0.1'] 54 | # Set locale to Chinese (China) with charset UTF-8 55 | time_and_locale['locale'] = 'zh_CN.UTF-8' 56 | # Remove the date and time, we do not want to update it manually 57 | time_and_locale.pop('dateTime') 58 | time_and_locale = oneview_client.appliance_time_and_locale_configuration.update(time_and_locale) 59 | print("\n## Updated appliance time and locale configurations successfully!") 60 | pprint(time_and_locale) 61 | 62 | # Note: Changing the locale will only be fully effective after resetting the appliance 63 | 64 | # Revert the changes made 65 | time_and_locale['ntpServers'] = bkp['ntpServers'] 66 | time_and_locale['locale'] = bkp['locale'] 67 | time_and_locale.pop('dateTime') 68 | time_and_locale = oneview_client.appliance_time_and_locale_configuration.update(time_and_locale) 69 | print("\n## Reverted appliance time and locale configurations successfully!") 70 | pprint(time_and_locale) 71 | -------------------------------------------------------------------------------- /examples/backups.py: -------------------------------------------------------------------------------- 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 hpOneView.exceptions import HPOneViewException 27 | from config_loader import try_load_from_file 28 | 29 | config = { 30 | "ip": "172.16.102.59", 31 | "credentials": { 32 | "userName": "administrator", 33 | "password": "" 34 | } 35 | } 36 | 37 | # Try load config from a file (if there is a config file) 38 | config = try_load_from_file(config) 39 | 40 | oneview_client = OneViewClient(config) 41 | 42 | # Create a new appliance backup 43 | print("\n## Create a new appliance backup") 44 | backup_details = oneview_client.backups.create() 45 | pprint(backup_details) 46 | 47 | filename = backup_details['id'] 48 | 49 | # Download the backup archive 50 | print("\n## Download the previously created backup archive") 51 | response = oneview_client.backups.download(backup_details['downloadUri'], filename) 52 | print(response) 53 | 54 | # Upload the backup archive 55 | print("\n## Upload the previously downloaded backup archive") 56 | backup_details = oneview_client.backups.upload(filename) 57 | pprint(backup_details) 58 | 59 | # Get by URI 60 | print("\n## Find recently created backup by URI") 61 | backup_by_uri = oneview_client.backups.get(backup_details['uri']) 62 | pprint(backup_by_uri) 63 | 64 | # Get all backups 65 | print("\n## Get all backups") 66 | backups = oneview_client.backups.get_all() 67 | pprint(backups) 68 | 69 | # Get the details of the backup configuration 70 | print("\n## Get the details of the backup configuration for the remote server and automatic backup schedule") 71 | config = oneview_client.backups.get_config() 72 | pprint(config) 73 | 74 | # Update the backup configuration 75 | try: 76 | print("\n## Update the backup configuration") 77 | config['scheduleTime'] = '23:00' 78 | updated_config = oneview_client.backups.update_config(config) 79 | pprint(updated_config) 80 | except HPOneViewException as e: 81 | print(e.msg) 82 | 83 | # Save the backup file to a previously-configured remote location 84 | try: 85 | print("\n## Save the backup file to a previously-configured remote location") 86 | backup_details = oneview_client.backups.update_remote_archive(backup_details['saveUri']) 87 | pprint(backup_details) 88 | except HPOneViewException as e: 89 | print(e.msg) 90 | -------------------------------------------------------------------------------- /examples/certificate_authority.py: -------------------------------------------------------------------------------- 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 | 26 | from config_loader import try_load_from_file 27 | from hpOneView.oneview_client import OneViewClient 28 | 29 | config = { 30 | "ip": "", 31 | "credentials": { 32 | "userName": "", 33 | "password": "" 34 | } 35 | } 36 | 37 | # Try load config from a file (if there is a config file) 38 | config = try_load_from_file(config) 39 | 40 | oneview_client = OneViewClient(config) 41 | 42 | # Retrieve Internal CA Certificate 43 | print('Get the internal Certificate Authority:') 44 | certificate = oneview_client.certificate_authority.get() 45 | pprint(certificate) 46 | 47 | # Retrieve Certificate Revocation List 48 | print("Getting the Certificate Revocation List") 49 | certificate_visual_content = oneview_client.certificate_authority.get_crl() 50 | pprint(certificate_visual_content) 51 | 52 | # Revoke Internal CA Signed Certificate 53 | print("Revoking Internal CA Signed Certificate") 54 | success = oneview_client.certificate_authority.delete("default") 55 | print(success) 56 | 57 | # Regenerate Certificates 58 | print("Regenerating Certificates") 59 | success = oneview_client.certificate_authority.delete("rabbitmq_readonly") 60 | print(success) 61 | -------------------------------------------------------------------------------- /examples/certificate_rabbitmq.py: -------------------------------------------------------------------------------- 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 | 26 | from config_loader import try_load_from_file 27 | from hpOneView.exceptions import HPOneViewException 28 | from hpOneView.oneview_client import OneViewClient 29 | 30 | config = { 31 | "ip": "", 32 | "credentials": { 33 | "userName": "", 34 | "password": "" 35 | } 36 | } 37 | 38 | # Try load config from a file (if there is a config file) 39 | config = try_load_from_file(config) 40 | 41 | oneview_client = OneViewClient(config) 42 | 43 | certificate_ca_signed_client = { 44 | "commonName": "default", 45 | "type": "RabbitMqClientCertV2" 46 | } 47 | 48 | certificate_self_signed_client = { 49 | "commonName": "any", 50 | "signedCert": "false", 51 | "type": "RabbitMqClientCertV2" 52 | } 53 | 54 | 55 | # Generate a CA Signed Certificate 56 | print('Generate a CA Signed Certificate') 57 | try: 58 | response = oneview_client.certificate_rabbitmq.generate(certificate_ca_signed_client) 59 | pprint(response) 60 | except HPOneViewException as e: 61 | print (e.msg) 62 | if e.oneview_response: 63 | print e.oneview_response.get('recommendedActions') 64 | 65 | 66 | # Generate a Self Signed Certificate 67 | print('\nGenerate a Self Signed Certificate') 68 | try: 69 | response = oneview_client.certificate_rabbitmq.generate(certificate_self_signed_client) 70 | pprint(response) 71 | except HPOneViewException as e: 72 | print (e.msg) 73 | if e.oneview_response: 74 | print e.oneview_response.get('recommendedActions') 75 | 76 | 77 | # Get by Alias Name 78 | print('\nGet by Alias Name') 79 | response = oneview_client.certificate_rabbitmq.get('default') 80 | pprint(response) 81 | 82 | 83 | # Get a Key Pair 84 | print('\nGet a Key Pair') 85 | response = oneview_client.certificate_rabbitmq.get_key_pair('default') 86 | pprint(response) 87 | 88 | 89 | # Get Keys in Base64 format 90 | print('\nGet Keys in Base64 format') 91 | response = oneview_client.certificate_rabbitmq.get_keys('default', 'Base64') 92 | pprint(response) 93 | 94 | 95 | # Get Keys in PKCS12 format 96 | print('\nGet Keys in PKCS12 format') 97 | response = oneview_client.certificate_rabbitmq.get_keys('default', 'PKCS12') 98 | pprint(response) 99 | -------------------------------------------------------------------------------- /examples/config-rename.json: -------------------------------------------------------------------------------- 1 | { 2 | "ip": "172.16.102.59", 3 | "image_streamer_ip": "172.16.102.60", 4 | "api_version": 500, 5 | "ssl_certificate": "", 6 | "credentials": { 7 | "userName": "administrator", 8 | "authLoginDomain": "", 9 | "password": "", 10 | "sessionID": "" 11 | }, 12 | "enclosure_hostname": "172.18.1.13", 13 | "enclosure_username": "", 14 | "enclosure_password": "", 15 | "enclosure_group_uri": "", 16 | "server_hostname": "", 17 | "server_username": "", 18 | "server_password": "", 19 | "storage_system_hostname": "", 20 | "storage_system_username": "", 21 | "storage_system_password": "", 22 | "power_device_hostname": "", 23 | "power_device_username": "", 24 | "power_device_password": "" 25 | } 26 | -------------------------------------------------------------------------------- /examples/config_loader.py: -------------------------------------------------------------------------------- 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 | from __future__ import absolute_import 24 | from __future__ import division 25 | from __future__ import print_function 26 | from __future__ import unicode_literals 27 | 28 | from future import standard_library 29 | 30 | standard_library.install_aliases() 31 | 32 | import json 33 | import os 34 | 35 | CUR_MODULE_DIR = os.path.dirname(__file__) 36 | DEFAULT_EXAMPLE_CONFIG_FILE = os.path.join(CUR_MODULE_DIR, 'config.json') 37 | 38 | 39 | def try_load_from_file(config, file_name=None): 40 | if not file_name: 41 | file_name = DEFAULT_EXAMPLE_CONFIG_FILE 42 | 43 | if not os.path.isfile(file_name): 44 | return config 45 | 46 | with open(file_name) as json_data: 47 | return json.load(json_data) 48 | -------------------------------------------------------------------------------- /examples/connections.py: -------------------------------------------------------------------------------- 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 hpOneView.exceptions import HPOneViewException 27 | from config_loader import try_load_from_file 28 | 29 | # You can use username/password or sessionID for authentication. 30 | # Be sure to inform a valid and active sessionID. 31 | config = { 32 | "ip": "", 33 | "credentials": { 34 | "userName": "", 35 | "password": "", 36 | "sessionID": "" 37 | } 38 | } 39 | 40 | 41 | # Try load config from a file (if there is a config file) 42 | config = try_load_from_file(config) 43 | 44 | oneview_client = OneViewClient(config) 45 | 46 | # Get all connections 47 | print("Get all connections") 48 | cons = oneview_client.connections.get_all() 49 | pprint(cons) 50 | 51 | # Get all connections with interconnectUri filter 52 | try: 53 | print("Get connections based on interconnect uri") 54 | filter = "interconnectUri='/rest/interconnects/794079a2-7eb4-4992-8027-e9743a40f5b0'" 55 | cons_interconnectUri = oneview_client.connections.get_all(filter=filter) 56 | pprint(cons_interconnectUri) 57 | except HPOneViewException as e: 58 | print(e.msg) 59 | 60 | # Get first 10 connections, sorted by name 61 | print("Get first 10 connections, sorting by name") 62 | cons_sorted = oneview_client.connections.get_all(0, 10, sort='name:descending') 63 | pprint(cons_sorted) 64 | 65 | # Find connection by name 66 | try: 67 | print("Get connection by name") 68 | con_byName = oneview_client.connections.get_by( 69 | 'name', "name981375475-1465399560370") 70 | pprint(con_byName) 71 | except HPOneViewException as e: 72 | print(e.msg) 73 | 74 | 75 | # Get by Uri 76 | try: 77 | print("Get connection by uri") 78 | con_byUri = oneview_client.connections.get( 79 | '/rest/connections/58ffb307-3087-4c9d-8574-44e8a79e0d6e') 80 | pprint(con_byUri) 81 | except HPOneViewException as e: 82 | print(e.msg) 83 | -------------------------------------------------------------------------------- /examples/datacenters.py: -------------------------------------------------------------------------------- 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 | 26 | from config_loader import try_load_from_file 27 | from hpOneView.oneview_client import OneViewClient 28 | 29 | config = { 30 | "ip": "", 31 | "credentials": { 32 | "userName": "", 33 | "password": "" 34 | } 35 | } 36 | 37 | # Try load config from a file (if there is a config file) 38 | config = try_load_from_file(config) 39 | 40 | oneview_client = OneViewClient(config) 41 | 42 | datacenter_information = { 43 | "name": "MyDatacenter", 44 | "width": 5000, "depth": 5000 45 | } 46 | 47 | # Add a Datacenter 48 | datacenter_added = oneview_client.datacenters.add(datacenter_information) 49 | print("\nAdded Datacenter '{name}' successfully\n".format(**datacenter_added)) 50 | 51 | # Retrieve Datacenter by URI 52 | datacenter = oneview_client.datacenters.get(datacenter_added['uri']) 53 | print("\nGet Datacenter by URI: retrieved '{name}' successfully\n".format(**datacenter)) 54 | 55 | # Update the Datacenter 56 | datacenter['name'] = "New Datacenter Name" 57 | datacenter = oneview_client.datacenters.update(datacenter) 58 | print("\nDatacenter '{name}' updated successfully\n".format(**datacenter)) 59 | 60 | # Get the Datacenter by name 61 | datacenter_list = oneview_client.datacenters.get_by('name', "New Datacenter Name") 62 | print("\nGet Datacenter device by name: '{name}'\n".format(**datacenter)) 63 | 64 | # Get the Datacenter visual content 65 | print("Getting the Datacenter visual content...") 66 | datacenter_visual_content = oneview_client.datacenters.get_visual_content(datacenter['uri']) 67 | pprint(datacenter_visual_content) 68 | 69 | # Remove added Datacenter 70 | oneview_client.datacenters.remove(datacenter) 71 | print("\nSuccessfully removed the datacenter") 72 | 73 | # Add a datacenter again and call Remove All 74 | datacenter_added = oneview_client.datacenters.add(datacenter_information) 75 | oneview_client.datacenters.remove_all(filter="name matches '%'") 76 | print("\nSuccessfully removed all datacenters") 77 | -------------------------------------------------------------------------------- /examples/drive_enclosures.py: -------------------------------------------------------------------------------- 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 | # This resource is only available on HPE Synergy 29 | 30 | config = { 31 | "ip": "", 32 | "credentials": { 33 | "userName": "", 34 | "password": "" 35 | } 36 | } 37 | 38 | # Try load config from a file (if there is a config file) 39 | config = try_load_from_file(config) 40 | oneview_client = OneViewClient(config) 41 | 42 | print("Get all drive enclosures") 43 | drive_enclosures = oneview_client.drive_enclosures.get_all() 44 | pprint(drive_enclosures) 45 | 46 | if drive_enclosures: 47 | 48 | first_drive_enclosure = drive_enclosures[0] 49 | drive_enclosure_uri = first_drive_enclosure["uri"] 50 | 51 | print("\nGet the drive enclosure by URI") 52 | drive_enclosure_by_uri = oneview_client.drive_enclosures.get(drive_enclosure_uri) 53 | pprint(drive_enclosure_by_uri) 54 | 55 | product_name = first_drive_enclosure['productName'] 56 | 57 | print("\nGet the drive enclosure by product name") 58 | drive_enclosure_by_product_name = oneview_client.drive_enclosures.get_by('productName', product_name) 59 | pprint(drive_enclosure_by_product_name) 60 | 61 | print("\nGet the drive enclosure port map") 62 | port_map = oneview_client.drive_enclosures.get_port_map(drive_enclosure_uri) 63 | pprint(port_map) 64 | 65 | print("\nRefresh the drive enclosure") 66 | refresh_config = dict(refreshState="RefreshPending") 67 | refreshed_drive_enclosure = oneview_client.drive_enclosures.refresh_state(drive_enclosure_uri, refresh_config) 68 | pprint(refreshed_drive_enclosure) 69 | 70 | print("\nPower off a drive enclosure") 71 | drive_enclosure_powered_off = oneview_client.drive_enclosures.patch( 72 | id_or_uri=drive_enclosure_uri, 73 | operation="replace", 74 | path="/powerState", 75 | value="Off" 76 | ) 77 | pprint(drive_enclosure_powered_off) 78 | -------------------------------------------------------------------------------- /examples/endpoints.py: -------------------------------------------------------------------------------- 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 | 26 | from config_loader import try_load_from_file 27 | from hpOneView.oneview_client import OneViewClient 28 | 29 | config = { 30 | "ip": "", 31 | "credentials": { 32 | "userName": "", 33 | "password": "", 34 | } 35 | } 36 | 37 | # To run this example, you must specify a WWN 38 | wwn = None 39 | 40 | # Try load config from a file (if there is a config file) 41 | config = try_load_from_file(config) 42 | 43 | oneview_client = OneViewClient(config) 44 | 45 | # Get all endpoints 46 | print("Get all endpoints") 47 | endpoints_all = oneview_client.endpoints.get_all() 48 | pprint(endpoints_all) 49 | 50 | # Get endpoints filtered to only the one with a specified WWN 51 | print("Get endpoints filtered to only the one with a specified WWN") 52 | query = "wwn eq '{}'".format(wwn) 53 | enpoints_with_query = oneview_client.endpoints.get_all(0, -1, query=query) 54 | pprint(enpoints_with_query) 55 | -------------------------------------------------------------------------------- /examples/events.py: -------------------------------------------------------------------------------- 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 hpOneView.oneview_client import OneViewClient 25 | from config_loader import try_load_from_file 26 | 27 | config = { 28 | "ip": "", 29 | "credentials": { 30 | "userName": "administrator", 31 | "password": "" 32 | } 33 | } 34 | 35 | options = { 36 | "description": "This is a very simple test event", 37 | "serviceEventSource": "true", 38 | "serviceEventDetails": { 39 | "caseId": "1234", 40 | "primaryContact": "contactDetails", 41 | "remoteSupportState": "Submitted" 42 | }, 43 | "severity": "OK", 44 | "healthCategory": "PROCESSOR", 45 | "eventTypeID": "hp.justATest", 46 | "rxTime": "2012-05-14T20:23:56.688Z", 47 | "urgency": "None", 48 | "eventDetails": 49 | [{"eventItemName": "ipv4Address", 50 | "eventItemValue": "198.51.100.5", 51 | "isThisVarbindData": "false", 52 | "varBindOrderIndex": -1}] 53 | } 54 | 55 | # Try load config from a file (if there is a config file) 56 | config = try_load_from_file(config) 57 | 58 | _client = OneViewClient(config) 59 | 60 | # Getting the first 5 events 61 | print("\nGetting the first 5 events:") 62 | events = _client.events.get_all(0, 5) 63 | for event in events: 64 | print("eventTypeID: '%s' | description: %s " % (event['description'], event['eventTypeID'])) 65 | 66 | # Create an Event 67 | event = _client.events.create(options) 68 | print("\nCreated event successfully.\n uri = '%s'" % (event['uri'])) 69 | 70 | # Get by Uri 71 | print("\nFind uri == %s" % ('/rest/events/24')) 72 | event_by_uri = _client.events.get('/rest/events/24') 73 | print("uri: '%s' | eventTypeID: '%s' \n" % (event_by_uri['uri'], event_by_uri['eventTypeID'])) 74 | 75 | # Filter by state 76 | print("\nGet all events filtering by eventTypeID") 77 | events = _client.events.get_all(filter="\"eventTypeID='StatusPoll.EnclosureStatus'\"", count=10) 78 | for event in events: 79 | print("uri: '%s' | eventTypeID: '%s'" % (event['uri'], event['eventTypeID'])) 80 | -------------------------------------------------------------------------------- /examples/fabrics.py: -------------------------------------------------------------------------------- 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 | 26 | from config_loader import try_load_from_file 27 | from hpOneView.exceptions import HPOneViewException 28 | from hpOneView.oneview_client import OneViewClient 29 | 30 | config = { 31 | "ip": "", 32 | "credentials": { 33 | "userName": "", 34 | "password": "" 35 | } 36 | } 37 | 38 | # To run the get operations by ID, an ID must be defined bellow 39 | fabric_id = 'a7896ce7-c11d-4658-829d-142bc66a85e4' 40 | 41 | # Try load config from a file (if there is a config file) 42 | config = try_load_from_file(config) 43 | 44 | oneview_client = OneViewClient(config) 45 | 46 | # Get all fabrics 47 | print("Get all fabrics") 48 | fabrics = oneview_client.fabrics.get_all() 49 | pprint(fabrics) 50 | 51 | # Get all sorting by name descending 52 | print("\nGet all fabrics sorting by name") 53 | fabrics_sorted = oneview_client.fabrics.get_all(sort='name:descending') 54 | pprint(fabrics_sorted) 55 | 56 | # Get by Id 57 | try: 58 | print("\nGet a fabric by id") 59 | fabrics_byid = oneview_client.fabrics.get(fabric_id) 60 | pprint(fabrics_byid) 61 | except HPOneViewException as e: 62 | print(e.msg) 63 | 64 | # Get by name 65 | print("\nGet a fabrics by name") 66 | fabric_byname = oneview_client.fabrics.get_by('name', 'DefaultFabric')[0] 67 | pprint(fabric_byname) 68 | 69 | # These methods are available for API version 300 or later 70 | if oneview_client.api_version >= 300: 71 | # Get reserved vlan ID range for the fabric. 72 | print("\nGet reserved vlan ID range for the fabric '%s'." % fabric_byname['name']) 73 | vlan_pool = oneview_client.fabrics.get_reserved_vlan_range(fabric_byname['uri']) 74 | pprint(vlan_pool) 75 | 76 | # Update the reserved vlan ID range for the fabric 77 | vlan_pool_data = { 78 | "start": 100, 79 | "length": 100 80 | } 81 | print("\nUpdate the reserved vlan ID range for the fabric '%s'." % fabric_byname['name']) 82 | fabric_byname = oneview_client.fabrics.update_reserved_vlan_range(fabric_byname['uri'], vlan_pool_data) 83 | pprint(fabric_byname) 84 | -------------------------------------------------------------------------------- /examples/firmware_bundles.py: -------------------------------------------------------------------------------- 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 | 26 | from config_loader import try_load_from_file 27 | from hpOneView.oneview_client import OneViewClient 28 | 29 | config = { 30 | "ip": "", 31 | "credentials": { 32 | "userName": "", 33 | "password": "" 34 | } 35 | } 36 | 37 | # To run this example you must define a path to a valid file 38 | firmware_path = "" 39 | 40 | # Try load config from a file (if there is a config file) 41 | config = try_load_from_file(config) 42 | oneview_client = OneViewClient(config) 43 | 44 | # Upload a firmware bundle 45 | print("\nUpload a firmware bundle") 46 | firmware_bundle_information = oneview_client.firmware_bundles.upload(file_path=firmware_path) 47 | print("\n Upload successful! Firmware information returned: \n") 48 | pprint(firmware_bundle_information) 49 | -------------------------------------------------------------------------------- /examples/id_pools_ipv4_ranges.py: -------------------------------------------------------------------------------- 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": "", 30 | "credentials": { 31 | "userName": "administrator", 32 | "password": "" 33 | } 34 | } 35 | 36 | # Try load config from a file (if there is a config file) 37 | config = try_load_from_file(config) 38 | 39 | oneview_client = OneViewClient(config) 40 | 41 | options = { 42 | "type": "Range", 43 | "name": "IPv4", 44 | "rangeCategory": "Custom", 45 | "startAddress": "10.10.2.2", 46 | "endAddress": "10.10.2.254", 47 | "subnetUri": "/rest/id-pools/ipv4/subnets/7e77926c-195c-4984-926d-c858fde63f9b" 48 | } 49 | 50 | print("\n Create an IPv4 Range for id pools") 51 | ipv4_range = oneview_client.id_pools_ipv4_ranges.create(options) 52 | pprint(ipv4_range) 53 | 54 | print("\n Update the IPv4 Range") 55 | ipv4_range['name'] = 'New Name' 56 | ipv4_range = oneview_client.id_pools_ipv4_ranges.update(ipv4_range) 57 | pprint(ipv4_range) 58 | 59 | print("\n Get the IPv4 range by uri") 60 | ipv4_range_byuri = oneview_client.id_pools_ipv4_ranges.get(ipv4_range['uri']) 61 | pprint(ipv4_range_byuri) 62 | 63 | print("\n Enable an IPv4 range") 64 | ipv4_range = oneview_client.id_pools_ipv4_ranges.enable( 65 | { 66 | "type": "Range", 67 | "enabled": True 68 | }, 69 | ipv4_range['uri']) 70 | print(" IPv4 range enabled successfully.") 71 | 72 | print("\n Get all allocated fragments in IPv4 range") 73 | allocated_fragments = oneview_client.id_pools_ipv4_ranges.get_allocated_fragments(ipv4_range['uri']) 74 | pprint(allocated_fragments) 75 | 76 | print("\n Get all free fragments in IPv4 range") 77 | allocated_fragments = oneview_client.id_pools_ipv4_ranges.get_free_fragments(ipv4_range['uri']) 78 | pprint(allocated_fragments) 79 | 80 | print("\n Disable an IPv4 range") 81 | ipv4_range = oneview_client.id_pools_ipv4_ranges.enable({ 82 | "type": "Range", 83 | "enabled": False 84 | }, ipv4_range['uri']) 85 | print(" IPv4 range disabled successfully.") 86 | 87 | print("\n Delete the IPv4_range") 88 | oneview_client.id_pools_ipv4_ranges.delete(ipv4_range) 89 | print(" Successfully deleted IPv4 range") 90 | -------------------------------------------------------------------------------- /examples/id_pools_ipv4_subnets.py: -------------------------------------------------------------------------------- 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": "", 30 | "credentials": { 31 | "userName": "administrator", 32 | "password": "" 33 | } 34 | } 35 | 36 | # Try load config from a file (if there is a config file) 37 | config = try_load_from_file(config) 38 | 39 | oneview_client = OneViewClient(config) 40 | 41 | options = { 42 | "type": "Subnet", 43 | "name": "IPv4Subnet", 44 | "networkId": '10.10.1.0', 45 | "subnetmask": "255.255.255.0", 46 | "gateway": "10.10.1.1", 47 | "domain": "example.com", 48 | "dnsServers": ["10.10.10.215"] 49 | } 50 | 51 | print('\n Create IPv4 subnet for id pools') 52 | ipv4_subnet = oneview_client.id_pools_ipv4_subnets.create(options) 53 | pprint(ipv4_subnet) 54 | 55 | print('\n Update IPv4 subnet for id pools') 56 | ipv4_subnet['name'] = 'Changed Name' 57 | ipv4_subnet = oneview_client.id_pools_ipv4_subnets.update(ipv4_subnet) 58 | 59 | print('\n Get IPv4 subnet by uri') 60 | ipv4_subnet_byuri = oneview_client.id_pools_ipv4_subnets.get(ipv4_subnet['uri']) 61 | pprint(ipv4_subnet_byuri) 62 | 63 | print('\n Get all IPv4 subnet') 64 | all_subnets = oneview_client.id_pools_ipv4_subnets.get_all() 65 | pprint(all_subnets) 66 | 67 | print('\n Delete IPv4 subnet') 68 | oneview_client.id_pools_ipv4_subnets.delete(ipv4_subnet) 69 | print(" Successfully deleted IPv4 subnet") 70 | -------------------------------------------------------------------------------- /examples/image_streamer/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/examples/image_streamer/__init__.py -------------------------------------------------------------------------------- /examples/image_streamer/build_plans.py: -------------------------------------------------------------------------------- 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 | import os 25 | from pprint import pprint 26 | from hpOneView.oneview_client import OneViewClient 27 | 28 | EXAMPLE_CONFIG_FILE = os.path.join(os.path.dirname(__file__), '../config.json') 29 | 30 | oneview_client = OneViewClient.from_json_file(EXAMPLE_CONFIG_FILE) 31 | 32 | image_streamer_client = oneview_client.create_image_streamer_client() 33 | 34 | build_plan_information = { 35 | "name": "Demo Build Plan", 36 | "oeBuildPlanType": "deploy" 37 | } 38 | 39 | # Create a Build Plan 40 | print("Create an OS Build Plan") 41 | build_plan_created = image_streamer_client.build_plans.create(build_plan_information) 42 | pprint(build_plan_created) 43 | 44 | # Update the Build Plan 45 | print("\nUpdate the OS Build Plan") 46 | build_plan_created["name"] = "Demo Build Plan - Renamed" 47 | build_plan_updated = image_streamer_client.build_plans.update(build_plan_created) 48 | pprint(build_plan_updated) 49 | 50 | # Get the Build Plan by URI 51 | print("\nGet the OS Build Plan by URI") 52 | build_plan_by_uri = image_streamer_client.build_plans.get(build_plan_updated['uri']) 53 | pprint(build_plan_by_uri) 54 | 55 | # Get all Build Plans 56 | print("\nGet all OS Build Plans") 57 | build_plans = image_streamer_client.build_plans.get_all() 58 | for build_plan in build_plans: 59 | print(build_plan['name']) 60 | 61 | # Delete the Build Plan 62 | print("\nDelete the OS Build Plan") 63 | image_streamer_client.build_plans.delete(build_plan_by_uri) 64 | print("OS Build Plan deleted successfully") 65 | -------------------------------------------------------------------------------- /examples/image_streamer/deployment_groups.py: -------------------------------------------------------------------------------- 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 | import os 25 | from pprint import pprint 26 | from hpOneView.oneview_client import OneViewClient 27 | 28 | EXAMPLE_CONFIG_FILE = os.path.join(os.path.dirname(__file__), '../config.json') 29 | 30 | oneview_client = OneViewClient.from_json_file(EXAMPLE_CONFIG_FILE) 31 | 32 | image_streamer_client = oneview_client.create_image_streamer_client() 33 | 34 | deployment_groups_information = { 35 | "name": "OSS", 36 | "id": "57f2d803-9c11-4f9a-bc02-71804a0fcc3e" 37 | } 38 | 39 | 40 | # Get all Deployment Groups 41 | print("\nGet all Deployment Groups") 42 | deployment_groups = image_streamer_client.deployment_groups.get_all() 43 | for deployment_group in deployment_groups: 44 | pprint(deployment_group) 45 | 46 | 47 | # Get the Deployment Group by ID 48 | print("\nGet the Deployment Group by ID") 49 | response = image_streamer_client.deployment_groups.get(deployment_groups_information['id']) 50 | pprint(response) 51 | 52 | 53 | # Get the Deployment Group by Name 54 | print("\nGet the Deployment Group by Name") 55 | response = image_streamer_client.deployment_groups.get_by_name(deployment_groups_information['name']) 56 | pprint(response) 57 | -------------------------------------------------------------------------------- /examples/image_streamer/os_volumes.py: -------------------------------------------------------------------------------- 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 | import os 25 | from pprint import pprint 26 | from hpOneView.oneview_client import OneViewClient 27 | 28 | EXAMPLE_CONFIG_FILE = os.path.join(os.path.dirname(__file__), '../config.json') 29 | 30 | oneview_client = OneViewClient.from_json_file(EXAMPLE_CONFIG_FILE) 31 | 32 | image_streamer_client = oneview_client.create_image_streamer_client() 33 | 34 | os_volumes_information = { 35 | "name": "OSVolume-5", 36 | "id": "57f2d803-9c11-4f9a-bc02-71804a0fcc3e" 37 | } 38 | destination_archive_path = './archive_log.txt' 39 | 40 | # Get all OS Volumes 41 | print("\nGet all OS Volumes") 42 | os_volumes = image_streamer_client.os_volumes.get_all() 43 | for os_volume in os_volumes: 44 | pprint(os_volume) 45 | 46 | 47 | # Get the OS Volume by ID 48 | print("\nGet the OS Volumes by ID") 49 | os_volume = image_streamer_client.os_volumes.get(os_volumes_information['id']) 50 | pprint(os_volume) 51 | 52 | 53 | # Get the OS Volume by Name 54 | print("\nGet the OS Volumes by Name") 55 | os_volume = image_streamer_client.os_volumes.get_by_name(os_volumes_information['name']) 56 | pprint(os_volume) 57 | 58 | # Get storage details (available only with API version 600 and above) 59 | print("Get storage details") 60 | storage = image_streamer_client.os_volumes.get_storage(os_volumes_information['id']) 61 | pprint(storage) 62 | 63 | # Retrieve archived logs of the OS Volume 64 | print("Retrieve archived logs of the OS Volume") 65 | if image_streamer_client.os_volumes.download_archive(os_volume['name'], destination_archive_path): 66 | print(" File downloaded successfully.") 67 | else: 68 | print(" Error downloading the file.") 69 | -------------------------------------------------------------------------------- /examples/index_resources.py: -------------------------------------------------------------------------------- 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 | from pprint import pprint 24 | 25 | from hpOneView.oneview_client import OneViewClient 26 | from config_loader import try_load_from_file 27 | 28 | config = { 29 | "ip": "", 30 | "credentials": { 31 | "userName": "", 32 | "password": "" 33 | } 34 | } 35 | 36 | attribute = 'Model' 37 | category = 'server-hardware' 38 | 39 | # Try load config from a file (if there is a config file) 40 | config = try_load_from_file(config) 41 | 42 | oneview_client = OneViewClient(config) 43 | 44 | print('\nGetting all index resources:') 45 | index_resources = oneview_client.index_resources.get_all() 46 | pprint(index_resources) 47 | 48 | sh = oneview_client.server_hardware.get_all()[0] 49 | print('\nGetting index resource for server hardware with uri "{0}":'.format(sh['uri'])) 50 | index_resource = oneview_client.index_resources.get(sh['uri']) 51 | pprint(index_resource) 52 | 53 | print('\nGetting aggregated index resources with attribute: "{0}" and category: "{1}"'.format(attribute, category)) 54 | index_resources = oneview_client.index_resources.get_aggregated(attribute, category) 55 | pprint(index_resources) 56 | -------------------------------------------------------------------------------- /examples/interconnect_link_topologies.py: -------------------------------------------------------------------------------- 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 | import re 26 | from hpOneView.oneview_client import OneViewClient 27 | from config_loader import try_load_from_file 28 | 29 | # This resource is only available on HPE Synergy 30 | 31 | config = { 32 | "ip": "", 33 | "credentials": { 34 | "userName": "administrator", 35 | "password": "" 36 | } 37 | } 38 | 39 | # Try load config from a file (if there is a config file) 40 | config = try_load_from_file(config) 41 | 42 | oneview_client = OneViewClient(config) 43 | 44 | # Get all interconnect link topologies 45 | print("Get all interconnect link topologies") 46 | interconnect_link_topologies = oneview_client.interconnect_link_topologies.get_all() 47 | pprint(interconnect_link_topologies) 48 | 49 | # Get all sorting by name descending 50 | print("Get all interconnect link topologies sorting by name") 51 | interconnect_link_topologies_sorted = oneview_client.interconnect_link_topologies.get_all(sort='name:descending') 52 | pprint(interconnect_link_topologies_sorted) 53 | 54 | # Get by uri 55 | if interconnect_link_topologies: 56 | print("Get an interconnect link topology by uri") 57 | ilt_uri = interconnect_link_topologies[0]['uri'] 58 | ilt_byuri = oneview_client.interconnect_link_topologies.get(ilt_uri) 59 | print(" Found '{name}' at uri: {uri}".format(**ilt_byuri)) 60 | 61 | # Get by Id 62 | if interconnect_link_topologies: 63 | print("Get an interconnect link topology by id") 64 | ilt_id = re.sub("/rest/interconnect-link-topologies/", '', interconnect_link_topologies[0]['uri']) 65 | ilt_byid = oneview_client.interconnect_link_topologies.get(ilt_id) 66 | print(" Found '{name}' at uri: {uri}".format(**ilt_byid)) 67 | 68 | # Get by name 69 | if interconnect_link_topologies: 70 | print("Get an interconnect link topology by name") 71 | ilt_byname = oneview_client.interconnect_link_topologies.get_by( 72 | 'name', interconnect_link_topologies[0]['name'])[0] 73 | print(" Found '{name}' at uri: {uri}".format(**ilt_byname)) 74 | -------------------------------------------------------------------------------- /examples/interconnect_types.py: -------------------------------------------------------------------------------- 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 hpOneView.exceptions import HPOneViewException 27 | from config_loader import try_load_from_file 28 | 29 | config = { 30 | "ip": "", 31 | "credentials": { 32 | "userName": "administrator", 33 | "password": "" 34 | } 35 | } 36 | 37 | # Try load config from a file (if there is a config file) 38 | config = try_load_from_file(config) 39 | 40 | oneview_client = OneViewClient(config) 41 | 42 | # Get all supported interconnect types 43 | print("Get all supported interconnect types") 44 | interconnect_types = oneview_client.interconnect_types.get_all() 45 | pprint(interconnect_types, depth=2) 46 | 47 | # Get all sorting by name descending 48 | print("Get all interconnect-types sorting by name") 49 | interconnect_types_sorted = oneview_client.interconnect_types.get_all( 50 | sort='name:descending') 51 | pprint(interconnect_types_sorted, depth=2) 52 | 53 | # Get by Id 54 | try: 55 | print("Get an interconnect_type by id") 56 | interconnect_types_byid = oneview_client.interconnect_types.get( 57 | 'e28949fa-8681-433d-9808-a9146feb8048') 58 | pprint(interconnect_types_byid, depth=1) 59 | except HPOneViewException as e: 60 | print(e.msg) 61 | 62 | # Get by name 63 | try: 64 | print("Get an interconnect_type by name") 65 | interconnect_type_byname = oneview_client.interconnect_types.get_by( 66 | 'name', 'HP VC Flex-10 Enet Module')[0] 67 | pprint(interconnect_type_byname, depth=1) 68 | except HPOneViewException as e: 69 | print(e.msg) 70 | -------------------------------------------------------------------------------- /examples/internal_link_sets.py: -------------------------------------------------------------------------------- 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": "", 30 | "credentials": { 31 | "userName": "", 32 | "password": "", 33 | } 34 | } 35 | 36 | # Try load config from a file (if there is a config file) 37 | config = try_load_from_file(config) 38 | 39 | oneview_client = OneViewClient(config) 40 | 41 | # Get all, with defaults 42 | print("Get all internal-link-sets") 43 | internal_links = oneview_client.internal_link_sets.get_all() 44 | pprint(internal_links) 45 | 46 | internal_link_set_uri = internal_links[0]['uri'] 47 | internal_link_set_name = internal_links[0]['name'] 48 | 49 | # Get by Uri 50 | print("\nGet a internal-link-set by uri") 51 | internal_links_by_uri = oneview_client.internal_link_sets.get(internal_link_set_uri) 52 | pprint(internal_links_by_uri) 53 | 54 | # Find by name 55 | internal_links_by_name = oneview_client.internal_link_sets.get_by('name', internal_link_set_name) 56 | print("\nFound the internal-link-sets by name: '{}':".format(internal_links_by_name[0]['name'])) 57 | -------------------------------------------------------------------------------- /examples/labels.py: -------------------------------------------------------------------------------- 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 | from pprint import pprint 24 | 25 | from hpOneView.oneview_client import OneViewClient 26 | from config_loader import try_load_from_file 27 | 28 | config = { 29 | "ip": "172.16.102.59", 30 | "credentials": { 31 | "userName": "administrator", 32 | "password": "" 33 | } 34 | } 35 | 36 | # Try load config from a file (if there is a config file) 37 | config = try_load_from_file(config) 38 | 39 | oneview_client = OneViewClient(config) 40 | 41 | resource_uri = "/rest/enclosures/09SGH100X6J1" 42 | 43 | print("\nSet the labels assigned to a resource") 44 | labels_to_create = dict( 45 | resourceUri=resource_uri, 46 | labels=["labelSample2", "enclosureDemo"] 47 | ) 48 | 49 | resource_labels = oneview_client.labels.create(labels_to_create) 50 | pprint(resource_labels) 51 | 52 | print("\nUpdate the resource labels") 53 | labels_to_update = dict( 54 | uri="/rest/labels/resources/" + resource_uri, 55 | resourceUri=resource_uri, 56 | type="ResourceLabels", 57 | labels=[ 58 | dict(name="new label"), 59 | dict(name="enclosureDemo") 60 | ] 61 | ) 62 | updated_resource_labels = oneview_client.labels.update(labels_to_update) 63 | pprint(updated_resource_labels) 64 | 65 | print("\nGet all labels") 66 | all_labels = oneview_client.labels.get_all() 67 | pprint(all_labels) 68 | 69 | label_uri = all_labels[0]["uri"] 70 | 71 | print("\nGet a label by uri") 72 | label_by_uri = oneview_client.labels.get(label_uri) 73 | pprint(label_by_uri) 74 | 75 | print("\nGet all the labels for the resource %s" % resource_uri) 76 | labels_by_resource = oneview_client.labels.get_by_resource(resource_uri) 77 | pprint(labels_by_resource) 78 | 79 | print("\nDelete all the labels for a resource") 80 | oneview_client.labels.delete(dict(uri="/rest/labels/resources/" + resource_uri)) 81 | print("Done!") 82 | -------------------------------------------------------------------------------- /examples/licenses.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ### 3 | # (C) Copyright (2012-2018) 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 config_loader import try_load_from_file 25 | from hpOneView.oneview_client import OneViewClient 26 | from pprint import pprint 27 | 28 | config = { 29 | "ip": "", 30 | "credentials": { 31 | "userName": "", 32 | "password": "" 33 | } 34 | } 35 | 36 | 37 | # Try load config from a file (if there is a config file) 38 | config = try_load_from_file(config) 39 | oneview_client = OneViewClient(config) 40 | 41 | # Example license Key 42 | # ACDE B9MA H9PY CHW3 U7B5 HWW5 Y9JL KMPL B89H MZVU DXAU 2CSM GHTG L762 KQL7 EG5M KJVT D5KM AFVW TT5J F77K NXWW BPSM YF26 28JS EWTZ X36Q 43 | # M5G7 WZJL HH5Q L975 SNJT 288F ADT2 LK44 56UG V8MC 2K9X 7KG2 F6AD EMVA 9GEB 95Y6 XBM3 HVDY LBSS PU24 KEWY JSJC FPZC 2JJE 44 | # ZLAB\"24R2-02192-002 T1111A HP_OneView_w/o_iLO_Explicit_Feature J4E8IAMANEON\" 45 | 46 | options = { 47 | "key": "", 48 | "type": "LicenseV500" 49 | } 50 | 51 | # Add a License 52 | license = oneview_client.licenses.create(options) 53 | print("\n\nLicense added '%s' successfully.\n" % license['key']) 54 | 55 | # Get all licenses 56 | print("\n\n\n\n ********** Displaying all the Licenses loaded on the appliance: ********** \n\n\n\n") 57 | licenses = oneview_client.licenses.get_all() 58 | pprint(licenses) 59 | 60 | # Get License by ID 61 | uri = license['uri'] 62 | print uri 63 | print("\n License fetched by ID is: \n") 64 | license = oneview_client.licenses.get_by_id(uri) 65 | pprint(license) 66 | 67 | # Delete License by ID 68 | print ("\n\n ********** Delete the license by ID: **********") 69 | print uri 70 | oneview_client.licenses.delete(uri) 71 | 72 | print("\n Check if the license is Deleted: \n") 73 | lic = oneview_client.licenses.get_by_id(uri) 74 | pprint(lic) 75 | -------------------------------------------------------------------------------- /examples/login_details.py: -------------------------------------------------------------------------------- 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": "", 30 | "credentials": { 31 | "userName": "", 32 | "password": "" 33 | } 34 | } 35 | 36 | # Try load config from a file (if there is a config file) 37 | config = try_load_from_file(config) 38 | 39 | oneview_client = OneViewClient(config) 40 | 41 | print("\n Querying system for login details\n") 42 | login_detail = oneview_client.login_details.get_login_details() 43 | 44 | print("\n Login details are: \n") 45 | pprint(login_detail) 46 | -------------------------------------------------------------------------------- /examples/metric_streaming.py: -------------------------------------------------------------------------------- 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 | 26 | from config_loader import try_load_from_file 27 | from hpOneView.oneview_client import OneViewClient 28 | 29 | config = { 30 | "ip": "", 31 | "credentials": { 32 | "userName": "", 33 | "password": "" 34 | } 35 | } 36 | # Try load config from a file (if there is a config file) 37 | config = try_load_from_file(config) 38 | 39 | oneview_client = OneViewClient(config) 40 | 41 | metrics_configuration = { 42 | "sourceTypeList": [ 43 | { 44 | "sourceType": "/rest/power-devices", 45 | "sampleIntervalInSeconds": "300", 46 | "frequencyOfRelayInSeconds": "3600" 47 | }, 48 | { 49 | "sourceType": "/rest/enclosures", 50 | "sampleIntervalInSeconds": "600", 51 | "frequencyOfRelayInSeconds": "3600" 52 | }, 53 | { 54 | "sourceType": "/rest/server-hardware", 55 | "sampleIntervalInSeconds": "600", 56 | "frequencyOfRelayInSeconds": "1800" 57 | }, 58 | ] 59 | } 60 | 61 | # Configure metric relay for server-hardware, enclosures and power-devices. 62 | print("Configure metric streaming") 63 | updated_metrics_configuration = oneview_client.metric_streaming.update_configuration(metrics_configuration) 64 | pprint(updated_metrics_configuration) 65 | 66 | # Get current relay configuration 67 | print("Get current configuration") 68 | current_configuration = oneview_client.metric_streaming.get_configuration() 69 | pprint(current_configuration) 70 | 71 | # Gets the list of all supported metrics and resource types. 72 | print("Gets the list of all supported metrics and resource types") 73 | supported_metrics = oneview_client.metric_streaming.get_capability() 74 | pprint(supported_metrics) 75 | -------------------------------------------------------------------------------- /examples/os_deployment_plans.py: -------------------------------------------------------------------------------- 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 | 26 | from config_loader import try_load_from_file 27 | from hpOneView.oneview_client import OneViewClient 28 | 29 | config = { 30 | "ip": "", 31 | "credentials": { 32 | "userName": "", 33 | "password": "" 34 | } 35 | } 36 | 37 | # To run this example you must define an OS Deployment Plan ID 38 | os_deployment_plan_id = "81decf85-0dff-4a5e-8a95-52994eeb6493" 39 | 40 | # Try load config from a file (if there is a config file) 41 | config = try_load_from_file(config) 42 | 43 | oneview_client = OneViewClient(config) 44 | 45 | print("\nGet OS Deployment Plans by Filter:") 46 | os_deployment_plans = oneview_client.os_deployment_plans.get_by('deploymentType', 'I3S') 47 | pprint(os_deployment_plans) 48 | 49 | print("\nGet the OS Deployment Plan by Name:") 50 | os_deployment_plans = oneview_client.os_deployment_plans.get_by_name('Deployment Plan') 51 | pprint(os_deployment_plans) 52 | 53 | print("\nGet all OS Deployment Plans:") 54 | os_deployment_plans_all = oneview_client.os_deployment_plans.get_all() 55 | pprint(os_deployment_plans_all) 56 | 57 | print("\nGet an OS Deployment Plan by ID:") 58 | os_deployment_plan = oneview_client.os_deployment_plans.get(os_deployment_plan_id) 59 | pprint(os_deployment_plan) 60 | -------------------------------------------------------------------------------- /examples/restores.py: -------------------------------------------------------------------------------- 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": "172.16.102.59", 30 | "credentials": { 31 | "userName": "administrator", 32 | "password": "123456" 33 | } 34 | } 35 | 36 | # Try load config from a file (if there is a config file) 37 | config = try_load_from_file(config) 38 | 39 | oneview_client = OneViewClient(config) 40 | 41 | # A Uri for a backup to restore must be set to run this example 42 | uri_of_backup_to_restore = "/rest/backups/example_backup_2017-04-25_195515" 43 | 44 | # Start a restore 45 | print("Starting a restore") 46 | options = { 47 | "uriOfBackupToRestore": uri_of_backup_to_restore 48 | } 49 | restore = oneview_client.restores.restore(options) 50 | pprint(restore) 51 | 52 | # Get all restores 53 | print("Get all Restores") 54 | restores = oneview_client.restores.get_all() 55 | pprint(restores) 56 | 57 | # Get by 58 | print("\nGet a Restore by hostName equals to '{}'".format(restore['hostName'])) 59 | restore_by_host_name = oneview_client.restores.get_by("hostName", restore['hostName']) 60 | pprint(restore_by_host_name) 61 | 62 | # Get by URI 63 | print("\nGet a Restore by URI") 64 | restore_by_uri = oneview_client.restores.get(restore['uri']) 65 | pprint(restore_by_uri) 66 | 67 | # Get Restore Failure 68 | print("\nRetrieving Restore Failure") 69 | failures = oneview_client.restores.get_failure() 70 | pprint(failures) 71 | -------------------------------------------------------------------------------- /examples/roles.py: -------------------------------------------------------------------------------- 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 | from pprint import pprint 24 | 25 | from hpOneView.oneview_client import OneViewClient 26 | from config_loader import try_load_from_file 27 | 28 | config = { 29 | "ip": "172.16.102.59", 30 | "credentials": { 31 | "userName": "administrator", 32 | "password": "" 33 | } 34 | } 35 | 36 | # Try load config from a file (if there is a config file) 37 | config = try_load_from_file(config) 38 | 39 | oneview_client = OneViewClient(config) 40 | 41 | print ('Get role by name:') 42 | role = oneview_client.roles.get('Infrastructure administrator') 43 | pprint(role) 44 | 45 | print ('\nGet role by URI:') 46 | role = oneview_client.roles.get('/rest/roles/Infrastructure administrator') 47 | pprint(role) 48 | 49 | print ('\nGet all roles:') 50 | roles = oneview_client.roles.get_all() 51 | pprint(roles) 52 | -------------------------------------------------------------------------------- /examples/sas_interconnect_types.py: -------------------------------------------------------------------------------- 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 | # This resource is only available on HPE Synergy 29 | 30 | config = { 31 | "ip": "", 32 | "credentials": { 33 | "userName": "", 34 | "password": "" 35 | } 36 | } 37 | 38 | # Try load config from a file (if there is a config file) 39 | config = try_load_from_file(config) 40 | 41 | oneview_client = OneViewClient(config) 42 | 43 | # Get all 44 | print("\nGet all SAS Interconnect Types") 45 | sas_interconnect_types = oneview_client.sas_interconnect_types.get_all() 46 | pprint(sas_interconnect_types) 47 | 48 | if sas_interconnect_types: 49 | # Get by URI 50 | print("\nGet a SAS Interconnect Type by URI") 51 | uri = sas_interconnect_types[0]['uri'] 52 | sas_interconnect_type_by_uri = oneview_client.sas_interconnect_types.get(uri) 53 | pprint(sas_interconnect_type_by_uri) 54 | 55 | # Get by name 56 | print("\nGet a SAS Interconnect Type by name") 57 | name = sas_interconnect_types[0]['name'] 58 | sas_interconnect_type_by_name = oneview_client.sas_interconnect_types.get_by('name', name) 59 | pprint(sas_interconnect_type_by_name) 60 | -------------------------------------------------------------------------------- /examples/sas_logical_jbod_attachments.py: -------------------------------------------------------------------------------- 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 | # This resource is only available on HPE Synergy 29 | 30 | config = { 31 | "ip": "", 32 | "credentials": { 33 | "userName": "", 34 | "password": "" 35 | } 36 | } 37 | 38 | # Try load config from a file (if there is a config file) 39 | config = try_load_from_file(config) 40 | 41 | oneview_client = OneViewClient(config) 42 | 43 | # Get all 44 | print("\nGet all SAS logical JBOD attachments") 45 | sas_logical_jbod_attachments = oneview_client.sas_logical_jbod_attachments.get_all() 46 | pprint(sas_logical_jbod_attachments) 47 | 48 | if sas_logical_jbod_attachments: 49 | # Get by URI 50 | print("\nGet a SAS logical JBOD attachment by URI") 51 | uri = sas_logical_jbod_attachments[0]['uri'] 52 | sas_logical_jbod_attachment_by_uri = oneview_client.sas_logical_jbod_attachments.get(uri) 53 | pprint(sas_logical_jbod_attachment_by_uri) 54 | 55 | # Get by name 56 | print("\nGet a SAS logical JBOD attachment by name") 57 | name = sas_logical_jbod_attachments[0]['name'] 58 | sas_logical_jbod_attachment_by_name = oneview_client.sas_logical_jbod_attachments.get_by('name', name) 59 | pprint(sas_logical_jbod_attachment_by_name) 60 | -------------------------------------------------------------------------------- /examples/sas_logical_jbods.py: -------------------------------------------------------------------------------- 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 | # This resource is only available on HPE Synergy 29 | 30 | config = { 31 | "ip": "", 32 | "credentials": { 33 | "userName": "", 34 | "password": "" 35 | } 36 | } 37 | 38 | # Try load config from a file (if there is a config file) 39 | config = try_load_from_file(config) 40 | 41 | oneview_client = OneViewClient(config) 42 | 43 | print("\nGet all SAS logical JBODs") 44 | all_sas_logical_jbods = oneview_client.sas_logical_jbods.get_all() 45 | pprint(all_sas_logical_jbods) 46 | 47 | if all_sas_logical_jbods: 48 | 49 | sas_logical_jbod_uri = all_sas_logical_jbods[0]["uri"] 50 | 51 | print("\nGet the SAS logical JBOD by uri") 52 | sas_logical_jbod_by_uri = oneview_client.sas_logical_jbods.get(id_or_uri=sas_logical_jbod_uri) 53 | pprint(sas_logical_jbod_by_uri) 54 | 55 | print("\nGet the list of drives allocated to this SAS logical JBOD") 56 | drives = oneview_client.sas_logical_jbods.get_drives(id_or_uri=sas_logical_jbod_uri) 57 | pprint(drives) 58 | -------------------------------------------------------------------------------- /examples/scmb/README: -------------------------------------------------------------------------------- 1 | These sample scripts demonstrate the functionality of connecting HPE OneView with 2 | external applications. Specifically, this example generate tickets in HPE Service 3 | Manager based on critical alerts received from HPE OneView's State-Change Message 4 | Bus and then annotates the alert in HPE OneView with the new ticket information 5 | received from HPE Service Manager. 6 | 7 | In HPE OneView the State-Change Message Bus (SCMB) is an interface that uses 8 | asynchronous messaging to notify subscribers of changes to managed resources, 9 | both logical and physical. For example, you can program applications to receive 10 | notifications when new server hardware is added to the managed environment or 11 | when the health status of physical resources changes—without having to 12 | continuously poll the appliance for status using the REST APIs. 13 | 14 | HPE OneView resources publish messages to the SCMB when they are created, 15 | updated, or deleted. The message content is sent in JSON (JavaScript Object 16 | Notation) format and includes the resource model. To view the list of HPE OneView 17 | resources that publish messages, see the HPE OneView REST API Reference. 18 | 19 | Two sample scripts are provided to demonstrate connectivity to the HPE OneView 20 | SCMB. Both of the example scripts use the external AMQP library. The first 21 | script, scmb.py, receives all SCMB messages in the alerts "resource-category" 22 | and will output all new, active alerts with a critical severity to the console. 23 | The second script, ov_to_sm.py, is an extension of the first script. Once a new 24 | critical alert is received this script will connect to HPE Service Manager and 25 | open a new ticket for the critical alert, it then takes the ticket number that 26 | was just created in HPE Service Manager and updates the Alert Notes field in HPE 27 | OneView with the ticket information. 28 | 29 | In order for either of the scripts to register and listen on the SCMB a couple 30 | of thing need to happen first. 31 | 32 | #1. The HPE OneView appliance needs to generate a Rabbit MQ keypair. This does 33 | not happen by default and must be done ONE TIME for the running HPE OneView 34 | appliance. If either of the example scripts is run with the “-g” argument it 35 | will request that the keypair is generated and exit. This only needs to be done 36 | 1 time for each HPE OneView appliance. 37 | 38 | #2. The script needs to download a copy of the SSL key and certificate. If 39 | either of the example scripts is run with the “-d” option it will download the 40 | required key and certificate. Again, this only needs to be done one time for the 41 | script. 42 | 43 | For Example: assuming, you have a brand new HPE OneView appliance invocation 44 | would be similar to this: 45 | 46 | # Generate the RabbitMQ keypair on the appliance 47 | 48 | ./scmb.py -a [HPE OneView Appliance IP] -u Administrator -p MyPass -g 49 | 50 | # Download the SSL key and certificate 51 | 52 | ./scmb.py -a [HPE OneView Appliance IP] -u Administrator -p MyPass -d 53 | 54 | Once those two commands have run one time: 55 | 56 | The scmby.py scrip can be invoked by: 57 | 58 | ./scmb.py -a [HPE OneView Appliance IP] -u Administrator -p MyPass 59 | 60 | The ov_to_sm.py script can be invoked by: 61 | 62 | ./ov_to_sm.py -a [HPE OneView Appliance IP] -u Administrator -p MyPass -sm [SM IP] -x [SM Password] 63 | -------------------------------------------------------------------------------- /examples/switch_types.py: -------------------------------------------------------------------------------- 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 hpOneView.exceptions import HPOneViewException 27 | from config_loader import try_load_from_file 28 | 29 | config = { 30 | "ip": "", 31 | "credentials": { 32 | "userName": "", 33 | "password": "" 34 | } 35 | } 36 | 37 | # Try load config from a file (if there is a config file) 38 | config = try_load_from_file(config) 39 | 40 | oneview_client = OneViewClient(config) 41 | 42 | # Add the ID of the switch to be retrieved 43 | switch_id = 'd017f9e4-e967-42ee-aacc-d6ad5797a175' 44 | 45 | # Get all supported switch types 46 | print("\nGet all supported switch types:") 47 | switch_types = oneview_client.switch_types.get_all() 48 | pprint(switch_types, depth=2) 49 | 50 | # Get all sorting by name descending 51 | print("\nGet all switch-types sorting by name:") 52 | switch_types_sorted = oneview_client.switch_types.get_all( 53 | sort='name:descending') 54 | pprint(switch_types_sorted, depth=2) 55 | 56 | # Get by Id 57 | try: 58 | print("\nGet a switch_types by id:") 59 | switch_types_byid = oneview_client.switch_types.get(switch_id) 60 | pprint(switch_types_byid, depth=1) 61 | except HPOneViewException as e: 62 | print(e.msg) 63 | 64 | # Get by name 65 | print("\nGet a switch_types by name:") 66 | switch_type_byname = oneview_client.switch_types.get_by( 67 | 'name', switch_types[0]['name'])[0] 68 | pprint(switch_type_byname, depth=1) 69 | -------------------------------------------------------------------------------- /examples/tasks.py: -------------------------------------------------------------------------------- 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 hpOneView.exceptions import HPOneViewException 27 | from config_loader import try_load_from_file 28 | 29 | config = { 30 | "ip": "172.16.102.59", 31 | "credentials": { 32 | "userName": "administrator", 33 | "password": "" 34 | } 35 | } 36 | 37 | # Try load config from a file (if there is a config file) 38 | config = try_load_from_file(config) 39 | 40 | oneview_client = OneViewClient(config) 41 | 42 | # Getting the first 5 tasks 43 | print("Getting the first 5 tasks") 44 | tasks = oneview_client.tasks.get_all(0, 5) 45 | pprint(tasks) 46 | 47 | # Get a specific task 48 | print("Get a specific task") 49 | try: 50 | tasks = oneview_client.tasks.get("36BD6806-71CD-4F1B-AA12-5E3E67379659") 51 | pprint(tasks) 52 | except HPOneViewException as e: 53 | print(e.msg) 54 | 55 | # Get a tree of tasks with specified filter 56 | print("Get a tree of tasks") 57 | tasks = oneview_client.tasks.get_all(filter="\"taskState='Completed'\"", view="tree", count=10) 58 | pprint(tasks) 59 | -------------------------------------------------------------------------------- /examples/unmanaged_devices.py: -------------------------------------------------------------------------------- 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 | 26 | from config_loader import try_load_from_file 27 | from hpOneView.oneview_client import OneViewClient 28 | 29 | config = { 30 | "ip": "", 31 | "credentials": { 32 | "userName": "", 33 | "password": "" 34 | } 35 | } 36 | 37 | # Try load config from a file (if there is a config file) 38 | config = try_load_from_file(config) 39 | 40 | oneview_client = OneViewClient(config) 41 | 42 | unmanaged_device_information = { 43 | "name": "MyUnmanagedDevice", 44 | "model": "Procurve 4200VL", 45 | "deviceType": "Server" 46 | } 47 | 48 | # Add an Unmanaged Device 49 | unmanaged_device_added = oneview_client.unmanaged_devices.add(unmanaged_device_information) 50 | print('Added Unmanaged Device "{name}" successfully\n'.format(**unmanaged_device_added)) 51 | 52 | # Retrieve Unmanaged Device by URI 53 | unmanaged_device = oneview_client.unmanaged_devices.get(unmanaged_device_added['uri']) 54 | print('Get unmanaged device by URI, retrieved "{name}" successfully\n'.format(**unmanaged_device)) 55 | 56 | # Update the Unmanaged Device 57 | unmanaged_device['name'] = "New Unmanaged Device Name" 58 | unmanaged_device = oneview_client.unmanaged_devices.update(unmanaged_device) 59 | print('Unmanaged Device "{name}" updated successfully\n'.format(**unmanaged_device)) 60 | 61 | # Get all Unmanaged Devices 62 | print("Get all Unmanaged Devices:") 63 | unmanaged_devices_all = oneview_client.unmanaged_devices.get_all() 64 | for unm_dev in unmanaged_devices_all: 65 | print(" - " + unm_dev['name']) 66 | 67 | # Get unmanaged device environmental configuration 68 | env_config = oneview_client.unmanaged_devices.get_environmental_configuration(unmanaged_device_added['uri']) 69 | print('Get Environmental Configuration result:') 70 | pprint(env_config) 71 | 72 | # Remove added unmanaged device 73 | oneview_client.unmanaged_devices.remove(unmanaged_device_added) 74 | print("Successfully removed the unmanaged device") 75 | 76 | # Add another unmanaged device and remove all 77 | unmanaged_device_added = oneview_client.unmanaged_devices.add(unmanaged_device_information) 78 | oneview_client.unmanaged_devices.remove_all("name matches '%'") 79 | print("Successfully removed all the unmanaged device") 80 | -------------------------------------------------------------------------------- /examples/user.py: -------------------------------------------------------------------------------- 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": "", 30 | "credentials": { 31 | "userName": "", 32 | "password": "" 33 | } 34 | } 35 | 36 | options = { 37 | 'emailAddress': 'testUser@example.com', 38 | 'enabled': 'true', 39 | 'fullName': 'testUser101', 40 | 'mobilePhone': '555-2121', 41 | 'officePhone': '555-1212', 42 | 'password': 'myPass1234', 43 | 'roles': ['Read only'], 44 | 'type': 'UserAndRoles', 45 | 'userName': 'testUser' 46 | } 47 | 48 | # Try load config from a file (if there is a config file) 49 | config = try_load_from_file(config) 50 | 51 | oneview_client = OneViewClient(config) 52 | 53 | # Create a User 54 | user = oneview_client.users.create(options) 55 | print("Created user '%s' successfully.\n uri = '%s'\n" % (user['userName'], user['uri'])) 56 | 57 | # Adds different roles to the recently created user 58 | user = oneview_client.users.get_by('userName', 'testUser') 59 | print(user) 60 | print("\n user: %s, roles before update: %s" % (user['userName'], user['roles'])) 61 | user['replaceRoles'] = True 62 | user['roles'] = ['Infrastructure administrator'] 63 | user = oneview_client.users.update(user) 64 | print("\n user: %s, roles after update: %s" % (user['userName'], user['roles'])) 65 | 66 | # Get user by role 67 | user = oneview_client.users.get_by('role', 'Read only') 68 | print("Found users by role: '%s'.\n '\n" % (user)) 69 | 70 | # Get user by name 71 | user = oneview_client.users.get_by('userName', 'testUser') 72 | print("Found user by name: '%s'. uri = '%s'\n" % (user['userName'], user['uri'])) 73 | 74 | # Get all users 75 | print("Get all users") 76 | users = oneview_client.users.get_all() 77 | pprint(users) 78 | 79 | # # Validates if full name is already in use 80 | bol = oneview_client.users.validate_full_name(options['fullName']) 81 | print("Is full name already in use? %s" % (bol)) 82 | 83 | # # Validates if user name is already in use 84 | bol = oneview_client.users.validate_user_name(options['userName']) 85 | print("Is user name already in use? %s" % (bol)) 86 | 87 | # Delete the created user 88 | oneview_client.users.delete(user) 89 | print("\nSuccessfully deleted user") 90 | -------------------------------------------------------------------------------- /examples/versions.py: -------------------------------------------------------------------------------- 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": "", 30 | "credentials": { 31 | "userName": "", 32 | "password": "" 33 | } 34 | } 35 | 36 | # Try load config from a file (if there is a config file) 37 | config = try_load_from_file(config) 38 | 39 | oneview_client = OneViewClient(config) 40 | 41 | # Get the current version and the minimum version 42 | print("Get the current version and the minimum version") 43 | version = oneview_client.versions.get_version() 44 | pprint(version) 45 | -------------------------------------------------------------------------------- /hpOneView/image_streamer/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/image_streamer/__init__.py -------------------------------------------------------------------------------- /hpOneView/image_streamer/resources/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/image_streamer/resources/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/activity/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/activity/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/data_services/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/data_services/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/facilities/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/facilities/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/fc_sans/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/fc_sans/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/fc_sans/endpoints.py: -------------------------------------------------------------------------------- 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 __future__ import absolute_import 25 | from __future__ import division 26 | from __future__ import print_function 27 | from __future__ import unicode_literals 28 | 29 | from future import standard_library 30 | 31 | standard_library.install_aliases() 32 | 33 | 34 | from hpOneView.resources.resource import ResourceClient 35 | 36 | 37 | class Endpoints(object): 38 | """ 39 | Endpoints API client. 40 | 41 | """ 42 | URI = '/rest/fc-sans/endpoints' 43 | 44 | def __init__(self, con): 45 | self._connection = con 46 | self._client = ResourceClient(con, self.URI) 47 | 48 | def get_all(self, start=0, count=-1, query='', sort=''): 49 | """ 50 | Retrieves the list of endpoints known by the appliance. 51 | 52 | Args: 53 | start: 54 | The first item to return, using 0-based indexing. 55 | If not specified, the default is 0 - start with the first available item. 56 | count: 57 | The number of resources to return. A count of -1 requests all items. The actual number of items in 58 | the response may differ from the requested count if the sum of start and count exceed the total number 59 | of items. 60 | query: 61 | A general query string to narrow the list of resources returned. 62 | The default is no query - all resources are returned. 63 | sort: 64 | The sort order of the returned data set. By default, the sort order is based 65 | on create time with the oldest entry first. 66 | 67 | Returns: 68 | list: The endpoints known by the appliance. 69 | """ 70 | return self._client.get_all(start=start, count=count, query=query, sort=sort) 71 | -------------------------------------------------------------------------------- /hpOneView/resources/networking/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/networking/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/search/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/search/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/security/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/security/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/security/certificate_authority.py: -------------------------------------------------------------------------------- 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 __future__ import absolute_import 25 | from __future__ import division 26 | from __future__ import print_function 27 | from __future__ import unicode_literals 28 | 29 | from future import standard_library 30 | 31 | standard_library.install_aliases() 32 | 33 | from hpOneView.resources.resource import ResourceClient 34 | 35 | 36 | class CertificateAuthority(object): 37 | """ 38 | Certificate Authority API client. 39 | """ 40 | 41 | URI = '/rest/certificates/ca' 42 | 43 | def __init__(self, con): 44 | self._connection = con 45 | self._client = ResourceClient(con, self.URI) 46 | 47 | def get(self): 48 | """ 49 | Retrieves the certificate of the internal CA in the form of a string. 50 | 51 | Returns: 52 | str: The Internal CA Certificate. 53 | """ 54 | return self._client.get(self.URI) 55 | 56 | def get_crl(self): 57 | """ 58 | Retrieves the contents of the CRL file maintained by the internal CA; in Base-64 encoded format, in the form 59 | of a string. 60 | 61 | Returns: 62 | str: The Certificate Revocation List 63 | """ 64 | crl_url = self.URI + "/crl" 65 | return self._client.get(crl_url) 66 | 67 | def delete(self, alias_name, timeout=-1): 68 | """ 69 | Revokes a certificate signed by the internal CA. If client certificate to be revoked is RabbitMQ_readonly, 70 | then the internal CA root certificate, RabbitMQ client certificate and RabbitMQ server certificate will be 71 | regenerated. This will invalidate the previous version of RabbitMQ client certificate and the RabbitMQ server 72 | will be restarted to read the latest certificates. 73 | 74 | Args: 75 | alias_name (str): Alias name. 76 | timeout: 77 | Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation 78 | in OneView, just stop waiting for its completion. 79 | """ 80 | uri = self.URI + "/" + alias_name 81 | return self._client.delete(uri, timeout=timeout) 82 | -------------------------------------------------------------------------------- /hpOneView/resources/security/login_details.py: -------------------------------------------------------------------------------- 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 __future__ import print_function 25 | from __future__ import unicode_literals 26 | from __future__ import division 27 | from __future__ import absolute_import 28 | from future import standard_library 29 | 30 | standard_library.install_aliases() 31 | 32 | 33 | from hpOneView.resources.resource import ResourceClient 34 | 35 | 36 | class LoginDetails(object): 37 | """ 38 | list login details. 39 | 40 | """ 41 | 42 | URI = '/rest/logindetails' 43 | 44 | def __init__(self, con): 45 | self._connection = con 46 | self._client = ResourceClient(con, self.URI) 47 | 48 | def get_login_details(self): 49 | """ 50 | List the login details 51 | 52 | Returns: 53 | dict: login details. 54 | """ 55 | return self._client.get(self.URI) 56 | -------------------------------------------------------------------------------- /hpOneView/resources/security/roles.py: -------------------------------------------------------------------------------- 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 __future__ import absolute_import 25 | from __future__ import division 26 | from __future__ import print_function 27 | from __future__ import unicode_literals 28 | 29 | from future import standard_library 30 | 31 | standard_library.install_aliases() 32 | 33 | from urllib.parse import quote 34 | from hpOneView.resources.resource import ResourceClient 35 | 36 | 37 | class Roles(object): 38 | """ 39 | Roles API client. 40 | """ 41 | 42 | URI = '/rest/roles' 43 | RESOURCES_PATH = '/resources' 44 | 45 | def __init__(self, con): 46 | self._connection = con 47 | self._client = ResourceClient(con, self.URI) 48 | 49 | def get_all(self, start=0, count=-1, filter='', sort=''): 50 | """ 51 | Gets a list of roles based on optional sorting and filtering and is constrained by start 52 | and count parameters. 53 | 54 | Args: 55 | start: 56 | The first item to return, using 0-based indexing. 57 | If not specified, the default is 0 - start with the first available item. 58 | count: 59 | The number of resources to return. A count of -1 requests all items. 60 | The actual number of items in the response might differ from the requested 61 | count if the sum of start and count exceeds the total number of items. 62 | filter (list or str): 63 | A general filter/query string to narrow the list of items returned. The 64 | default is no filter; all resources are returned. 65 | sort: 66 | The sort order of the returned data set. By default, the sort order is based 67 | on create time with the oldest entry first. 68 | 69 | Returns: 70 | list: A list of roles. 71 | """ 72 | return self._client.get_all(start=start, count=count, filter=filter, sort=sort) 73 | 74 | def get(self, name_or_uri): 75 | """ 76 | Get the role by its URI or Name. 77 | 78 | Args: 79 | name_or_uri: 80 | Can be either the Name or the URI. 81 | 82 | Returns: 83 | dict: Role 84 | """ 85 | name_or_uri = quote(name_or_uri) 86 | return self._client.get(name_or_uri) 87 | -------------------------------------------------------------------------------- /hpOneView/resources/servers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/servers/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/settings/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/settings/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/settings/appliance_device_read_community.py: -------------------------------------------------------------------------------- 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 __future__ import absolute_import 25 | from __future__ import division 26 | from __future__ import print_function 27 | from __future__ import unicode_literals 28 | 29 | from future import standard_library 30 | 31 | standard_library.install_aliases() 32 | 33 | from hpOneView.resources.resource import ResourceClient 34 | 35 | 36 | class ApplianceDeviceReadCommunity(object): 37 | """ 38 | ApplianceDeviceReadCommunity API client. 39 | The device read community string is used by the appliance to establish SNMP communication with devices managed by the appliance. 40 | """ 41 | URI = '/rest/appliance/device-read-community-string' 42 | 43 | def __init__(self, con): 44 | self._client = ResourceClient(con, self.URI) 45 | 46 | def get(self): 47 | """ 48 | Retrieves the global community string. 49 | 50 | Returns: 51 | dict: ApplianceDeviceReadCommunity 52 | """ 53 | return self._client.get(self.URI) 54 | 55 | def update(self, resource, timeout=-1): 56 | """ 57 | Update the device read community string. 58 | This results in an update of the community string on all servers being managed/monitored by this OneView instance. 59 | 60 | Args: 61 | resource (dict): Object to update. 62 | timeout: 63 | Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation 64 | in OneView, just stop waiting for its completion. 65 | 66 | Returns: 67 | dict: Updated appliance SNMPv1 read community string. 68 | """ 69 | return self._client.update(resource, timeout=timeout) 70 | -------------------------------------------------------------------------------- /hpOneView/resources/settings/appliance_node_information.py: -------------------------------------------------------------------------------- 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 __future__ import absolute_import 25 | from __future__ import division 26 | from __future__ import print_function 27 | from __future__ import unicode_literals 28 | 29 | from future import standard_library 30 | 31 | standard_library.install_aliases() 32 | 33 | from hpOneView.resources.resource import ResourceClient 34 | 35 | 36 | class ApplianceNodeInformation(object): 37 | """ 38 | ApplianceNodeInformation API client. 39 | 40 | """ 41 | URI = '/rest/appliance/nodeinfo' 42 | 43 | def __init__(self, con): 44 | self._client = ResourceClient(con, self.URI) 45 | 46 | def get_status(self): 47 | """ 48 | Retrieves node's status information 49 | 50 | Returns: 51 | dict: Node's status information 52 | """ 53 | uri = self.URI + '/status' 54 | return self._client.get(uri) 55 | 56 | def get_version(self): 57 | """ 58 | Retrieves node's version information 59 | 60 | Returns: 61 | dict: Node's version information 62 | """ 63 | uri = self.URI + '/version' 64 | return self._client.get(uri) 65 | -------------------------------------------------------------------------------- /hpOneView/resources/settings/appliance_time_and_locale_configuration.py: -------------------------------------------------------------------------------- 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 __future__ import absolute_import 25 | from __future__ import division 26 | from __future__ import print_function 27 | from __future__ import unicode_literals 28 | 29 | from future import standard_library 30 | 31 | standard_library.install_aliases() 32 | 33 | from hpOneView.resources.resource import ResourceClient 34 | 35 | 36 | class ApplianceTimeAndLocaleConfiguration(object): 37 | """ 38 | ApplianceTimeAndLocaleConfiguration API client. 39 | 40 | """ 41 | URI = '/rest/appliance/configuration/time-locale' 42 | 43 | DEFAULT_VALUES = { 44 | '200': {"type": "TimeAndLocale"}, 45 | '300': {"type": "TimeAndLocale"} 46 | } 47 | 48 | def __init__(self, con): 49 | self._client = ResourceClient(con, self.URI) 50 | 51 | def get(self): 52 | """ 53 | Gets the appliance time and locale configuration. 54 | 55 | Returns: 56 | dict: ApplianceTimeAndLocaleConfiguration 57 | """ 58 | return self._client.get(self.URI) 59 | 60 | def update(self, resource, timeout=-1): 61 | """ 62 | Updates the appliance time and locale configuration. 63 | 64 | Args: 65 | resource (dict): Object to update. 66 | timeout: 67 | Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation 68 | in OneView, just stop waiting for its completion. 69 | 70 | Returns: 71 | dict: Updated appliance time and locale configuration. 72 | 73 | """ 74 | return self._client.create(resource, timeout=timeout, default_values=self.DEFAULT_VALUES) 75 | -------------------------------------------------------------------------------- /hpOneView/resources/settings/firmware_bundles.py: -------------------------------------------------------------------------------- 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 __future__ import absolute_import 25 | from __future__ import division 26 | from __future__ import print_function 27 | from __future__ import unicode_literals 28 | 29 | from future import standard_library 30 | 31 | standard_library.install_aliases() 32 | 33 | 34 | from hpOneView.resources.resource import ResourceClient 35 | 36 | 37 | class FirmwareBundles(object): 38 | """ 39 | Firmware Bundles API client. 40 | 41 | """ 42 | URI = '/rest/firmware-bundles' 43 | 44 | def __init__(self, con): 45 | self._connection = con 46 | self._client = ResourceClient(con, self.URI) 47 | 48 | def upload(self, file_path, timeout=-1): 49 | """ 50 | Upload an SPP ISO image file or a hotfix file to the appliance. 51 | The API supports upload of one hotfix at a time into the system. 52 | For the successful upload of a hotfix, ensure its original name and extension are not altered. 53 | 54 | Args: 55 | file_path: Full path to firmware. 56 | timeout: Timeout in seconds. Wait for task completion by default. The timeout does not abort the operation 57 | in OneView; it just stops waiting for its completion. 58 | 59 | Returns: 60 | dict: Information about the updated firmware bundle. 61 | """ 62 | return self._client.upload(file_path, timeout=timeout) 63 | -------------------------------------------------------------------------------- /hpOneView/resources/settings/versions.py: -------------------------------------------------------------------------------- 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 __future__ import absolute_import 25 | from __future__ import division 26 | from __future__ import print_function 27 | from __future__ import unicode_literals 28 | 29 | from future import standard_library 30 | 31 | standard_library.install_aliases() 32 | 33 | from hpOneView.resources.resource import ResourceClient 34 | 35 | 36 | class Versions(object): 37 | """ 38 | Version API client. It indicates the range of API versions supported by the appliance. 39 | 40 | """ 41 | URI = '/rest/version' 42 | 43 | def __init__(self, con): 44 | self._client = ResourceClient(con, self.URI) 45 | 46 | def get_version(self): 47 | """ 48 | Returns the range of possible API versions supported by the appliance. 49 | The response contains the current version and the minimum version. 50 | The current version is the recommended version to specify in the REST header. 51 | The other versions are supported for backward compatibility, but might not support the most current features. 52 | 53 | Returns: 54 | dict: The minimum and maximum supported API versions. 55 | """ 56 | version = self._client.get(self.URI) 57 | return version 58 | -------------------------------------------------------------------------------- /hpOneView/resources/storage/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/storage/__init__.py -------------------------------------------------------------------------------- /hpOneView/resources/uncategorized/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/hpOneView/resources/uncategorized/__init__.py -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | future >= 0.15.2 2 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file=README.md 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 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 | 25 | from setuptools import find_packages 26 | from setuptools import setup 27 | 28 | setup(name='hpOneView', 29 | version='4.8.0', 30 | description='HPE OneView Python Library', 31 | url='https://github.com/HewlettPackard/python-hpOneView', 32 | download_url="https://github.com/HewlettPackard/python-hpOneView/tarball/v4.8.0", 33 | author='Hewlett Packard Enterprise Development LP', 34 | author_email='oneview-pythonsdk@hpe.com', 35 | license='MIT', 36 | packages=find_packages(exclude=['examples*', 'tests*']), 37 | keywords=['oneview', 'hpe'], 38 | install_requires=['future>=0.15.2']) 39 | -------------------------------------------------------------------------------- /test_requirements.txt: -------------------------------------------------------------------------------- 1 | mock == 2.0.0 -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/__init__.py -------------------------------------------------------------------------------- /tests/test_utils.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def mock_builtin(method_name='open'): 5 | package_name = 'builtins' if sys.version_info[:3] >= (3,) else '__builtin__' 6 | return "%s.%s" % (package_name, method_name) 7 | -------------------------------------------------------------------------------- /tests/unit/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/__init__.py -------------------------------------------------------------------------------- /tests/unit/image_streamer/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/image_streamer/__init__.py -------------------------------------------------------------------------------- /tests/unit/image_streamer/resources/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/image_streamer/resources/__init__.py -------------------------------------------------------------------------------- /tests/unit/image_streamer/resources/test_deployment_groups.py: -------------------------------------------------------------------------------- 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 unittest import TestCase 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.image_streamer.resources.deployment_groups import DeploymentGroups 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class DeploymentGroupsTest(TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._client = DeploymentGroups(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get_all') 40 | def test_get_all_called_once(self, mock_get_all): 41 | filter = 'name=TestName' 42 | sort = 'name:ascending' 43 | 44 | self._client.get_all(2, 500, filter, sort) 45 | 46 | mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort) 47 | 48 | @mock.patch.object(ResourceClient, 'get_all') 49 | def test_get_all_called_once_with_default_values(self, mock_get_all): 50 | self._client.get_all() 51 | 52 | mock_get_all.assert_called_once_with(0, -1, filter='', sort='') 53 | 54 | @mock.patch.object(ResourceClient, 'get') 55 | def test_get_called_once(self, mock_get): 56 | self._client.get('57f2d803-9c11-4f9a-bc02-71804a0fcc3e') 57 | 58 | mock_get.assert_called_once_with('57f2d803-9c11-4f9a-bc02-71804a0fcc3e') 59 | 60 | @mock.patch.object(ResourceClient, 'get_by') 61 | def test_get_by_called_once(self, mock_get_by): 62 | self._client.get_by('name', 'OSS') 63 | 64 | mock_get_by.assert_called_once_with('name', 'OSS') 65 | 66 | @mock.patch.object(ResourceClient, 'get_by') 67 | def test_get_by_name_called_once(self, mock_get_by): 68 | self._client.get_by_name('OSS') 69 | 70 | mock_get_by.assert_called_once_with('name', 'OSS') 71 | -------------------------------------------------------------------------------- /tests/unit/resources/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/__init__.py -------------------------------------------------------------------------------- /tests/unit/resources/activity/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/activity/__init__.py -------------------------------------------------------------------------------- /tests/unit/resources/activity/test_tasks.py: -------------------------------------------------------------------------------- 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 unittest import TestCase 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.activity.tasks import Tasks 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class TasksTest(TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._client = Tasks(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get_all') 40 | def test_get_all(self, mock_get): 41 | self._client.get_all(fields='parentTaskUri,owner,name', 42 | filter="\"taskState='Running'&filter=associatedResource.resourceCatgory='appliance'\"", 43 | sort='name:ascending', 44 | view='day') 45 | 46 | mock_get.assert_called_once_with(count=-1, fields='parentTaskUri,owner,name', 47 | filter='"taskState=\'Running\'&filter=associatedResource' 48 | '.resourceCatgory=\'appliance\'"', 49 | query='', sort='name:ascending', start=0, view='day') 50 | 51 | @mock.patch.object(ResourceClient, 'get') 52 | def test_get_specific(self, mock_get): 53 | self._client.get('35323930-4936-4450-5531-303153474820') 54 | mock_get.assert_called_once_with('35323930-4936-4450-5531-303153474820') 55 | -------------------------------------------------------------------------------- /tests/unit/resources/data_services/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/data_services/__init__.py -------------------------------------------------------------------------------- /tests/unit/resources/data_services/test_metric_streaming.py: -------------------------------------------------------------------------------- 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 unittest import TestCase 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.data_services.metric_streaming import MetricStreaming 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class MetricStreamingTest(TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._metrics = MetricStreaming(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get') 40 | def test_get_capability_called_once(self, mock_get): 41 | self._metrics.get_capability() 42 | mock_get.assert_called_once_with("/rest/metrics/capability") 43 | 44 | @mock.patch.object(ResourceClient, 'get') 45 | def test_get_configuration_called_once(self, mock_get): 46 | self._metrics.get_configuration() 47 | mock_get.assert_called_once_with("/rest/metrics/configuration") 48 | 49 | @mock.patch.object(ResourceClient, 'update') 50 | def test_update_should_use_given_values(self, mock_update): 51 | configuration = { 52 | "sourceTypeList": [ 53 | { 54 | "sourceType": "/rest/power-devices", 55 | "sampleIntervalInSeconds": "300", 56 | "frequencyOfRelayInSeconds": "3600" 57 | } 58 | ] 59 | } 60 | configuration_rest_call = configuration.copy() 61 | mock_update.return_value = configuration 62 | 63 | self._metrics.update_configuration(configuration) 64 | mock_update.assert_called_once_with(configuration_rest_call, uri="/rest/metrics/configuration") 65 | -------------------------------------------------------------------------------- /tests/unit/resources/facilities/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/facilities/__init__.py -------------------------------------------------------------------------------- /tests/unit/resources/fc_sans/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/fc_sans/__init__.py -------------------------------------------------------------------------------- /tests/unit/resources/fc_sans/test_endpoints.py: -------------------------------------------------------------------------------- 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 unittest import TestCase 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.resource import ResourceClient 30 | from hpOneView.resources.fc_sans.endpoints import Endpoints 31 | 32 | TIMEOUT = -1 33 | 34 | 35 | class EndpointsTest(TestCase): 36 | def setUp(self): 37 | host = '127.0.0.1' 38 | http_connection = connection(host) 39 | self._resource = Endpoints(http_connection) 40 | 41 | @mock.patch.object(ResourceClient, 'get_all') 42 | def test_get_all_with_defaults(self, mock_get_all): 43 | self._resource.get_all() 44 | mock_get_all.assert_called_once_with(start=0, count=-1, query='', sort='') 45 | 46 | @mock.patch.object(ResourceClient, 'get_all') 47 | def test_get_all(self, mock_get_all): 48 | query_filter = "name EQ 'TestName'" 49 | sort = 'name:ascending' 50 | 51 | self._resource.get_all(start=2, count=500, query=query_filter, sort=sort) 52 | mock_get_all.assert_called_once_with(start=2, count=500, query=query_filter, sort=sort) 53 | -------------------------------------------------------------------------------- /tests/unit/resources/networking/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/networking/__init__.py -------------------------------------------------------------------------------- /tests/unit/resources/networking/test_fabrics.py: -------------------------------------------------------------------------------- 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.networking.fabrics import Fabrics 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class FabricsTest(unittest.TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._fabrics = Fabrics(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get') 40 | def test_get_called_once(self, mock_get): 41 | self._fabrics.get('7a9f7d09-3c24-4efe-928f-50a1af411120') 42 | 43 | mock_get.assert_called_once_with( 44 | '7a9f7d09-3c24-4efe-928f-50a1af411120') 45 | 46 | @mock.patch.object(ResourceClient, 'get_all') 47 | def test_get_all_called_once(self, mock_get_all): 48 | filter = 'name=TestName' 49 | sort = 'name:ascending' 50 | 51 | self._fabrics.get_all(2, 500, filter, sort) 52 | 53 | mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort) 54 | 55 | @mock.patch.object(ResourceClient, 'get_by') 56 | def test_get_by_called_once(self, mock_get_by): 57 | self._fabrics.get_by('name', 'DefaultFabric') 58 | 59 | mock_get_by.assert_called_once_with('name', 'DefaultFabric') 60 | 61 | @mock.patch.object(ResourceClient, 'get') 62 | def test_get_reserved_vlan_range(self, mock_get): 63 | uri = '/rest/fabrics/123/reserved-vlan-range' 64 | self._fabrics.get_reserved_vlan_range('123') 65 | 66 | mock_get.assert_called_once_with(uri) 67 | 68 | @mock.patch.object(ResourceClient, 'update') 69 | def test_update_reserved_vlan_range(self, mock_update): 70 | uri = '/rest/fabrics/123/reserved-vlan-range' 71 | data_to_update = { 72 | "start": 100, 73 | "length": 100 74 | } 75 | 76 | self._fabrics.update_reserved_vlan_range('123', data_to_update) 77 | 78 | mock_update.assert_called_once_with( 79 | resource=data_to_update, 80 | uri=uri, 81 | force=False, 82 | default_values=Fabrics.DEFAULT_VALUES 83 | ) 84 | -------------------------------------------------------------------------------- /tests/unit/resources/networking/test_interconnect_link_topologies.py: -------------------------------------------------------------------------------- 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.networking.interconnect_link_topologies import InterconnectLinkTopologies 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class InterconnectLinkTopologiesTest(unittest.TestCase): 34 | 35 | def setUp(self): 36 | self.host = '127.0.0.1' 37 | self.connection = connection(self.host) 38 | self._interconnect_link_topologies = InterconnectLinkTopologies(self.connection) 39 | 40 | @mock.patch.object(ResourceClient, 'get') 41 | def test_get_called_once_by_id(self, mock_get): 42 | ilt_id = 'c6f4e705-2bb5-430a-b7a1-a35b2f7aa9b9' 43 | self._interconnect_link_topologies.get(ilt_id) 44 | 45 | mock_get.assert_called_once_with(ilt_id) 46 | 47 | @mock.patch.object(ResourceClient, 'get') 48 | def test_get_called_once_by_uri(self, mock_get): 49 | ilt_uri = '/rest/interconnect-link-topologies/c6f4e705-2bb5-430a-b7a1-a35b2f7aa9b9' 50 | self._interconnect_link_topologies.get(ilt_uri) 51 | 52 | mock_get.assert_called_once_with(ilt_uri) 53 | 54 | @mock.patch.object(ResourceClient, 'get_all') 55 | def test_get_all_called_once(self, mock_get_all): 56 | filter = 'name=TestName' 57 | sort = 'name:ascending' 58 | 59 | self._interconnect_link_topologies.get_all(2, 500, filter, sort) 60 | 61 | mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort) 62 | 63 | @mock.patch.object(ResourceClient, 'get_by') 64 | def test_get_by_called_once(self, mock_get_by): 65 | self._interconnect_link_topologies.get_by('name', 'sample name') 66 | 67 | mock_get_by.assert_called_once_with( 68 | 'name', 'sample name') 69 | -------------------------------------------------------------------------------- /tests/unit/resources/networking/test_interconnect_types.py: -------------------------------------------------------------------------------- 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.networking.interconnect_types import InterconnectTypes 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class InterconnectTypesTest(unittest.TestCase): 34 | 35 | def setUp(self): 36 | self.host = '127.0.0.1' 37 | self.connection = connection(self.host) 38 | self._interconnect_types = InterconnectTypes(self.connection) 39 | 40 | @mock.patch.object(ResourceClient, 'get') 41 | def test_get_called_once(self, mock_get): 42 | self._interconnect_types.get('c6f4e705-2bb5-430a-b7a1-a35b2f7aa9b9') 43 | 44 | mock_get.assert_called_once_with( 45 | 'c6f4e705-2bb5-430a-b7a1-a35b2f7aa9b9') 46 | 47 | @mock.patch.object(ResourceClient, 'get_all') 48 | def test_get_all_called_once(self, mock_get_all): 49 | filter = 'name=TestName' 50 | sort = 'name:ascending' 51 | 52 | self._interconnect_types.get_all(2, 500, filter, sort) 53 | 54 | mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort) 55 | 56 | @mock.patch.object(ResourceClient, 'get_by') 57 | def test_get_by_called_once(self, mock_get_by): 58 | self._interconnect_types.get_by('name', 'HP VC Flex-10 Enet Module') 59 | 60 | mock_get_by.assert_called_once_with( 61 | 'name', 'HP VC Flex-10 Enet Module') 62 | -------------------------------------------------------------------------------- /tests/unit/resources/networking/test_sas_interconnect_types.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ### 3 | # (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP 4 | # 5 | # Permission is hereby granted, free of chlarge, 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.networking.sas_interconnect_types import SasInterconnectTypes 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class SasInterconnectTypesTest(unittest.TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._sas_interconnect_types = SasInterconnectTypes(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get_all') 40 | def test_get_all_called_once(self, mock_get_all): 41 | filter = 'name=TestName' 42 | sort = 'name:ascending' 43 | 44 | self._sas_interconnect_types.get_all(2, 500, filter, sort) 45 | 46 | @mock.patch.object(ResourceClient, 'get_by') 47 | def test_get_by_called_once(self, mock_get_by): 48 | self._sas_interconnect_types.get_by('name', 'SAS Interconnect Type 1') 49 | 50 | mock_get_by.assert_called_once_with('name', 'SAS Interconnect Type 1') 51 | 52 | @mock.patch.object(ResourceClient, 'get') 53 | def test_get_called_once(self, mock_get): 54 | self._sas_interconnect_types.get('3518be0e-17c1-4189-8f81-83f3724f6155') 55 | 56 | mock_get.assert_called_once_with('3518be0e-17c1-4189-8f81-83f3724f6155') 57 | 58 | @mock.patch.object(ResourceClient, 'get') 59 | def test_get_with_uri_called_once(self, mock_get): 60 | uri = '/rest/sas-interconnect-types/3518be0e-17c1-4189-8f81-83f3724f6155' 61 | self._sas_interconnect_types.get(uri) 62 | 63 | mock_get.assert_called_once_with(uri) 64 | -------------------------------------------------------------------------------- /tests/unit/resources/networking/test_switch_types.py: -------------------------------------------------------------------------------- 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.networking.switch_types import SwitchTypes 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class SwitchTypesTest(unittest.TestCase): 34 | 35 | def setUp(self): 36 | self.host = '127.0.0.1' 37 | self.connection = connection(self.host) 38 | self._switch_types = SwitchTypes(self.connection) 39 | 40 | @mock.patch.object(ResourceClient, 'get') 41 | def test_get_called_once(self, mock_get): 42 | self._switch_types.get('c6f4e705-2bb5-430a-b7a1-a35b2f7aa9b9') 43 | 44 | mock_get.assert_called_once_with( 45 | 'c6f4e705-2bb5-430a-b7a1-a35b2f7aa9b9') 46 | 47 | @mock.patch.object(ResourceClient, 'get_all') 48 | def test_get_all_called_once(self, mock_get_all): 49 | filter = 'name=TestName' 50 | sort = 'name:ascending' 51 | 52 | self._switch_types.get_all(2, 500, filter, sort) 53 | 54 | mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort) 55 | 56 | @mock.patch.object(ResourceClient, 'get_by') 57 | def test_get_by_called_once(self, mock_get_by): 58 | self._switch_types.get_by('name', 'Cisco Nexus 6xxx') 59 | 60 | mock_get_by.assert_called_once_with( 61 | 'name', 'Cisco Nexus 6xxx') 62 | -------------------------------------------------------------------------------- /tests/unit/resources/search/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/search/__init__.py -------------------------------------------------------------------------------- /tests/unit/resources/security/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/security/__init__.py -------------------------------------------------------------------------------- /tests/unit/resources/security/test_certificate_authority.py: -------------------------------------------------------------------------------- 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.security.certificate_authority import CertificateAuthority 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class CertificateAuthorityTest(unittest.TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._certificates = CertificateAuthority(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get') 40 | def test_get_called_once(self, mock_get): 41 | self._certificates.get() 42 | mock_get.assert_called_once_with('/rest/certificates/ca') 43 | 44 | @mock.patch.object(ResourceClient, 'get') 45 | def test_get_crl_called_once(self, mock_get): 46 | self._certificates.get_crl() 47 | mock_get.assert_called_once_with('/rest/certificates/ca/crl') 48 | 49 | @mock.patch.object(ResourceClient, 'delete') 50 | def test_delete_called_once(self, mock_delete): 51 | self._certificates.delete("default") 52 | mock_delete.assert_called_once_with("/rest/certificates/ca/default", timeout=-1) 53 | -------------------------------------------------------------------------------- /tests/unit/resources/security/test_certificate_rabbitmq.py: -------------------------------------------------------------------------------- 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 unittest import TestCase 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.resource import ResourceClient 30 | from hpOneView.resources.security.certificate_rabbitmq import CertificateRabbitMQ 31 | 32 | 33 | class CertificateRabbitMQTest(TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._certificate_rabbitmq = CertificateRabbitMQ(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'create') 40 | def test_generate_called_once_with_defaults(self, mock_create): 41 | information = { 42 | "commonName": "default", 43 | "type": "RabbitMqClientCertV2" 44 | } 45 | self._certificate_rabbitmq.generate(information) 46 | mock_create.assert_called_once_with(information, timeout=-1) 47 | 48 | @mock.patch.object(ResourceClient, 'get') 49 | def test_get_by_alias_name_called_once(self, mock_get): 50 | alias_name = 'default' 51 | self._certificate_rabbitmq.get(alias_name) 52 | mock_get.assert_called_once_with(alias_name) 53 | 54 | @mock.patch.object(ResourceClient, 'get') 55 | def test_get_key_pair_called_once(self, mock_get): 56 | alias_name = 'default' 57 | self._certificate_rabbitmq.get_key_pair(alias_name) 58 | uri = "/rest/certificates/client/rabbitmq/keypair/" + alias_name 59 | mock_get.assert_called_once_with(uri) 60 | 61 | @mock.patch.object(ResourceClient, 'get') 62 | def test_get_keys_called_once(self, mock_get): 63 | alias_name = 'default' 64 | key_format = 'Base64' 65 | self._certificate_rabbitmq.get_keys(alias_name, key_format) 66 | uri = "/rest/certificates/client/rabbitmq/keys/" + alias_name + "?format=" + key_format 67 | mock_get.assert_called_once_with(uri) 68 | -------------------------------------------------------------------------------- /tests/unit/resources/security/test_login_details.py: -------------------------------------------------------------------------------- 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.security.login_details import LoginDetails 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class LoginDetailsTest(unittest.TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._login_details = LoginDetails(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get') 40 | def test_get_called_once(self, mock_get): 41 | self._login_details.get_login_details() 42 | mock_get.assert_called_once_with(LoginDetails.URI) 43 | -------------------------------------------------------------------------------- /tests/unit/resources/security/test_roles.py: -------------------------------------------------------------------------------- 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 | 25 | import mock 26 | 27 | from unittest import TestCase 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.resource import ResourceClient 30 | from hpOneView.resources.security.roles import Roles 31 | 32 | 33 | class RolesTest(TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._client = Roles(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get_all') 40 | def test_get_all_called_once(self, mock_get_all): 41 | filter = 'name=TestName' 42 | sort = 'name:ascending' 43 | 44 | self._client.get_all(2, 500, filter=filter, sort=sort) 45 | 46 | mock_get_all.assert_called_once_with(count=500, filter='name=TestName', sort='name:ascending', start=2) 47 | 48 | @mock.patch.object(ResourceClient, 'get_all') 49 | def test_get_all_called_once_with_default(self, mock_get_all): 50 | self._client.get_all() 51 | mock_get_all.assert_called_once_with(count=-1, filter=u'', sort=u'', start=0) 52 | 53 | @mock.patch.object(ResourceClient, 'get') 54 | def test_get_by_id_called_once(self, mock_get): 55 | id = "Infrastructure administrator" 56 | self._client.get(id) 57 | mock_get.assert_called_once_with('Infrastructure%20administrator') 58 | 59 | @mock.patch.object(ResourceClient, 'get') 60 | def test_get_by_uri_called_once(self, mock_get): 61 | uri = "/rest/roles/Infrastructure administrator" 62 | self._client.get(uri) 63 | mock_get.assert_called_once_with('/rest/roles/Infrastructure%20administrator') 64 | -------------------------------------------------------------------------------- /tests/unit/resources/servers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/servers/__init__.py -------------------------------------------------------------------------------- /tests/unit/resources/servers/test_connections.py: -------------------------------------------------------------------------------- 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 unittest import TestCase 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.servers.connections import Connections 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class ConnectionsTest(TestCase): 34 | 35 | def setUp(self): 36 | self.host = '127.0.0.1' 37 | self.connection = connection(self.host) 38 | self._connections = Connections(self.connection) 39 | 40 | @mock.patch.object(ResourceClient, 'get_all') 41 | def test_get_all_called_once(self, mock_get_all): 42 | filter = 'interconnectUri=xxxx' 43 | sort = 'name:ascending' 44 | fields = 'name' 45 | view = '' 46 | 47 | self._connections.get_all(2, 500, filter, sort, view, fields) 48 | 49 | mock_get_all.assert_called_once_with( 50 | 2, 500, filter=filter, sort=sort, view=view, fields=fields) 51 | 52 | @mock.patch.object(ResourceClient, 'get_all') 53 | def test_get_all_called_once_with_defaults(self, mock_get_all): 54 | self._connections.get_all() 55 | 56 | mock_get_all.assert_called_once_with( 57 | 0, -1, filter='', sort='', view='', fields='') 58 | 59 | @mock.patch.object(ResourceClient, 'get_by') 60 | def test_get_by_called_once(self, mock_get_by): 61 | self._connections.get_by('name', 'OneViewSDK-Test-Connection') 62 | 63 | mock_get_by.assert_called_once_with( 64 | 'name', 'OneViewSDK-Test-Connection') 65 | 66 | @mock.patch.object(ResourceClient, 'get') 67 | def test_get_called_once(self, mock_get): 68 | self._connections.get('3518be0e-17c1-4189-8f81-83f3724f6155') 69 | 70 | mock_get.assert_called_once_with( 71 | '3518be0e-17c1-4189-8f81-83f3724f6155') 72 | 73 | @mock.patch.object(ResourceClient, 'get') 74 | def test_get_with_uri_called_once(self, mock_get): 75 | uri = '/rest/connections/3518be0e-17c1-4189-8f81-83f3724f6155' 76 | self._connections.get(uri) 77 | 78 | mock_get.assert_called_once_with(uri) 79 | -------------------------------------------------------------------------------- /tests/unit/resources/settings/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/settings/__init__.py -------------------------------------------------------------------------------- /tests/unit/resources/settings/test_appliance_device_read_community.py: -------------------------------------------------------------------------------- 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.settings.appliance_device_read_community import ApplianceDeviceReadCommunity 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class ApplianceDeviceReadCommunityTest(unittest.TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._read_community = ApplianceDeviceReadCommunity(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get') 40 | def test_get_called_once(self, mock_get): 41 | self._read_community.get() 42 | mock_get.assert_called_once_with('/rest/appliance/device-read-community-string') 43 | 44 | @mock.patch.object(ResourceClient, 'update') 45 | def test_update_called_once(self, mock_create): 46 | resource = { 47 | 'communityString': 'public', 48 | 'uri': '/rest/appliance/device-read-community-string' 49 | } 50 | self._read_community.update(resource) 51 | mock_create.assert_called_once_with(resource, timeout=-1) 52 | -------------------------------------------------------------------------------- /tests/unit/resources/settings/test_appliance_node_information.py: -------------------------------------------------------------------------------- 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.settings.appliance_node_information import ApplianceNodeInformation 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class ApplianceTimeAndLocaleConfigurationTest(unittest.TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._node_information = ApplianceNodeInformation(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get') 40 | def test_get_status_called_once(self, mock_get): 41 | self._node_information.get_status() 42 | mock_get.assert_called_once_with('/rest/appliance/nodeinfo/status') 43 | 44 | @mock.patch.object(ResourceClient, 'get') 45 | def test_get_version_called_once(self, mock_get): 46 | self._node_information.get_version() 47 | mock_get.assert_called_once_with('/rest/appliance/nodeinfo/version') 48 | -------------------------------------------------------------------------------- /tests/unit/resources/settings/test_appliance_time_and_locale_configuration.py: -------------------------------------------------------------------------------- 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.settings.appliance_time_and_locale_configuration import ApplianceTimeAndLocaleConfiguration 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class ApplianceTimeAndLocaleConfigurationTest(unittest.TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._time_and_locale = ApplianceTimeAndLocaleConfiguration(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get') 40 | def test_get_called_once(self, mock_get): 41 | self._time_and_locale.get() 42 | mock_get.assert_called_once_with('/rest/appliance/configuration/time-locale') 43 | 44 | @mock.patch.object(ResourceClient, 'create') 45 | def test_update_called_once(self, mock_create): 46 | resource = { 47 | 'dateTime': '2020-02-27T7:55:00.000Z', 48 | 'locale': 'en_US.UTF-8', 49 | 'localeDisplayName': 'English (United States)', 50 | 'ntpServers': ['127.0.0.1'], 51 | 'timezone': 'UTC', 52 | 'uri': None 53 | } 54 | self._time_and_locale.update(resource) 55 | mock_create.assert_called_once_with(resource, timeout=-1, default_values=self._time_and_locale.DEFAULT_VALUES) 56 | -------------------------------------------------------------------------------- /tests/unit/resources/settings/test_firmware_bundles.py: -------------------------------------------------------------------------------- 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.settings.firmware_bundles import FirmwareBundles 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class FirmwareBundlesTest(unittest.TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._firmware_bundles = FirmwareBundles(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'upload') 40 | def test_upload(self, mock_upload): 41 | firmware_path = "test/SPPgen9snap6.2015_0405.81.iso" 42 | 43 | self._firmware_bundles.upload(firmware_path) 44 | 45 | mock_upload.assert_called_once_with(firmware_path, timeout=-1) 46 | -------------------------------------------------------------------------------- /tests/unit/resources/settings/test_licenses.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ### 3 | # (C) Copyright (2012-2018) 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 unittest import TestCase 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.resource import ResourceClient 30 | from hpOneView.resources.settings.licenses import Licenses 31 | 32 | 33 | class LicensesTest(TestCase): 34 | DEFAULT_HOST = '127.0.0.1' 35 | 36 | def setUp(self): 37 | oneview_connection = connection(self.DEFAULT_HOST) 38 | self.resource = Licenses(oneview_connection) 39 | 40 | @mock.patch.object(ResourceClient, 'create') 41 | def test_create_called_once(self, mock_create): 42 | data = { 43 | 'key': 'ASD8 JKL7 UYT9', 44 | 'type': 'LicenseListV500' 45 | } 46 | self.resource.create(data) 47 | mock_create.assert_called_once_with(data, timeout=-1, default_values=self.resource.DEFAULT_VALUES) 48 | 49 | @mock.patch.object(ResourceClient, 'delete') 50 | def test_delete_called_once(self, mock_delete): 51 | id = '54' 52 | self.resource.delete(id) 53 | mock_delete.assert_called_once_with(id) 54 | 55 | @mock.patch.object(ResourceClient, 'get') 56 | def test_get_called_once(self, mock_get_by_id): 57 | id = '/rest/licenses/54' 58 | self.resource.get_by_id(id) 59 | mock_get_by_id.assert_called_once_with(id) 60 | 61 | @mock.patch.object(ResourceClient, 'get_all') 62 | def test_get_all_called_once(self, mock_get_all): 63 | filter = 'name=TestName' 64 | sort = 'name:ascending' 65 | self.resource.get_all(2, 500, filter, sort) 66 | mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort) 67 | -------------------------------------------------------------------------------- /tests/unit/resources/settings/test_versions.py: -------------------------------------------------------------------------------- 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 | import mock 24 | import unittest 25 | 26 | from hpOneView.connection import connection 27 | from hpOneView.resources.settings.versions import Versions 28 | from hpOneView.resources.resource import ResourceClient 29 | 30 | 31 | class VersionsTest(unittest.TestCase): 32 | def setUp(self): 33 | self.host = '127.0.0.1' 34 | self.connection = connection(self.host) 35 | self._client = Versions(self.connection) 36 | 37 | @mock.patch.object(ResourceClient, 'get') 38 | def test_get_with_uri_called_once(self, mock_get): 39 | self._client.get_version() 40 | mock_get.assert_called_once_with('/rest/version') 41 | -------------------------------------------------------------------------------- /tests/unit/resources/storage/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/storage/__init__.py -------------------------------------------------------------------------------- /tests/unit/resources/storage/test_sas_logical_jbod_attachments.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ### 3 | # (C) Copyright (2012-2017) Hewlett Packard Enterprise Development LP 4 | # 5 | # Permission is hereby granted, free of chlarge, 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.storage.sas_logical_jbod_attachments import SasLogicalJbodAttachments 30 | from hpOneView.resources.resource import ResourceClient 31 | 32 | 33 | class SasLogicalJbodAttachmentsTest(unittest.TestCase): 34 | def setUp(self): 35 | self.host = '127.0.0.1' 36 | self.connection = connection(self.host) 37 | self._sas_logical_jbod_attachments = SasLogicalJbodAttachments(self.connection) 38 | 39 | @mock.patch.object(ResourceClient, 'get_all') 40 | def test_get_all_called_once(self, mock_get_all): 41 | filter = 'name=TestName' 42 | sort = 'name:ascending' 43 | 44 | self._sas_logical_jbod_attachments.get_all(2, 500, filter, sort) 45 | 46 | @mock.patch.object(ResourceClient, 'get_by') 47 | def test_get_by_called_once(self, mock_get_by): 48 | self._sas_logical_jbod_attachments.get_by('name', 'SAS Logical JBOD Attachment Name') 49 | 50 | mock_get_by.assert_called_once_with('name', 'SAS Logical JBOD Attachment Name') 51 | 52 | @mock.patch.object(ResourceClient, 'get') 53 | def test_get_called_once(self, mock_get): 54 | self._sas_logical_jbod_attachments.get('3518be0e-17c1-4189-8f81-83f3724f6155') 55 | 56 | mock_get.assert_called_once_with('3518be0e-17c1-4189-8f81-83f3724f6155') 57 | 58 | @mock.patch.object(ResourceClient, 'get') 59 | def test_get_with_uri_called_once(self, mock_get): 60 | uri = '/rest/sas-logical-jbods-attachments/3518be0e-17c1-4189-8f81-83f3724f6155' 61 | self._sas_logical_jbod_attachments.get(uri) 62 | 63 | mock_get.assert_called_once_with(uri) 64 | -------------------------------------------------------------------------------- /tests/unit/resources/storage/test_sas_logical_jbods.py: -------------------------------------------------------------------------------- 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 | import unittest 25 | 26 | import mock 27 | 28 | from hpOneView.connection import connection 29 | from hpOneView.resources.resource import ResourceClient 30 | from hpOneView.resources.storage.sas_logical_jbods import SasLogicalJbods 31 | 32 | 33 | class SasLogicalJbodsTest(unittest.TestCase): 34 | 35 | SAS_LOGICAL_JBOD_ID = 'c8ed5329-f9c1-492c-aa46-b78665ee7734' 36 | SAS_LOGICAL_JBOD_URI = '/rest/sas-logical-jbods/' + SAS_LOGICAL_JBOD_ID 37 | 38 | def setUp(self): 39 | self.host = '127.0.0.1' 40 | self.connection = connection(self.host) 41 | self._resource = SasLogicalJbods(self.connection) 42 | 43 | @mock.patch.object(ResourceClient, 'get_all') 44 | def test_get_all_called_once(self, mock_get_all): 45 | args = dict( 46 | start=2, 47 | count=500, 48 | filter='name=TestName', 49 | sort='name:ascending' 50 | ) 51 | 52 | self._resource.get_all(**args) 53 | mock_get_all.assert_called_once_with(**args) 54 | 55 | @mock.patch.object(ResourceClient, 'get') 56 | def test_get_called_once(self, mock_get): 57 | self._resource.get(id_or_uri=self.SAS_LOGICAL_JBOD_ID) 58 | mock_get.assert_called_once_with(id_or_uri=self.SAS_LOGICAL_JBOD_ID) 59 | 60 | @mock.patch.object(ResourceClient, 'get_by') 61 | def test_get_by_called_once(self, mock_get_by): 62 | self._resource.get_by('name', 'SAS Logical JBOD Name') 63 | 64 | mock_get_by.assert_called_once_with('name', 'SAS Logical JBOD Name') 65 | 66 | @mock.patch.object(ResourceClient, 'build_uri') 67 | @mock.patch.object(ResourceClient, 'get') 68 | def test_get_drives_called_once(self, mock_get, mock_build_uri): 69 | mock_build_uri.return_value = self.SAS_LOGICAL_JBOD_URI 70 | self._resource.get_drives(id_or_uri=self.SAS_LOGICAL_JBOD_ID) 71 | 72 | expected_uri = self.SAS_LOGICAL_JBOD_URI + SasLogicalJbods.DRIVES_PATH 73 | mock_build_uri.assert_called_once_with(id_or_uri=self.SAS_LOGICAL_JBOD_ID) 74 | mock_get.assert_called_once_with(id_or_uri=expected_uri) 75 | -------------------------------------------------------------------------------- /tests/unit/resources/uncategorized/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HewlettPackard/python-hpOneView/678d53b338f6bc7af7adb63153d7d8d99dc94ac0/tests/unit/resources/uncategorized/__init__.py -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | # Tox (http://tox.testrun.org/) is a tool for running tests 2 | # in multiple virtualenvs. This configuration file will run the 3 | # test suite on all supported python versions. To use it, "pip install tox" 4 | # and then run "tox" from this directory. 5 | 6 | 7 | [tox] 8 | envlist = docs, py34, py36, py27-coverage, py27-flake8 9 | skip_missing_interpreters = true 10 | 11 | [flake8] 12 | # E402 module level import not at top of file 13 | # W504 line break after binary operator 14 | # W605 invalid escape sequence '\_' 15 | ignore = E402, W504, W605 16 | max-line-length = 160 17 | exclude = hpOneView/__init__.py 18 | max-complexity = 14 19 | 20 | [testenv] 21 | deps = 22 | -r{toxinidir}/test_requirements.txt 23 | commands = 24 | {envpython} -m unittest discover 25 | 26 | [testenv:py27-coverage] 27 | basepython = 28 | python2.7 29 | passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH 30 | deps = 31 | -r{toxinidir}/test_requirements.txt 32 | coverage 33 | coveralls 34 | commands = 35 | coverage erase 36 | coverage run --source=hpOneView -m unittest discover 37 | - coveralls 38 | 39 | [testenv:py27-flake8] 40 | basepython = 41 | python2.7 42 | deps = 43 | flake8 44 | commands = 45 | flake8 {posargs} hpOneView/ tests/ examples/ 46 | 47 | [testenv:docs] 48 | basepython=python2.7 49 | deps= 50 | sphinx 51 | sphinx_rtd_theme 52 | commands= 53 | sphinx-apidoc -f -o docs/source hpOneView \ 54 | hpOneView/common.py \ 55 | hpOneView/activity.py \ 56 | hpOneView/exception_handler.py \ 57 | hpOneView/facilities.py \ 58 | hpOneView/fcsans.py \ 59 | hpOneView/metrics.py \ 60 | hpOneView/networking.py \ 61 | hpOneView/profile.py \ 62 | hpOneView/search.py \ 63 | hpOneView/security.py \ 64 | hpOneView/servers.py \ 65 | hpOneView/settings.py \ 66 | hpOneView/storage.py \ 67 | hpOneView/uncategorized.py 68 | sphinx-build -b html docs/source docs/build/html 69 | --------------------------------------------------------------------------------