XML API

Report 26 Downloads 218 Views
Cisco UCS Python SDKs John McDonough, DevNet Data Center Automation Evangelist DEVNET-2063

Agenda •

Introduction •

DEVNET-2063 - Cisco UCS Python SDKs



UCS Unified API Overview



UCS Python SDK • • • •

Install / Get Help / Variable Inspection / Meta Data Connect / Query / Filter / Dump XML Configure / Transactions Compare / Sync / Code Generation



What else and What’s next



Conclusion

UCS Unified API - Overview

Cisco Unified Computing System Cisco UCS™ Manager / IMC / Central

Cisco UCS Fabric Interconnects Cisco UCS I/O modules Cisco UCS Blade Server Chassis

Cisco UCS Blade and Rack Servers

Cisco UCS I/O Adapters

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

5

UCS Management Programmatic Infrastructure Libraries / SDKs

GUI & CLI

3rd Party

Direct

Customer Self Serve portals Management Tools Auditing Tools

XML API Status Inventory Configuration

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

6

UCS XML API Overview

UCS XML API Features • • • • • • • • • •

Communicates over HTTP / HTTPS XML Based, Transactional Standard Request / Response cycle Role Based Authentication Object Model Hierarchy Built-in Object Browser Published XML Schema Full Object Documentation High Availability by default Event Stream

XML API

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

7

UCSM Object Model Documentation

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

8

Management Information Model(MIM) Root

Everything is an object

Objects are hierarchically organized Class identifies object type: Card, Port, VNIC… Class Inheritance

Server port is a subclass of port. A server blade is a subclass of compute entity. Set of attributes

MO represents any physical or logical entity Managed Object

Each MO is uniquely identified by DN

UCS XML Database contains comprehensive system information  Discovered components  System configuration  Operational status including statistics and faults DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

9

Distinguished Names Root

rn1 rn2

Slash delimited sequence of RNs Immutable DN Provides a fully qualified path

rn3

dn = {rn1}/{rn2}/{rn3} Example:

DN unambiguously identifies a target object. DN name is composed of sequence of Relative Names (RN). RN identifies an object within the context of its parent object.

is composed of the following relative names: topSystem MO: rn="sys" equipmentChassis MO: rn="chassis-" computeBlade MO: rn ="blade-<slotId>" adaptorUnit MO: rn="adaptor-" adaptorHostEthIf MO: rn="host-eth-"

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

10

Python SDK

Install

Cisco UCS Python SDKs - Install •

Hosted on Github •

UCS Manager SDK – GA •

• •



UCS IMC SDK – Beta •

• •



Source – https://github.com/CiscoUcs/ucsmsdk Samples – https://github.com/CiscoUcs/ucsmsdk_samples Documents – https://CiscoUcs.github.io/ucsmsdk_docs

Source – https://github.com/CiscoUcs/imcsdk Samples – Documents – https://ciscoucs.github.io/imcsdk_docs

Beta at your own Risk

UCS Central Python SDK – Beta •

Source – https://github.com/CiscoUcs/ucscentralsdk

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

13

Cisco UCS Python SDKs - Install •

Install Python 2.7.X or 3.5.X •

Or both UCS Python SDKs can coexist!



pip – Preferred Installer Program (package manager) •

Installs latest “Release” from https://pypi.python.org/pypi pip install ucsmsdk



git – Install from github.com – works for ucsmsdk, imcsdk, ucscentralsdk •

Installs latest SDK source code from https://github.com/CiscoUcs/ucsmsdk git clone https://github.com/CiscoUcs/ucsmsdk.git cd ucsmsdk C:\Python27\python.exe .\setup.py install  Python 2.7 'C:\Program Files\Python35\python.exe' .\setup.py install  Python 3.5 DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

14

Get Help / Variable Inspection / Meta Data

Get Help •

help(ClassName)

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

16

Variable Inspection - vars •

vars(variable_name)

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

17

MetaData – get_meta_info •

get_meta_info(class_id="ClassName")

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

18

Find the Class Id

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

19

Connect / Query / Filter / Dump XML

Connect & Query •

Connect from ucsmsdk.ucshandle import UcsHandle handle = UcsHandle("", "admin", "passsword") handle.login()



UcsHandle • • • • •

handle.query_classid – Query a Specific ClassId handle.query_classids – Query a group of ClassIds handle.query_children – Query a dn children or Specific ClassId children of a dn handle.query_dn – Query a Specific dn handle.query_dns – Query a group of dns

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

21

Connect & Query

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

22

Dump XML •

handle.set_dump_xml()

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

23

Query Filters # Exact Match by default filter_exp='(model,"UCSB-B200-M4")' compute_blades = handle.query_classid("ComputeBlade",filter_str=filter_exp) len(compute_blades)

# Exact Match Specified filter_exp='(model,"UCSB-B420-M4", type="eq")' compute_blades = handle.query_classid("ComputeBlade",filter_str=filter_exp) len(compute_blades)

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

24

Query Filters # Exact Match is Case Sensitive filter_exp='(model,"ucsb-b420-m4", type="eq")' compute_blades = handle.query_classid("ComputeBlade",filter_str=filter_exp) len(compute_blades)

# Exact Match without Case Sensitivity compute_blades = handle.query_classid("ComputeBlade",filter_str=filter_exp) filter_exp='(model,"ucsb-b420-m4", flag="I")' len(compute_blades)

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

25

Query Filters From ucsfilter.py types = {"eq": "ne": "ge": "gt": "le": "lt": "re": }

"EqFilter", "NeFilter", "GeFilter", "GtFilter", "LeFilter", "LtFilter", "WcardFilter"

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

26

Demo

Configure / Transactions

Configure – Create •

Create / Update / Delete •

Create VLAN

1.

import

2.

login

3.

query Parent object

4.

add child object(s)

5.

commit

6.

logout

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

29

Configure – Update •

Create / Update / Delete •

Update VLAN

1.

import

2.

login

3.

query object

4.

set object

5.

commit

6.

logout

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

30

Configure – Delete •

Create / Update / Delete •

Delete VLAN

1.

import

2.

login

3.

query object

4.

remove object

5.

commit

6.

logout

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

31

Transactions •

Transactions are Implicit •

Create VLANs

1.

import

2.

login

3.

query Parent object

4.

add child objects

5.

commit

6.

logout

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

32

Compare / Sync / Code Creation

Compare & Sync •

Use compare_ucs_mo to see the Object differences between two domains.



Use sync_ucs_mo with diff object to synchronize the VLANS between two domains. from ucsmsdk.ucshandle import UcsHandle from ucsmsdk.utils import comparesyncmo source_ucs=UcsHandle("192.168.0.1", "admin", "password") target_ucs=UcsHandle("192.168.0.2", "admin", "password") source_ucs.login() target_ucs.login() source_ucs_vlans=source_ucs.query_classid("fabricVlan") target_ucs_vlans=target_ucs.query_classid("fabricVlan") difference_vlans=comparesyncmo.compare_ucs_mo(target_ucs_vlans, source_ucs_vlans) comparesyncmo.write_mo_diff(difference_vlans) # print the difference to the console comparesyncmo.sync_ucs_mo(target_ucs, difference_vlans, delete_not_present=False) delete_not_present=True, Removes VLANs from target_ucs that are not present in source_ucs

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

34

Code Creation

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

35

Demo

Conclusion

Complete Your Online Session Evaluation •

Please complete your Online Session Evaluations after each session



Complete 4 Session Evaluations & the Overall Conference Evaluation (available from Thursday) to receive your Cisco Live T-shirt



All surveys can be completed via the Cisco Live Mobile App or the Communication Stations

Don’t forget: Cisco Live sessions will be available for viewing on-demand after the event at CiscoLive.com/Online

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

38

Continue Your Education •

Demos in the Cisco campus



Walk-in Self-Paced Labs



Lunch & Learn



Meet the Engineer 1:1 meetings



Related sessions

DEVNET-2063

© 2017 Cisco and/or its affiliates. All rights reserved.

Cisco Public

39

Thank You