Skip to content

Commit

Permalink
Merge pull request CiscoUcs#103 from waghswapnil/misc_features
Browse files Browse the repository at this point in the history
add api for asset tagging server/chassis
  • Loading branch information
waghswapnil authored Jan 31, 2017
2 parents a869e26 + 5a2cfc2 commit ec356e0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
46 changes: 45 additions & 1 deletion imcsdk/apis/server/serveractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import time
from imcsdk.imcexception import ImcOperationError
from imcsdk.mometa.compute.ComputeRackUnit import ComputeRackUnitConsts
from imcsdk.mometa.compute.ComputeRackUnit import ComputeRackUnit,\
ComputeRackUnitConsts
from imcsdk.mometa.equipment.EquipmentChassis import EquipmentChassis
from imcsdk.mometa.compute.ComputeServerNode import ComputeServerNodeConsts
from imcsdk.mometa.equipment.EquipmentLocatorLed \
import EquipmentLocatorLed, EquipmentLocatorLedConsts
Expand Down Expand Up @@ -318,3 +320,45 @@ def locator_led_off(handle, **kwargs):
if _is_valid_arg("server_id", kwargs) or \
handle.platform == IMC_PLATFORM.TYPE_CLASSIC:
_set_server_locator_led_state(handle, False, kwargs)


def tag_server(handle, tag):
"""
This method will tag the server with the label specified.
Applicable to non-C3260 platforms
Args:
handle(ImcHandle)
tag (str): Label to be used to tag the asset
Returns:
ComputeRackUnit object
Example:
tag_server(handle, tag="Row21-Rack10-Slot5")
"""
mo = ComputeRackUnit(parent_mo_or_dn="sys", server_id='1')
mo.asset_tag = str(tag)
handle.set_mo(mo)
return mo


def tag_chassis(handle, tag):
"""
This method will tag the chassis with the label specified.
Applicable to C3260 platforms
Args:
handle(ImcHandle)
tag (str): Label to be used to tag the asset
Returns:
EquipmentChassis object
Example:
tag_server(handle, tag="Row21-Rack10-Slot10")
"""
mo = EquipmentChassis(parent_mo_or_dn="sys")
mo.asset_tag = str(tag)
handle.set_mo(mo)
return mo
20 changes: 19 additions & 1 deletion tests/server/test_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from nose.tools import raises
from nose.tools import raises, assert_equal
from ..connection.info import custom_setup, custom_teardown
from imcsdk.apis.server.inventory import get_inventory
from imcsdk.apis.server.serveractions import tag_server, tag_chassis
from imcsdk.imccoreutils import IMC_PLATFORM

handle = None

Expand Down Expand Up @@ -57,3 +59,19 @@ def test_get_inventory_error():
@raises(Exception)
def test_get_inventory_invalid_component():
get_inventory(handle, component="invalid", file_format="csv")


def test_asset_tag_server():
if handle.platform != IMC_PLATFORM.TYPE_CLASSIC:
return
mo = tag_server(handle, tag='ABCD-1234')
mo = handle.query_dn(mo.dn)
assert_equal(mo.asset_tag, 'ABCD-1234')


def test_asset_tag_chassis():
if handle.platform != IMC_PLATFORM.TYPE_MODULAR:
return
mo = tag_chassis(handle, tag='ABCD-1234')
mo = handle.query_dn(mo.dn)
assert_equal(mo.asset_tag, 'ABCD-1234')

0 comments on commit ec356e0

Please sign in to comment.