diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..124969c --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +*.py[cod] + +# C extensions +*.so + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +var +sdist +develop-eggs +.installed.cfg +lib +lib64 + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox +nosetests.xml +htmlcov + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# Complexity +output/*.html +output/*/index.html + +# Sphinx +docs/_build + +# Idea IDE +.idea/* + +.DS_Store +tags diff --git a/requirements_dev.txt b/requirements_dev.txt index 6c91547..acd4ddc 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -5,4 +5,5 @@ flake8==2.4.1 tox==2.1.1 coverage==4.0 Sphinx==1.3.1 - +nose==1.3.7 +mock==2.0.0 diff --git a/setup.py b/setup.py index faec9e9..331be01 100755 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ ] test_requirements = [ - # TODO: put package test requirements here + 'nose' ] setup( @@ -49,7 +49,7 @@ 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', ], - test_suite='tests', + test_suite='nose.collector', tests_require=test_requirements, extras_require={ 'docs': ['sphinx<1.3', 'sphinxcontrib-napoleon', diff --git a/tests/test_ucsmsdk_samples.py b/tests/test_ucsmsdk_samples.py index 3c6e719..53fd165 100755 --- a/tests/test_ucsmsdk_samples.py +++ b/tests/test_ucsmsdk_samples.py @@ -10,8 +10,6 @@ import unittest -from ucsmsdk_samples import ucsmsdk_samples - class TestUcsmsdk_samples(unittest.TestCase): diff --git a/tests/unit_tests/test_network.py b/tests/unit_tests/test_network.py new file mode 100644 index 0000000..d6aa5b9 --- /dev/null +++ b/tests/unit_tests/test_network.py @@ -0,0 +1,93 @@ +# Copyright 2016 Cisco Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from mock import patch +from ucsmsdk.ucshandle import UcsHandle +from ucsmsdk_samples.network.uplink_port import uplink_port_create +from ucsmsdk_samples.network.server_port import server_port_create + + +@patch.object(UcsHandle, 'commit') +@patch.object(UcsHandle, 'add_mo') +def test_valid_uplink_port_create(add_mo_mock, commit_mock): + # Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC + # Patch UcsHandle.commit to simulate CIMC interaction w/o real CIMC + add_mo_mock.return_value = True + commit_mock.return_value = True + handle = UcsHandle('169.254.1.1', 'admin', 'password') + + # Scenario: Set Fabric-A port Eth1/10 to uplink port + fabric_dn = 'fabric/lan/A' + port_id = '10' + slot_id = '1' + uplink_port_create(handle, fabric_dn, port_id, slot_id) + + # Assert values of the object passed to add_mo() + test_uplink_mo = add_mo_mock.call_args[0][0] + assert test_uplink_mo.port_id == "10" + assert test_uplink_mo.slot_id == "1" + assert test_uplink_mo.dn == '{0}/phys-slot-{1}-port-{2}'.format(fabric_dn, + slot_id, + port_id) + + # Scenario: Set Fabric-B port Eth2/6 to uplink port + fabric_dn = 'fabric/lan/B' + port_id = '6' + slot_id = '2' + uplink_port_create(handle, fabric_dn, port_id, slot_id) + + # Assert values of the object passed to add_mo() + test_uplink_mo = add_mo_mock.call_args[0][0] + assert test_uplink_mo.port_id == "6" + assert test_uplink_mo.slot_id == "2" + assert test_uplink_mo.dn == '{0}/phys-slot-{1}-port-{2}'.format(fabric_dn, + slot_id, + port_id) + + +@patch.object(UcsHandle, 'commit') +@patch.object(UcsHandle, 'add_mo') +def test_valid_server_port_create(add_mo_mock, commit_mock): + # Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC + # Patch UcsHandle.commit to simulate CIMC interaction w/o real CIMC + add_mo_mock.return_value = True + commit_mock.return_value = True + handle = UcsHandle('169.254.1.1', 'admin', 'password') + + # Scenario: Set Fabric-A port Eth1/10 to server port + fabric_dn = 'fabric/lan/A' + port_id = '10' + slot_id = '1' + server_port_create(handle, fabric_dn, port_id, slot_id) + + # Assert values of the object passed to add_mo() + test_server_mo = add_mo_mock.call_args[0][0] + assert test_server_mo.port_id == "10" + assert test_server_mo.slot_id == "1" + assert test_server_mo.dn == '{0}/slot-{1}-port-{2}'.format(fabric_dn, + slot_id, + port_id) + + # Scenario: Set Fabric-B port Eth2/6 to server port + fabric_dn = 'fabric/lan/B' + port_id = '6' + slot_id = '2' + server_port_create(handle, fabric_dn, port_id, slot_id) + + # Assert values of the object passed to add_mo() + test_server_mo = add_mo_mock.call_args[0][0] + assert test_server_mo.port_id == "6" + assert test_server_mo.slot_id == "2" + assert test_server_mo.dn == '{0}/slot-{1}-port-{2}'.format(fabric_dn, + slot_id, + port_id) diff --git a/tests/unit_tests/test_server.py b/tests/unit_tests/test_server.py new file mode 100644 index 0000000..96f0630 --- /dev/null +++ b/tests/unit_tests/test_server.py @@ -0,0 +1,120 @@ +# Copyright 2016 Cisco Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from mock import patch +from nose.tools import assert_raises +from ucsmsdk.ucshandle import UcsHandle +from ucsmsdk.mometa.org.OrgOrg import OrgOrg +from ucsmsdk_samples.server.ipmi_policy import ipmi_policy_create +from ucsmsdk.mometa.aaa.AaaEpAuthProfile import AaaEpAuthProfile +from ucsmsdk_samples.server.local_drive import disk_state_set + + +# Patch UcsHandle.commit to simulate CIMC interaction w/o real CIMC +@patch.object(UcsHandle, 'commit') +# Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC +@patch.object(UcsHandle, 'add_mo') +# Patch UcsHandle.query_dn to simulate orgs +@patch.object(UcsHandle, 'query_dn') +def test_valid_ipmi_policy_create(query_mock, add_mo_mock, commit_mock): + # Create a root org as a return value to query_dn + query_mock.return_value = OrgOrg(parent_mo_or_dn="org-root", name="root") + add_mo_mock.return_value = True + commit_mock.return_value = True + handle = UcsHandle('169.254.1.1', 'admin', 'password') + + # Scenario: Default parameters + ipmi_retval = ipmi_policy_create(handle, name="test_ipmi_policy") + # Verify we were passed back the correct object type + assert isinstance(ipmi_retval, AaaEpAuthProfile) + # Verify the name we gave it was assigned correctly + assert ipmi_retval.name == "test_ipmi_policy" + # Verify the retruned object has no users (children) + assert len(ipmi_retval.child) == 0 + + # Scenario: default user, custom password + ipmi_retval = ipmi_policy_create(handle, name="test_ipmi_policy", + password="password") + user_retval = ipmi_retval.child[0] + # Verify the returned policy has a user (child) + assert user_retval is not None + # Verify the username is the default 'admin' + assert user_retval.name is 'admin' + # Verify the password was assigned correctly + assert user_retval.pwd is 'password' + + # Scenario: custom user, custom password + ipmi_retval = ipmi_policy_create(handle, name="test_ipmi_policy", + username="myuser", password="password") + user_retval = ipmi_retval.child[0] + # Verify the returned policy has a user (child) + assert user_retval is not None + # Verify the username was assigned correctly + assert user_retval.name is 'myuser' + # Verify the password was assigned correctly + assert user_retval.pwd is 'password' + + +@patch.object(UcsHandle, 'commit') +@patch.object(UcsHandle, 'add_mo') +@patch.object(UcsHandle, 'query_dn') +def test_invalid_ipmi_policy_create(query_mock, add_mo_mock, commit_mock): + # Patch UcsHandle.query_dn to simulate valid/invalid orgs + # Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC + # Patch UcsHandle.commit to simulate CIMC interaction w/o real CIMC + add_mo_mock.return_value = True + commit_mock.return_value = True + handle = UcsHandle('169.254.1.1', 'admin', 'password') + + # Scenario: Invalid Org + query_mock.return_value = None + # Verify exception was raised for invalid org + assert_raises(ValueError, ipmi_policy_create, handle, 'invalid') + + +# Patch UcsHandle.commit to simulate CIMC interaction w/o real CIMC +@patch.object(UcsHandle, 'commit') +# Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC +@patch.object(UcsHandle, 'add_mo') +def test_valid_disk_state(add_mo_mock, commit_mock): + add_mo_mock.return_value = True + commit_mock.return_value = True + handle = UcsHandle('169.254.1.1', 'admin', 'password') + + # Scenario: jbod mode + test_retval = disk_state_set(handle, 1, 4, "jbod") + assert test_retval.admin_action == "jbod" + assert test_retval.dn == "sys/rack-unit-1/board/storage-SAS-1/disk-4" + + # Scenario: unconfigured-good mode + test_retval = disk_state_set(handle, 2, 5, "unconfigured-good") + assert test_retval.admin_action == "unconfigured-good" + assert test_retval.dn == "sys/rack-unit-2/board/storage-SAS-1/disk-5" + + # Scenario: custom controller + test_retval = disk_state_set(handle, 3, 6, "jbod", "storage-SAS-4") + assert test_retval.dn == "sys/rack-unit-3/board/storage-SAS-4/disk-6" + + +# Patch UcsHandle.commit to simulate CIMC interaction w/o real CIMC +@patch.object(UcsHandle, 'commit') +# Patch UcsHandle.add_mo to simulate CIMC interaction w/o real CIMC +@patch.object(UcsHandle, 'add_mo') +def test_invalid_disk_state(add_mo_mock, commit_mock): + add_mo_mock.return_value = True + commit_mock.return_value = True + handle = UcsHandle('169.254.1.1', 'admin', 'password') + + # Scenario invalid state + assert_raises(ValueError, disk_state_set, handle, 16, 1, "blah") diff --git a/ucsmsdk_samples/admin/domain.py b/ucsmsdk_samples/admin/domain.py index 84be6a3..b6ff2bc 100755 --- a/ucsmsdk_samples/admin/domain.py +++ b/ucsmsdk_samples/admin/domain.py @@ -70,11 +70,11 @@ def domain_exists(handle, name, refresh_period="600", session_timeout="7200", dn = "sys/svc-ext/dns-svc/dns-" + name mo = handle.query_dn(dn) if mo: - if ((descr and (mo.descr != descr)) - and - (refresh_period and (mo.refresh_period != refresh_period)) - and - (session_timeout and (mo.session_timeout != session_timeout))): + if ( + (descr and (mo.descr != descr)) and + (refresh_period and (mo.refresh_period != refresh_period)) and + (session_timeout and (mo.session_timeout != session_timeout)) + ): return False return True return False diff --git a/ucsmsdk_samples/admin/keyring.py b/ucsmsdk_samples/admin/keyring.py index 276d75a..eb357f1 100755 --- a/ucsmsdk_samples/admin/keyring.py +++ b/ucsmsdk_samples/admin/keyring.py @@ -78,12 +78,14 @@ def key_ring_exists(handle, name, descr="", policy_owner="local", tp="", dn = "sys/pki-ext/keyring-" + name mo = handle.query_dn(dn) if mo: - if ((descr and mo.descr != descr) and + if ( + (descr and mo.descr != descr) and (policy_owner and mo.policy_owner != policy_owner) and (tp and mo.tp != tp) and (cert and mo.cert != cert) and (regen and mo.regen != regen) and - (modulus and mo.modulus != modulus)): + (modulus and mo.modulus != modulus) + ): return False return True return False @@ -273,7 +275,8 @@ def certificate_request_exists(handle, name, dns="", locality="", state="", dn = "sys/pki-ext/keyring-" + name + "certreq" mo = handle.query_dn(dn) if mo: - if ((dns and mo.dns != dns) and + if ( + (dns and mo.dns != dns) and (locality and mo.locality != locality) and (state and mo.state != state) and (country and mo.country != country) and @@ -287,7 +290,8 @@ def certificate_request_exists(handle, name, dns="", locality="", state="", (ip_b and mo.ip_b != ip_b) and (ipv6 and mo.ipv6 != ipv6) and (ipv6_a and mo.ipv6_a != ipv6_a) and - (ipv6_b and mo.ipv6_b != ipv6_b)): + (ipv6_b and mo.ipv6_b != ipv6_b) + ): return False return True return False diff --git a/ucsmsdk_samples/admin/ldap.py b/ucsmsdk_samples/admin/ldap.py index fa846da..42073c3 100755 --- a/ucsmsdk_samples/admin/ldap.py +++ b/ucsmsdk_samples/admin/ldap.py @@ -100,7 +100,8 @@ def ldap_provider_exists(handle, name, order="lowest-available", rootdn="", dn = "sys/ldap-ext/provider-" + name mo = handle.query_dn(dn) if mo: - if ((order and mo.order != order) and + if ( + (order and mo.order != order) and (rootdn and mo.rootdn != rootdn) and (basedn and mo.basedn != basedn) and (port and mo.port != port) and @@ -111,7 +112,8 @@ def ldap_provider_exists(handle, name, order="lowest-available", rootdn="", (timeout and mo.timeout != timeout) and (vendor and mo.vendor != vendor) and (retries and mo.retries != retries) and - (descr and mo.descr != descr)): + (descr and mo.descr != descr) + ): return False return True return False @@ -581,8 +583,7 @@ def ldap_provider_group_provider_exists(handle, group_name, name, order, provider_dn = group_dn + "/provider-ref-" + name mo = handle.query_dn(provider_dn) if mo: - if ((descr and mo.descr != descr) and - (order and mo.order != order)): + if ((descr and mo.descr != descr) and (order and mo.order != order)): return False return True return False diff --git a/ucsmsdk_samples/admin/locale.py b/ucsmsdk_samples/admin/locale.py index b4559db..d4eea6d 100755 --- a/ucsmsdk_samples/admin/locale.py +++ b/ucsmsdk_samples/admin/locale.py @@ -64,8 +64,10 @@ def locale_exists(handle, name, descr="", policy_owner="local"): dn = "sys/user-ext/locale-" + name mo = handle.query_dn(dn) if mo: - if ((descr and mo.descr != descr) and - (policy_owner and mo.policy_owner != policy_owner)): + if ( + (descr and mo.descr != descr) and + (policy_owner and mo.policy_owner != policy_owner) + ): return False return True return False diff --git a/ucsmsdk_samples/admin/radius.py b/ucsmsdk_samples/admin/radius.py index 1ccae70..1d034f7 100755 --- a/ucsmsdk_samples/admin/radius.py +++ b/ucsmsdk_samples/admin/radius.py @@ -83,13 +83,15 @@ def radius_provider_exists(handle, name, order="lowest-available", key="", dn = "sys/radius-ext/provider-" + name mo = handle.query_dn(dn) if mo: - if ((order and mo.order != order) and + if ( + (order and mo.order != order) and (key and mo.key != key) and (auth_port and mo.auth_port != auth_port) and (timeout and mo.timeout != timeout) and (retries and mo.retries != retries) and (enc_key and mo.enc_key != enc_key) and - (descr and mo.descr != descr)): + (descr and mo.descr != descr) + ): return False return True return False @@ -331,8 +333,7 @@ def radius_provider_group_provider_exists(handle, group_name, name, order, raise ValueError("Radius Provider does not exist.") if mo: - if ((order and mo.order != order) and - (descr and mo.descr != descr)): + if ((order and mo.order != order) and (descr and mo.descr != descr)): return False return True return False diff --git a/ucsmsdk_samples/admin/role.py b/ucsmsdk_samples/admin/role.py index e80b67a..5def400 100755 --- a/ucsmsdk_samples/admin/role.py +++ b/ucsmsdk_samples/admin/role.py @@ -68,9 +68,11 @@ def role_exists(handle, name, priv, descr="", policy_owner="local"): dn = "sys/user-ext/role-" + name mo = handle.query_dn(dn) if mo: - if ((priv and mo.priv != priv) and + if ( + (priv and mo.priv != priv) and (descr and mo.descr != descr) and - (policy_owner and mo.policy_owner != policy_owner)): + (policy_owner and mo.policy_owner != policy_owner) + ): return False return True return False diff --git a/ucsmsdk_samples/admin/snmp.py b/ucsmsdk_samples/admin/snmp.py index 40631e2..9a478c7 100755 --- a/ucsmsdk_samples/admin/snmp.py +++ b/ucsmsdk_samples/admin/snmp.py @@ -171,12 +171,14 @@ def snmp_trap_exists(handle, hostname, community, port, version="v3", dn = "sys/svc-ext/snmp-svc/snmp-trap" + hostname mo = handle.query_dn(dn) if mo: - if ((community and mo.community != community) and + if ( + (community and mo.community != community) and (port and mo.port != port) and (version and mo.version != version) and (notification_type and mo.notification_type != notification_type) and - (v3_privilege and mo.v3_privilege != v3_privilege)): + (v3_privilege and mo.v3_privilege != v3_privilege) + ): return False return True return False @@ -325,11 +327,13 @@ def snmp_user_exists(handle, name, descr, pwd, privpwd, auth="md5", dn = "sys/svc-ext/snmp-svc/snmpv3-user-" + name mo = handle.query_dn(dn) if mo: - if ((descr and mo.descr != descr) and + if ( + (descr and mo.descr != descr) and (pwd and mo.pwd != pwd) and (privpwd and mo.privpwd != privpwd) and (auth and mo.auth != auth) and - (use_aes and mo.use_aes != use_aes)): + (use_aes and mo.use_aes != use_aes) + ): return False return True return False diff --git a/ucsmsdk_samples/admin/tacacsplus.py b/ucsmsdk_samples/admin/tacacsplus.py index 434fdaa..52338a0 100755 --- a/ucsmsdk_samples/admin/tacacsplus.py +++ b/ucsmsdk_samples/admin/tacacsplus.py @@ -84,13 +84,15 @@ def tacacsplus_provider_exists(handle, name, order="lowest-available", key="", dn = "sys/tacacs-ext/provider-" + name mo = handle.query_dn(dn) if mo: - if ((order and mo.order != order) and + if ( + (order and mo.order != order) and (key and mo.key != key) and (port and mo.port != port) and (timeout and mo.timeout != timeout) and (retries and mo.retries != retries) and (enc_key and mo.enc_key != enc_key) and - (descr and mo.descr != descr)): + (descr and mo.descr != descr) + ): return False return True return False @@ -329,8 +331,10 @@ def tacacsplus_provider_group_provider_exists(handle, group_name, name, order, provider_dn = "sys/tacacs-ext/provider-" + name mo = handle.query_dn(provider_dn) if mo: - if ((descr and mo.descr != descr) and - (order and mo.order != order)): + if ( + (descr and mo.descr != descr) and + (order and mo.order != order) + ): return False return True return False diff --git a/ucsmsdk_samples/admin/user.py b/ucsmsdk_samples/admin/user.py index 557a4c9..6f8ffed 100755 --- a/ucsmsdk_samples/admin/user.py +++ b/ucsmsdk_samples/admin/user.py @@ -118,7 +118,8 @@ def user_exists(handle, name, first_name, last_name, descr, clear_pwd_history, dn = "sys/user-ext/user-" + name mo = handle.query_dn(dn) if mo: - if ((first_name and mo.first_name != first_name) and + if ( + (first_name and mo.first_name != first_name) and (last_name and mo.last_name != last_name) and (descr and mo.descr != descr) and (clear_pwd_history and @@ -131,7 +132,8 @@ def user_exists(handle, name, first_name, last_name, descr, clear_pwd_history, (expiration and mo.expiration != expiration) and (enc_pwd and mo.enc_pwd != enc_pwd) and (enc_pwd_set and mo.enc_pwd_set != enc_pwd_set) and - (account_status and mo.account_status != account_status)): + (account_status and mo.account_status != account_status) + ): return False return True return False diff --git a/ucsmsdk_samples/firmware/ucsfirmware.py b/ucsmsdk_samples/firmware/ucsfirmware.py index 7053589..e7fa0d0 100755 --- a/ucsmsdk_samples/firmware/ucsfirmware.py +++ b/ucsmsdk_samples/firmware/ucsfirmware.py @@ -706,7 +706,7 @@ def firmware_activate_infra(handle, version="2.2(2c)", if require_user_confirmation: set_flag = False set_str = input("Are you sure want to proceed? This will reboot " - "theFabric Interconnects. Enter 'yes' to proceed.") + "theFabric Interconnects. Enter 'yes' to proceed.") if set_str.strip().lower() == "yes": set_flag = True @@ -851,10 +851,10 @@ def wait_for_blade_activation(handle, if require_user_confirmation: set_flag = False set_str = input("The update process will need to " - "reboot the server(s). " - "Would you like to acknowledge " - "the same?" - "Enter 'yes' to proceed.") + "reboot the server(s). " + "Would you like to acknowledge " + "the same?" + "Enter 'yes' to proceed.") if set_str.strip().lower() == "yes": set_flag = True @@ -957,8 +957,8 @@ def firmware_activate_blade(handle, version, require_user_confirmation=True): if require_user_confirmation: set_flag = False set_str = input("Are you sure want to proceed? This will " - "reboot the server." - "Enter 'yes' to proceed.") + "reboot the server." + "Enter 'yes' to proceed.") if set_str.strip().lower() == "yes": set_flag = True @@ -972,9 +972,9 @@ def firmware_activate_blade(handle, version, require_user_confirmation=True): if require_user_confirmation: set_flag = False set_str = input("The update process will need to reboot " - "the server(s). Would you like to " - "acknowledge the same?" - "Enter 'yes' to proceed.") + "the server(s). Would you like to " + "acknowledge the same?" + "Enter 'yes' to proceed.") if set_str.strip().lower() == "yes": set_flag = True diff --git a/ucsmsdk_samples/network/ip_pools.py b/ucsmsdk_samples/network/ip_pools.py index b570b2e..da3faed 100755 --- a/ucsmsdk_samples/network/ip_pools.py +++ b/ucsmsdk_samples/network/ip_pools.py @@ -57,6 +57,7 @@ def ip_pool_create(handle, name, assignment_order, handle.commit() return mo + def ip_pool_remove(handle, name, parent_dn="org-root"): """ Removes the specified IP Pool @@ -126,7 +127,7 @@ def add_ip_block(handle, r_from, to, subnet, default_gw, prim_dns, sec_dns, handle.add_mo(mo, True) handle.commit() return mo - + def ip_block_remove(handle, name, parent_dn="org-root"): """ @@ -140,7 +141,8 @@ def ip_block_remove(handle, name, parent_dn="org-root"): Raises: ValueError: If IP Block is not present Example: - ip_block_remove(handle, "1.1.1.1-1.1.1.253", parent_dn="org-root/org-demo/ip-pool-cimc") + ip_block_remove(handle, "1.1.1.1-1.1.1.253", + parent_dn="org-root/org-demo/ip-pool-cimc") """ dn = parent_dn + "/block-" + name diff --git a/ucsmsdk_samples/network/lan_conn_policy.py b/ucsmsdk_samples/network/lan_conn_policy.py index 0fc8650..f7bdac5 100755 --- a/ucsmsdk_samples/network/lan_conn_policy.py +++ b/ucsmsdk_samples/network/lan_conn_policy.py @@ -247,16 +247,21 @@ def vnic_exists(handle, parent_dn, name, nw_ctrl_policy_name=None, dn = parent_dn + '/ether-' + name mo = handle.query_dn(dn) if mo: - if ((nw_ctrl_policy_name - and mo.nw_ctrl_policy_name != nw_ctrl_policy_name) and + if ( + ( + nw_ctrl_policy_name and + mo.nw_ctrl_policy_name != nw_ctrl_policy_name + ) and (admin_host_port and mo.admin_host_port != admin_host_port) and (admin_vcon and mo.admin_vcon != admin_vcon) and (stats_policy_name and mo.stats_policy_name != stats_policy_name) and (admin_cdn_name and mo.admin_cdn_name != admin_cdn_name) and (switch_id and mo.switch_id != switch_id) and - (pin_to_group_name and mo.pin_to_group_name != pin_to_group_name) - and + ( + pin_to_group_name and + mo.pin_to_group_name != pin_to_group_name + ) and (mtu and mo.mtu != mtu) and (qos_policy_name and mo.qos_policy_name != qos_policy_name) and (adaptor_profile_name and mo.adaptor_profile_name != @@ -264,7 +269,8 @@ def vnic_exists(handle, parent_dn, name, nw_ctrl_policy_name=None, (ident_pool_name and mo.ident_pool_name != ident_pool_name) and (order and mo.order != order) and (nw_templ_name and mo.nw_templ_name != nw_templ_name) and - (addr and mo.addr != addr)): + (addr and mo.addr != addr) + ): return False return True return False @@ -413,15 +419,20 @@ def vnic_iscsi_exists(handle, parent_dn, name, addr=None, admin_host_port=None, dn = parent_dn + '/iscsi-' + name mo = handle.query_dn(dn) if mo: - if ((addr and mo.addr != addr) and + if ( + (addr and mo.addr != addr) and (admin_host_port and mo.admin_host_port != admin_host_port) and (admin_vcon and mo.admin_vcon != admin_vcon) and - (stats_policy_name and mo.stats_policy_name != stats_policy_name) - and + ( + stats_policy_name and + mo.stats_policy_name != stats_policy_name + ) and (admin_cdn_name and mo.admin_cdn_name != admin_cdn_name) and (switch_id and mo.switch_id != switch_id) and - (pin_to_group_name and mo.pin_to_group_name != pin_to_group_name) - and + ( + pin_to_group_name and + mo.pin_to_group_name != pin_to_group_name + ) and (vnic_name and mo.vnic_name != vnic_name) and (qos_policy_name and mo.qos_policy_name != qos_policy_name) and (adaptor_profile_name and mo.adaptor_profile_name != @@ -429,7 +440,8 @@ def vnic_iscsi_exists(handle, parent_dn, name, addr=None, admin_host_port=None, (ident_pool_name and mo.ident_pool_name != ident_pool_name) and (order and mo.order != order) and (nw_templ_name and mo.nw_templ_name != nw_templ_name) and - (vlan_name and mo.vlan_name != vlan_name)): + (vlan_name and mo.vlan_name != vlan_name) + ): return False return True return False diff --git a/ucsmsdk_samples/network/nwctrl_policy.py b/ucsmsdk_samples/network/nwctrl_policy.py index 453d22b..d4bd33b 100755 --- a/ucsmsdk_samples/network/nwctrl_policy.py +++ b/ucsmsdk_samples/network/nwctrl_policy.py @@ -135,15 +135,17 @@ def nw_control_policy_exists(handle, name, cdp=None, mac_register_mode=None, dn = parent_dn + '/nwctrl-' + name mo = handle.query_dn(dn) if mo: - if ((cdp and mo.cdp != cdp) and - (mac_register_mode and mo.mac_register_mode - != mac_register_mode) and - (uplink_fail_action and mo.uplink_fail_action - != uplink_fail_action) and + if ( + (cdp and mo.cdp != cdp) and + (mac_register_mode and + mo.mac_register_mode != mac_register_mode) and + (uplink_fail_action and + mo.uplink_fail_action != uplink_fail_action) and (forge and mo.forge != forge) and (lldp_transmit and mo.lldp_transmit != lldp_transmit) and (lldp_receive and mo.lldp_receive != lldp_receive) and - (descr and mo.descr != descr)): + (descr and mo.descr != descr) + ): return False return True return False diff --git a/ucsmsdk_samples/network/qos.py b/ucsmsdk_samples/network/qos.py index 68f412c..01f1735 100755 --- a/ucsmsdk_samples/network/qos.py +++ b/ucsmsdk_samples/network/qos.py @@ -57,7 +57,7 @@ def qos_class_enable(handle, priority, weight="normal", mtu="normal", qos_class = handle.query_dn("fabric/lan/classes/class-" + priority) if qos_class: qos_class.weight = weight - qos_class.cos = cos + qos_class.cos = cos else: raise ValueError("QoS class %s is not available" % priority) else: @@ -135,13 +135,13 @@ def qos_class_conf_drift(handle, priority, admin_state=None, cos=None, dn = "fabric/lan/classes/class-" + priority mo = handle.query_dn(dn) if mo: - # the mo is present and already disabled + # the mo is present and already disabled if admin_state == "disabled" and mo.admin_state == admin_state: - return False + return False # the mo is present and not disabled. Need to act if admin_state == "disabled" and mo.admin_state != admin_state: - return True + return True # the mo is present and already enabled if admin_state == "enabled" and mo.admin_state == admin_state: @@ -150,8 +150,8 @@ def qos_class_conf_drift(handle, priority, admin_state=None, cos=None, (drop and mo.drop != drop) or (weight and mo.weight != weight) or (mtu and mo.mtu != mtu) or - (multicast_optimize and mo.multicast_optimize - != multicast_optimize)): + (multicast_optimize and + mo.multicast_optimize != multicast_optimize)): # configuration drift detected return True # passed prop:val and mo[prop:val] are same. @@ -161,7 +161,6 @@ def qos_class_conf_drift(handle, priority, admin_state=None, cos=None, # the mo is present and not enabled. Need to act if admin_state == "enabled" and mo.admin_state != admin_state: return True - return False @@ -271,10 +270,12 @@ def qos_policy_exists(handle, name, priority=None, burst=None, rate=None, dn = parent_dn + '/ep-qos-' + name mo = handle.query_dn(dn) if mo: - if ((priority and mo.priority != priority) and + if ( + (priority and mo.priority != priority) and (burst and mo.burst != burst) and (rate and mo.rate != rate) and - (host_control and mo.host_control != host_control)): + (host_control and mo.host_control != host_control) + ): return False return True return False diff --git a/ucsmsdk_samples/network/server_port.py b/ucsmsdk_samples/network/server_port.py index 01b6915..0d7b1f1 100755 --- a/ucsmsdk_samples/network/server_port.py +++ b/ucsmsdk_samples/network/server_port.py @@ -19,13 +19,13 @@ def server_port_create(handle, dn, port_id, slot_id): """ This method configures the port as a server port - + Args: handle (Handle) dn (string): parent_dn port_id (number): Port id of the port slot_id (number): Slot id of the port - + Returns: FabricDceSwSrvEp @@ -36,7 +36,7 @@ def server_port_create(handle, dn, port_id, slot_id): from ucsmsdk.mometa.fabric.FabricDceSwSrvEp import \ FabricDceSwSrvEp - + mo = FabricDceSwSrvEp(parent_mo_or_dn=dn, slot_id=slot_id, port_id=port_id) handle.add_mo(mo, modify_present=False) handle.commit() diff --git a/ucsmsdk_samples/network/uplink_port.py b/ucsmsdk_samples/network/uplink_port.py index 51191b6..bc78665 100755 --- a/ucsmsdk_samples/network/uplink_port.py +++ b/ucsmsdk_samples/network/uplink_port.py @@ -19,13 +19,13 @@ def uplink_port_create(handle, dn, port_id, slot_id): """ This method configures the port as an uplink port - + Args: handle (Handle) dn (string): parent_dn port_id (number): Port id of the port slot_id (number): Slot id of the port - + Returns: FabricEthLanEp @@ -36,7 +36,7 @@ def uplink_port_create(handle, dn, port_id, slot_id): from ucsmsdk.mometa.fabric.FabricEthLanEp import \ FabricEthLanEp - + mo = FabricEthLanEp(parent_mo_or_dn=dn, slot_id=slot_id, port_id=port_id) handle.add_mo(mo, modify_present=False) handle.commit() diff --git a/ucsmsdk_samples/network/vlan.py b/ucsmsdk_samples/network/vlan.py index 35e348f..3ab3c40 100755 --- a/ucsmsdk_samples/network/vlan.py +++ b/ucsmsdk_samples/network/vlan.py @@ -125,13 +125,15 @@ def vlan_exists(handle, name, vlan_id=None, sharing=None, dn = parent_dn + '/net-' + name mo = handle.query_dn(dn) if mo: - if ((vlan_id and mo.vlan_id != vlan_id) and + if ( + (vlan_id and mo.vlan_id != vlan_id) and (sharing and mo.sharing != sharing) and - (mcast_policy_name and mo.mcast_policy_name - != mcast_policy_name) and + (mcast_policy_name and + mo.mcast_policy_name != mcast_policy_name) and (compression_type and mo.compression_type != compression_type) and (default_net and mo.default_net != default_net) and - (pub_nw_name and mo.pub_nw_name != pub_nw_name)): + (pub_nw_name and mo.pub_nw_name != pub_nw_name) + ): return False return True return False diff --git a/ucsmsdk_samples/network/vnic.py b/ucsmsdk_samples/network/vnic.py index 5b3f352..ebb24cd 100755 --- a/ucsmsdk_samples/network/vnic.py +++ b/ucsmsdk_samples/network/vnic.py @@ -197,21 +197,23 @@ def vnic_template_exists(handle, name, con_policy_type=None, mo = handle.query_dn(dn) # TODO: Compare vlans associated with the vnic template if mo: - if ((con_policy_type and mo.con_policy_type != con_policy_type) and + if ( + (con_policy_type and mo.con_policy_type != con_policy_type) and (con_policy_name and mo.con_policy_name != con_policy_name) and (mtu and mo.mtu != mtu) and (qos_policy_name and mo.qos_policy_name != qos_policy_name) and (target and mo.target != target) and (ident_pool_name and mo.ident_pool_name != ident_pool_name) and - (nw_ctrl_policy_name and mo.nw_ctrl_policy_name - != nw_ctrl_policy_name) and - (pin_to_group_name and mo.pin_to_group_name - != pin_to_group_name) and + (nw_ctrl_policy_name and + mo.nw_ctrl_policy_name != nw_ctrl_policy_name) and + (pin_to_group_name and + mo.pin_to_group_name != pin_to_group_name) and (switch_id and mo.switch_id != switch_id) and - (stats_policy_name and mo.stats_policy_name - != stats_policy_name) and + (stats_policy_name and + mo.stats_policy_name != stats_policy_name) and (templ_type and mo.templ_type != templ_type) and - (descr and mo.descr != descr)): + (descr and mo.descr != descr) + ): return False return True return False diff --git a/ucsmsdk_samples/reports/serials.py b/ucsmsdk_samples/reports/serials.py index ecadbe5..540c515 100644 --- a/ucsmsdk_samples/reports/serials.py +++ b/ucsmsdk_samples/reports/serials.py @@ -12,16 +12,17 @@ # limitations under the License. - def domain_serials(handle): """ - This function will query all of the models and serial numbers from the ucs domain + This function will query all of the models and serial numbers + from the ucs domain Args: handle (UcsHandle) - + Returns: - Dictionary of dn, model, and serial for chassis, interconnects, and blades + Dictionary of dn, model, and serial + for chassis, interconnects, and blades Raises: None @@ -29,13 +30,14 @@ def domain_serials(handle): Example: domain_serials(handle) """ - + query_dict = {} query_dict['chassis'] = {} query_dict['fi'] = {} query_dict['blade'] = {} - query_data = handle.query_classids('orgOrg', 'EquipmentChassis', 'NetworkElement', 'ComputeBlade') + query_data = handle.query_classids('orgOrg', 'EquipmentChassis', + 'NetworkElement', 'ComputeBlade') for chassis in query_data['EquipmentChassis']: query_dict['chassis'][chassis.dn] = {} @@ -52,4 +54,4 @@ def domain_serials(handle): query_dict['blade'][blade.dn]['model'] = blade.model query_dict['blade'][blade.dn]['serial'] = blade.serial - return query_dict \ No newline at end of file + return query_dict diff --git a/ucsmsdk_samples/server/bios.py b/ucsmsdk_samples/server/bios.py index b0879ab..982c8ac 100755 --- a/ucsmsdk_samples/server/bios.py +++ b/ucsmsdk_samples/server/bios.py @@ -85,27 +85,27 @@ def bios_create(handle, parent_org_dn, name, descr="", parent_mo_or_dn=obj, name=name, descr=descr, reboot_on_update=reboot_on_update) - mo_1 = BiosVfConsistentDeviceNameControl( + BiosVfConsistentDeviceNameControl( parent_mo_or_dn=mo, vp_cdn_control=vp_cdn_control) - mo_2 = BiosVfFrontPanelLockout( + BiosVfFrontPanelLockout( parent_mo_or_dn=mo, vp_front_panel_lockout=vp_front_panel_lockout) - mo_3 = BiosVfPOSTErrorPause( + BiosVfPOSTErrorPause( parent_mo_or_dn=mo, vp_post_error_pause=vp_post_error_pause) - mo_4 = BiosVfQuietBoot(parent_mo_or_dn=mo, vp_quiet_boot=vp_quiet_boot) + BiosVfQuietBoot(parent_mo_or_dn=mo, vp_quiet_boot=vp_quiet_boot) - mo_5 = BiosVfResumeOnACPowerLoss( + BiosVfResumeOnACPowerLoss( parent_mo_or_dn=mo, vp_resume_on_ac_power_loss=vp_resume_on_ac_power_loss) - mo_6 = BiosVfSerialPortAEnable( + BiosVfSerialPortAEnable( parent_mo_or_dn=mo, vp_serial_port_a_enable=vp_serial_port_a_enable) - mo_7 = BiosVfConsoleRedirection( + BiosVfConsoleRedirection( parent_mo_or_dn=mo, vp_baud_rate=vp_baud_rate, vp_console_redirection=vp_console_redirection, @@ -510,8 +510,8 @@ def bios_conf_intel_speed_step( if obj: mo = BiosVfEnhancedIntelSpeedStepTech( parent_mo_or_dn=obj, - vp_enhanced_intel_speed_step_tech= - vp_enhanced_intel_speed_step_tech) + vp_enhanced_intel_speed_step_tech=vp_enhanced_intel_speed_step_tech + ) handle.add_mo(mo, True) handle.commit() else: @@ -665,13 +665,15 @@ def bios_conf_virtual_tech( from ucsmsdk.mometa.bios.BiosVfIntelVirtualizationTechnology import \ BiosVfIntelVirtualizationTechnology + # Shorten variable name to satisfy flake8, but keep backward compatibility + vp_intel_virt_tech = vp_intel_virtualization_technology + profile_dn = parent_org_dn + "/bios-prof-" + name obj = handle.query_dn(profile_dn) if obj: mo = BiosVfIntelVirtualizationTechnology( parent_mo_or_dn=obj, - vp_intel_virtualization_technology= - vp_intel_virtualization_technology) + vp_intel_virtualization_technology=vp_intel_virt_tech) handle.add_mo(mo, True) handle.commit() return mo @@ -714,14 +716,16 @@ def bios_conf_processor_prefetch( from ucsmsdk.mometa.bios.BiosVfProcessorPrefetchConfig import \ BiosVfProcessorPrefetchConfig + # Shorten variable name to satisfy flake8, but keep backward compatibility + vp_adj_cache_line_prefetcher = vp_adjacent_cache_line_prefetcher + profile_dn = parent_org_dn + "/bios-prof-" + name obj = handle.query_dn(profile_dn) if obj: mo = BiosVfProcessorPrefetchConfig( parent_mo_or_dn=obj, vp_dcuip_prefetcher=vp_dcuip_prefetcher, - vp_adjacent_cache_line_prefetcher= - vp_adjacent_cache_line_prefetcher, + vp_adjacent_cache_line_prefetcher=vp_adj_cache_line_prefetcher, vp_hardware_prefetcher=vp_hardware_prefetcher, vp_dcu_streamer_prefetch=vp_dcu_streamer_prefetch) handle.add_mo(mo, True) @@ -1392,13 +1396,15 @@ def bios_conf_intel_directed_io( from ucsmsdk.mometa.bios.BiosVfIntelVTForDirectedIO import \ BiosVfIntelVTForDirectedIO + # Shorten variable name to satisfy flake8, but keep backward compatibility + vp_intel_vtd_pass_thru_dma = vp_intel_vtd_pass_through_dma_support + profile_dn = parent_org_dn + "/bios-prof-" + name obj = handle.query_dn(profile_dn) if obj: mo = BiosVfIntelVTForDirectedIO( parent_mo_or_dn=obj, - vp_intel_vtd_pass_through_dma_support= - vp_intel_vtd_pass_through_dma_support, + vp_intel_vtd_pass_through_dma_support=vp_intel_vtd_pass_thru_dma, vp_intel_vtdats_support=vp_intel_vtdats_support, vp_intel_vtd_interrupt_remapping=vp_intel_vtd_interrupt_remapping, vp_intel_vtd_coherency_support=vp_intel_vtd_coherency_support, @@ -1437,13 +1443,15 @@ def bios_conf_ras_memory( from ucsmsdk.mometa.bios.BiosVfSelectMemoryRASConfiguration import \ BiosVfSelectMemoryRASConfiguration + # Shorten variable name to satisfy flake8, but keep backward compatibility + vp_select_memory_ras_config = vp_select_memory_ras_configuration + profile_dn = parent_org_dn + "/bios-prof-" + name obj = handle.query_dn(profile_dn) if obj: mo = BiosVfSelectMemoryRASConfiguration( parent_mo_or_dn=obj, - vp_select_memory_ras_configuration= - vp_select_memory_ras_configuration) + vp_select_memory_ras_configuration=vp_select_memory_ras_config) handle.add_mo(mo, True) handle.commit() return mo @@ -2145,13 +2153,15 @@ def bios_conf_trusted_platform( from ucsmsdk.mometa.bios.BiosVfTrustedPlatformModule import \ BiosVfTrustedPlatformModule + # Shorten variable name to satisfy flake8, but keep backward compatibility + vp_trusted_platform_mod_support = vp_trusted_platform_module_support + profile_dn = parent_org_dn + "/bios-prof-" + name obj = handle.query_dn(profile_dn) if obj: mo = BiosVfTrustedPlatformModule( parent_mo_or_dn=obj, - vp_trusted_platform_module_support= - vp_trusted_platform_module_support) + vp_trusted_platform_module_support=vp_trusted_platform_mod_support) handle.add_mo(mo, True) handle.commit() return mo @@ -2186,13 +2196,15 @@ def bios_conf_trusted_execution( from ucsmsdk.mometa.bios.BiosVfIntelTrustedExecutionTechnology import \ BiosVfIntelTrustedExecutionTechnology + # Shorten variable name to satisfy flake8, but keep backward compatibility + vp_trust_exec_tech = vp_intel_trusted_execution_technology_support + profile_dn = parent_org_dn + "/bios-prof-" + name obj = handle.query_dn(profile_dn) if obj: mo = BiosVfIntelTrustedExecutionTechnology( parent_mo_or_dn=obj, - vp_intel_trusted_execution_technology_support= - vp_intel_trusted_execution_technology_support) + vp_intel_trusted_execution_technology_support=vp_trust_exec_tech) handle.add_mo(mo, True) handle.commit() return mo @@ -2498,13 +2510,15 @@ def bios_conf_boot_watchdog_timer_timeout( from ucsmsdk.mometa.bios.BiosVfOSBootWatchdogTimerTimeout import \ BiosVfOSBootWatchdogTimerTimeout + # Shorten variable name to satisfy flake8, but keep backward compatibility + vp_boot_watchdog_timer_timeout = vp_os_boot_watchdog_timer_timeout + profile_dn = parent_org_dn + "/bios-prof-" + name obj = handle.query_dn(profile_dn) if obj: mo = BiosVfOSBootWatchdogTimerTimeout( parent_mo_or_dn=obj, - vp_os_boot_watchdog_timer_timeout= - vp_os_boot_watchdog_timer_timeout) + vp_os_boot_watchdog_timer_timeout=vp_boot_watchdog_timer_timeout) handle.add_mo(mo, True) handle.commit() else: diff --git a/ucsmsdk_samples/server/boot_policy.py b/ucsmsdk_samples/server/boot_policy.py index 417b358..0ccd2b3 100755 --- a/ucsmsdk_samples/server/boot_policy.py +++ b/ucsmsdk_samples/server/boot_policy.py @@ -13,9 +13,6 @@ import logging -log = logging.getLogger('ucs') - - from ucsmsdk.mometa.lsboot.LsbootVirtualMedia import LsbootVirtualMedia from ucsmsdk.mometa.lsboot.LsbootStorage import LsbootStorage from ucsmsdk.mometa.lsboot.LsbootLocalStorage import LsbootLocalStorage @@ -28,6 +25,9 @@ from ucsmsdk.mometa.lsboot.LsbootUsbExternalImage import LsbootUsbExternalImage +log = logging.getLogger('ucs') + + def boot_policy_create(handle, name, descr="", reboot_on_update="yes", enforce_vnic_name="yes", @@ -184,13 +184,13 @@ def boot_policy_exist(handle, name, reboot_on_update="yes", dn = parent_dn + "/boot-policy-" + name mo = handle.query_dn(dn) if mo: - if ((boot_mode and mo.boot_mode != boot_mode) - and - (reboot_on_update and mo.reboot_on_update != reboot_on_update) - and + if ( + (boot_mode and mo.boot_mode != boot_mode) and + (reboot_on_update and mo.reboot_on_update != reboot_on_update) and (enforce_vnic_name and - mo.enforce_vnic_name != enforce_vnic_name)and - (descr and mo.descr != descr)): + mo.enforce_vnic_name != enforce_vnic_name) and + (descr and mo.descr != descr) + ): return False return True return False @@ -206,7 +206,7 @@ def _add_device(handle, parent_mo, boot_device): log.debug("Deleting boot device from boot policy: %s", child.dn) handle.remove_mo(child) - + for k in boot_device.keys(): log.debug("Add boot device: order=%s, %s", k, boot_device[k]) if boot_device[k] in ["cdrom-local", "cdrom"]: diff --git a/ucsmsdk_samples/server/hfp_policy.py b/ucsmsdk_samples/server/hfp_policy.py index 128c372..798b6b0 100755 --- a/ucsmsdk_samples/server/hfp_policy.py +++ b/ucsmsdk_samples/server/hfp_policy.py @@ -155,12 +155,14 @@ def hfp_exists(handle, name, blade_bundle_version, rack_bundle_version, dn = parent_dn + "/fw-host-pack-" + name mo = handle.query_dn(dn) if mo: - if ((blade_bundle_version and + if ( + (blade_bundle_version and mo.blade_bundle_version != blade_bundle_version) and (rack_bundle_version and mo.rack_bundle_version != rack_bundle_version) and (mode and mo.mode != mode) and - (descr and mo.descr != descr)): + (descr and mo.descr != descr) + ): return False return True return False diff --git a/ucsmsdk_samples/server/ipmi_policy.py b/ucsmsdk_samples/server/ipmi_policy.py new file mode 100644 index 0000000..d4f3cac --- /dev/null +++ b/ucsmsdk_samples/server/ipmi_policy.py @@ -0,0 +1,53 @@ +# Copyright 2016 Cisco Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from ucsmsdk.mometa.aaa.AaaEpAuthProfile import AaaEpAuthProfile +from ucsmsdk.mometa.aaa.AaaEpUser import AaaEpUser + + +def ipmi_policy_create(handle, name, descr="", parent_dn="org-root", + username="admin", password=None): + """ + This method creates AaaEpAuthProfile policy, with optional + username and password. + + Args: + handle (UcsHandle) + name (string): Name of the AaaEpAuthProfile policy. + descr (string): Basic description. + parent_dn (string): Parent of Org. + username (string): username for authenticating the IPMI + password (string): password of user + + Returns: + AaaEpAuthProfile: Managed Object + + Example: + ipmi_policy_create(handle, name="sample_ipmi_pol", + parent_dn="org-root/org-sub") + + """ + + obj = handle.query_dn(parent_dn) + if not obj: + raise ValueError("org '%s' does not exist" % parent_dn) + + mo = AaaEpAuthProfile(parent_mo_or_dn=obj, policy_owner="local", + ipmi_over_lan="enable", name=name, descr=descr) + if password is not None: + AaaEpUser(parent_mo_or_dn=mo, pwd=password, name=username, + descr="", priv="admin") + handle.add_mo(mo, modify_present=True) + handle.commit() + return mo diff --git a/ucsmsdk_samples/server/local_disk_policy.py b/ucsmsdk_samples/server/local_disk_policy.py index abf5b7a..8063991 100755 --- a/ucsmsdk_samples/server/local_disk_policy.py +++ b/ucsmsdk_samples/server/local_disk_policy.py @@ -168,17 +168,15 @@ def local_disk_policy_exist(handle, name, mode="any-configuration", dn = parent_dn + "/local-disk-config-" + name mo = handle.query_dn(dn) if mo: - if ((mode and mo.mode != mode) - and - (flex_flash_state and mo.flex_flash_state != flex_flash_state) - and + if ( + (mode and mo.mode != mode) and + (flex_flash_state and mo.flex_flash_state != flex_flash_state) and (flex_flash_raid_reporting_state and - mo.flex_flash_raid_reporting_state != - flex_flash_raid_reporting_state) - and - (protect_config and mo.protect_config != protect_config) - and - (descr and mo.descr != descr)): + mo.flex_flash_raid_reporting_state != + flex_flash_raid_reporting_state) and + (protect_config and mo.protect_config != protect_config) and + (descr and mo.descr != descr) + ): return False return True return False diff --git a/ucsmsdk_samples/server/local_disk_state.py b/ucsmsdk_samples/server/local_disk_state.py new file mode 100644 index 0000000..811101e --- /dev/null +++ b/ucsmsdk_samples/server/local_disk_state.py @@ -0,0 +1,50 @@ +# Copyright 2015 Cisco Systems, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from ucsmsdk.mometa.storage.StorageLocalDisk import StorageLocalDisk + + +def disk_state_set(handle, rack_id, disk_id, state, + controller="storage-SAS-1"): + """ + This method sets the disk state on rackmount servers + to either jbod or uncofigured (pre-RAID). This should + be done before applying service profile to the server. + + Args: + handle (UcsHandle) + rack_id (int): Rack Unit ID of server to configure + disk_id (int): ID of disk to configure + state (string): either "unconfigured-good" or "jbod" + controller (string): The part of the DN string that describes + which storage controller to which the disks + are connected + + Returns: + StorageLocalDisk + + Example: + disk_state_set(handle, 1, 3, "uconfigured-good") + + """ + + if state != "unconfigured-good" and state != "jbod": + raise ValueError('Invalid State: "{0}"'.format(state)) + + dn = "sys/rack-unit-{0}/board/{1}".format(rack_id, controller) + mo = StorageLocalDisk(parent_mo_or_dn=dn, id=str(disk_id), + admin_action=state, + admin_action_trigger="triggered") + handle.add_mo(mo, True) + handle.commit() + return mo diff --git a/ucsmsdk_samples/server/maintenance_policy.py b/ucsmsdk_samples/server/maintenance_policy.py index 47ec33f..8eea3f4 100755 --- a/ucsmsdk_samples/server/maintenance_policy.py +++ b/ucsmsdk_samples/server/maintenance_policy.py @@ -146,9 +146,10 @@ def maintenance_policy_exist(handle, name, uptime_disr="user-ack", descr="", dn = parent_dn + "/maint-" + name mo = handle.query_dn(dn) if mo: - if ((uptime_disr and mo.uptime_disr != uptime_disr) - and - (descr and mo.descr != descr)): + if ( + (uptime_disr and mo.uptime_disr != uptime_disr) and + (descr and mo.descr != descr) + ): return False return True return False diff --git a/ucsmsdk_samples/server/power_control_policy.py b/ucsmsdk_samples/server/power_control_policy.py index c071077..ffcfca5 100755 --- a/ucsmsdk_samples/server/power_control_policy.py +++ b/ucsmsdk_samples/server/power_control_policy.py @@ -139,8 +139,7 @@ def power_control_policy_exist(handle, name, prio="no-cap", descr="", dn = parent_dn + "/power-policy-" + name mo = handle.query_dn(dn) if mo: - if ((prio and mo.prio != prio) and - (descr and mo.descr != descr)): + if ((prio and mo.prio != prio) and (descr and mo.descr != descr)): return False return True return False diff --git a/ucsmsdk_samples/server/scrub_policy.py b/ucsmsdk_samples/server/scrub_policy.py index 94ae3cb..0340f1a 100755 --- a/ucsmsdk_samples/server/scrub_policy.py +++ b/ucsmsdk_samples/server/scrub_policy.py @@ -160,11 +160,13 @@ def scrub_policy_exist(handle, name, flex_flash_scrub="no", dn = parent_dn + "/scrub-" + name mo = handle.query_dn(dn) if mo: - if ((disk_scrub and mo.disk_scrub != disk_scrub) and + if ( + (disk_scrub and mo.disk_scrub != disk_scrub) and (flex_flash_scrub and mo.flex_flash_scrub != flex_flash_scrub) and (bios_settings_scrub and mo.bios_settings_scrub != bios_settings_scrub) and - (descr and mo.descr != descr)): + (descr and mo.descr != descr) + ): return False return True return False diff --git a/ucsmsdk_samples/server/serverdeployment.py b/ucsmsdk_samples/server/serverdeployment.py index 7eb2cbc..9cbb565 100755 --- a/ucsmsdk_samples/server/serverdeployment.py +++ b/ucsmsdk_samples/server/serverdeployment.py @@ -15,11 +15,11 @@ import time import datetime import logging +from ucsmsdk.ucseventhandler import UcsEventHandle +from ucsmsdk.mometa.ls.LsServer import LsServerConsts log = logging.getLogger('ucs') -from ucsmsdk.ucseventhandler import UcsEventHandle -from ucsmsdk.mometa.ls.LsServer import LsServerConsts # TODO: should not be global. This will not work when multiple nodes are # associate in parallel diff --git a/ucsmsdk_samples/server/service_profile.py b/ucsmsdk_samples/server/service_profile.py index 6b6381f..bcef2ee 100755 --- a/ucsmsdk_samples/server/service_profile.py +++ b/ucsmsdk_samples/server/service_profile.py @@ -12,7 +12,6 @@ # limitations under the License. - def sp_template_create(handle, name, type, resolve_remote, descr="", usr_lbl="", src_templ_name="", ext_ip_state="none", ext_ip_pool_name="", ident_pool_name="", @@ -47,7 +46,7 @@ def sp_template_create(handle, name, type, resolve_remote, descr="", src_templ_name (string): Name of Source template ext_ip_state= :none", "pooled", "static" ext_ip_pool_name (string): Name of IP Pool - ident_pool_name (string): Name of Ident pool + ident_pool_name (string): Name of Ident pool agent_policy_name (string): Name of agent policy bios_profile_name (string): Name of bios profile boot_policy_name (string): Name of boot policy @@ -67,7 +66,7 @@ def sp_template_create(handle, name, type, resolve_remote, descr="", vcon_profile_name (string): Virtual Connection profile policy vmedia_policy_name (string): Virtual media policy parent_dn= Parent DN - + Returns: Service Profile: Managed Object @@ -113,10 +112,10 @@ def sp_template_create(handle, name, type, resolve_remote, descr="", vmedia_policy_name=vmedia_policy_name ) - vnic_conn_def_mo = VnicConnDef( - parent_mo_or_dn=mo, - lan_conn_policy_name=lan_conn_policy_name, - san_conn_policy_name=san_conn_policy_name) + # Add vNIC Connection Policy to template + VnicConnDef(parent_mo_or_dn=mo, + lan_conn_policy_name=lan_conn_policy_name, + san_conn_policy_name=san_conn_policy_name) handle.add_mo(mo, True) handle.commit() @@ -148,7 +147,7 @@ def sp_template_modify(handle, name, type=None, resolve_remote=None, src_templ_name (string): Name of Source template ext_ip_state= :none", "pooled", "static" ext_ip_pool_name (string): Name of IP Pool - ident_pool_name (string): Name of Ident pool + ident_pool_name (string): Name of Ident pool agent_policy_name (string): Name of agent policy bios_profile_name (string): Name of bios profile boot_policy_name (string): Name of boot policy @@ -168,7 +167,7 @@ def sp_template_modify(handle, name, type=None, resolve_remote=None, vcon_profile_name (string): Virtual Connection profile policy vmedia_policy_name (string): Virtual media policy parent_dn= Parent DN - + Returns: LsServer: Managed Object @@ -268,8 +267,8 @@ def set_inband_mgmt(handle, sp_dn, vlan_name): raise ValueError("SP '%s' does not exist" % sp_dn) mo = MgmtInterface(parent_mo_or_dn=obj, mode="in-band") - mo_1 = MgmtVnet(parent_mo_or_dn=mo, name=vlan_name) - mo_2 = VnicIpV4MgmtPooledAddr(parent_mo_or_dn=mo, name="hyperflex") + MgmtVnet(parent_mo_or_dn=mo, name=vlan_name) + VnicIpV4MgmtPooledAddr(parent_mo_or_dn=mo, name="hyperflex") handle.add_mo(mo, True) handle.commit() @@ -390,7 +389,7 @@ def sp_create_from_template(handle, """ - import os + import os from ucsmsdk.ucsmethodfactory import ls_instantiate_n_named_template from ucsmsdk.ucsbasetype import DnSet, Dn @@ -486,10 +485,11 @@ def sp_power_on(handle, sp_name, parent_dn="org-root"): if not mo: raise ValueError("sp '%s' does not exist" % dn) - power_change = LsPower(parent_mo_or_dn=mo, state=LsPowerConsts.STATE_UP) + LsPower(parent_mo_or_dn=mo, state=LsPowerConsts.STATE_UP) handle.set_mo(mo) handle.commit() + def sp_power_off(handle, sp_name, parent_dn="org-root"): """ This function will power off a service profile @@ -519,13 +519,15 @@ def sp_power_off(handle, sp_name, parent_dn="org-root"): if not mo: raise ValueError("sp '%s' does not exist" % dn) - power_change = LsPower(parent_mo_or_dn=mo, state=LsPowerConsts.STATE_DOWN) + LsPower(parent_mo_or_dn=mo, state=LsPowerConsts.STATE_DOWN) handle.set_mo(mo) handle.commit() + def sp_wwpn(handle, sp_name, parent_dn="org-root"): """ - This function will return the fibre channel wwpn addresses of a service profile + This function will return the fibre channel wwpn addresses + of a service profile Args: handle (UcsHandle) @@ -577,8 +579,10 @@ def sp_macaddress(handle, sp_name, parent_dn="org-root"): ValueError: If LsServer is not present Example: - sp_macaddress(handle, sp_name="sample_sp", parent_dn="org-root") - sp_macaddress(handle, sp_name="sample_sp", parent_dn="org-root/sub-org") + sp_macaddress(handle, sp_name="sample_sp", + parent_dn="org-root") + sp_macaddress(handle, sp_name="sample_sp", + parent_dn="org-root/sub-org") """ dn = parent_dn + "/ls-" + sp_name mo = handle.query_dn(dn) diff --git a/ucsmsdk_samples/server/sol_policy.py b/ucsmsdk_samples/server/sol_policy.py index 7e8e8f1..96e8615 100755 --- a/ucsmsdk_samples/server/sol_policy.py +++ b/ucsmsdk_samples/server/sol_policy.py @@ -145,11 +145,11 @@ def sol_policy_exist(handle, name, admin_state, speed="9600", descr="", dn = parent_dn + "/scrub-" + name mo = handle.query_dn(dn) if mo: - if ((admin_state and mo.admin_state != admin_state) - and - (speed and mo.speed != speed) - and - (descr and mo.descr != descr)): + if ( + (admin_state and mo.admin_state != admin_state) and + (speed and mo.speed != speed) and + (descr and mo.descr != descr) + ): return False return True return False