2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 2
What are WBEM and CIM?
A management
WBEM model/insfrastructure
Profiles defined by:
WBEM Infrastructure
Operations, Events, Query Languages, Namespaces
• DMTF Specifications
Profiles • CIM Model
WBEM Protocols • Systems
• WBEM Operations
CIM-XML, etc. • Devices
• Software • Profile Concepts
• Smash/Dash
initiatives
CIM CIM Schema • Profiles
Models, classes, etc
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 3
What is pywbem?
functionality WBEM
PyWBEM Public API
WBEM Subscription Indication New
Server Class Manager Class Listener Class Classes
Add general capabilities Connection pywbem
pywbem MOF
& Request CIM
CIM Objects Compiler
Add and grow tools Common
Methods Objects
HTTP/HTTPS
elements CIM/XML HTTPS/HTTP
Create project with SMI Requests and
Responses
WBEM
Indications
PyWBEMClient
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 6
WBEM Infrastructure
• WBEM Architecture Components
• Server, client, listener
WBEM • WBEM Operations definitions
Profiles • Get, Enumerate, Create, Delete, Modify
WBEM Infrastructure (classes, instances, etc.), InvokeMethod,
Operations, Events, Query Languages,
Namespaces ExecQuery
Profiles • Events(indications)
WBEM Protocols • Systems
• Query Languages
CIM-XML, etc. • Devices
• Software
WBEM Client WBEM Listener
CIM Schema
CIM Models, classes, etc.
CIM Infrastructure
Meta schema, Schema, Rules, Initiatives, MOF
WBEM Server
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 7
WBEM Protocols
WBEM Protocols
• Communicate between WBEM
architecture components
• Define WBEM Message
• Multiple protocols allowed
• CIM/XML
• Etc.
PyWBEM Public API
WBEM WBEM
Indication
Server Subscription
Listener Class
Class Manager Class
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 8
CIMProperty CIMParameter
The CIM Schema •
•
Name
CIMValue
•
•
Name
CIM Value
• CIMQualifiers • CIMQualifiers
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 9
CIM Schema: Qualifiers
• Qualifiers define characteristics of other
WBEM CIM model Elements
Profiles
WBEM Infrastructure • Generally predefined in DMTF
Operations, Events, Query Languages, Schema
Namespaces
Profiles • Apply to class definitions of class,
WBEM Protocols • Systems
property, method, parameter
CIM-XML, etc. • Devices
• Software
• Major Qualifiers
CIM Schema • Key (Identify key properties of class)
CIM Models, classes, etc.
• Description
CIM Infrastructure • Association (identify assoc class)
Meta schema, Schema, Rules, Initiatives, MOF • Indication (identify indication class)
• Required
• In, Out (Parameter direction)
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 10
CIM has different types of Classes
• CIM Class
• Defines manged resources
• Key properties provide identity
• CIM Properties defined with
key qualifier
• CIM Association
• Defines relation between classes
• Reference properties point to
other classes/instances
• CIMIndication
• CIM Class used to pass event
information
• No keys (i.e snapshot of data)
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 11
THIS SHOULD HAVE DIAGRAM
Class Association Example
Combine this and
previous page
Associators operation
Class Class
A B
Association class C
• Reference to A
Association Operations • Reference to B
• References – Get Associations for Target Clarify weak relationships
• For Target A, gets C
• Associators – Get Associated for Target
• For Target A gets B
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 12
CIM Schema: Datatypes
CIM Data Type Pwbem Implementation
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 13
CIM Infrastructure
• Meta schema
WBEM • Defines the model
Profiles • Based on UML
WBEM Infrastructure
Operations, Events, Query Languages, • Schema
Namespaces
Profiles • Package of CIM Classes,
WBEM Protocols • Systems Qualifiers, etc. representing
CIM-XML, etc. • Devices
• Software coherent DMTF release.
• Rules
CIM Schema • Constraints defined in
CIM Models, classes, etc. Specification
CIM Infrastructure • MOF
Meta schema, Schema, Rules, Initiatives, MOF • Source code language for CIM
Model
• Defines CIM class, CIM Qualifier
Declaration, CIMInstance
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 14
CIM MOF
• Language to define CIM classes, instances, Qualifiers,
Methods
• Used by DMTF/SNIA to define Released CIM
Schemas
• Can be used to define instances Pywbem client includes
• Normally compiled by implementation compiler to MOF compiler.
produce internal representations of classes, instances
DMTF
Example MOF:
Qualifier Association : boolean = false, Schema My MOF
Scope(association), MOF
Flavor(DisableOverride, ToSubclass); WBEM Client
Class CIM_Foo { MOF Local CIM
[Key, Description(“blah blah”)
string InstanceID; Compiler Objects
uint32 IntegerProp;
uint32 ArrayIntProp[]; WBEM Server
uint32 StartService();
Model
2018 Storage Developer Conference. © Insert Your Company Name. All Repository
Rights Reserved. 15
Indications & Subscriptions
CIM_ListenerDestinationCIMXML
• Indications are representations Defines the listener destination url
of specific events sent by
server to listener CIM_IndicationFilter
• Subscriptions define activation Defines the CQL or
and characteristics of specific WQL filter for an
indications for server indication
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 17
Profiles vs. Schema
Profile
Schema Subset of classes from
Qualifier declarations the DMTF schema
Broad set of classes adapted to represent a
Resources
particular management
Associations
goal/domain
Indications Constraints, usage,
Structures scripts
DMTF released schema Indication definitions
(~ 3000 classes)
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 18
18
Profile Characteristics
Structured Array Profile
Autonomous Profiles
Standalone. The profile instance
32 component profiles
not referenced by other profiles. BlockServices, Health,
Component Profiles indications, xxx_targetPorts,
xxx_initiator_ports(mandatory
Referenced by other profiles )
Documented in SMI Spec and Software, etc. (Optional)
DMTF specs
9 classes
Registered profiles
2 mandatory
Central Class
Scoping Classes
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 19
19
Central and scoping classes
Central class
The focal point for the profile TODO
Only required for
autonomous profiles
Scoping class
Relate component profile to
referenced profile.
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 20
20
Navigating Profiles from the client
Start with Registered
WBEM Server
profiles
Server lists profiles it supports Profile Instance of central
scoping and classes
Association to central class registration
for autonomous profiles ElementConformsTo Autonomous profile
Component profiles related Implementation
to autonomous profile by
Scoping Path
scoping classes
• Example of profiles:
•Autonomous profiles
• Server, Array, NAS Component Profile
•Component profiles implementation
• Disk drive
• Port
• Software
• SoftwareIdentity
• …
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 21
21
Defining Profiles
Profile Definition
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 22
pywbem: Registered Profiles and Profiles Central and
scoping
WbemServer Class
CIM_ElementConfromsToProfile
Association
CIM_ComputerSyst
RegisteredProfile em
CIM_ComputerSystem
SMI.Array.1.7.0 (CentralClass
Pywbem
HostedStoragePool
Client
ReferencedProfile
PrimordialStoragePool
RegisteredProfile Class
Autonomous SMI.BlockServices.1.7.
Profile 0 Central
Class
Component
Profile
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 23
pywbem Public APIs Pywbem users
Profile Tools (browsers, etc.)
Implementations Ex. Pywbemtools project
Pywbem Public API Pywbem operations
WBEM WBEM Connecting to the Server
Indication MOF
Server Subscription pywbem WBEM Operations
Listener Class Compiler
Class Manager Class
pywbem CIM Objects
PyWBEM Connection Higher Level Classes
CIM Objects & Request Methods
WBEM Server
Common
elements HTTP/HTTPS WBEMSubscriptionManager
CIM/XML HTTPS/HTTP
Requests and WBEM
Indications
pywbemListener
Responses
PyWBEMClient
Python Package
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 24
24
pywbem and CIM/WBEM
CIMObjects as PyWBEM
CIM data types as
classes
Python/Pywbem classes: CIMClass
CIM Data Type pwbem Implementation CIMClassName
Boolean Python bool CIMInstance
Char16 Python string CIMInstanceName
CIMProperty
string Python string
CIMParameter
Uint/Sint(8,16,32,64) pywbem class for each
CIMQualifier
Real (32,64) pywbem classes CIMQualifierDeclaration
CIMDateTime pywbem datetime CIMProperty
Array python list CIMParameter
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 25
SDC 2017 - Pywbem 25
pywbem: WBEM Operations
All errors are exceptions.
Operations for Class, Instance, Server exceptions are pywbem Error or CIMError
Qualifier Return data depends on operation type:
get, enumerate, create, delete, modify
Enumerates, associators, references
InvokeMethod operation executes List instances, instancenames, classes,
method on class or instance qualifierDecls
Operations for references and Get
associators 1 instance, instance name, class, qualifierDecl
invokeMethod
Operations support concepts of returnValue, output parameters
pull (get partial results) and use create/modify
of python iterator Success or failure, path for create
Pull Operations
Instances or paths, end_of_sequence,
enumeration_context as a named tuple
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 26
26
pywbem: connecting to a WBEM Server
WBEMConnection class defines connection
Lazy execution
Connection not made until request issued
Attributes:
url - host name/ip including scheme and port
Credentials - if required (name and password)
default_namspace – Namespace to use unless overridden by
individual namespace on operations
X509 – client cert/key if server demands client authentication
verify_callback – Callback for optional extra checking of server certs
ca_certs – ca authority common with server
no_verification, boolean option to inhibit verification of server cert
timeout – timeout for server response time
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 27
A simple example: Enumerate Instances
# Get instances of defined class/subclasses in namespace
import pywbem
CONN = WBEMConnect(url, default_namespace=‘root/myns’,…)
insts = CONN.EnumerateInstances (‘CIM_ComputerSystem’)
for inst in insts:
print(‘%s’% inst.tomof())
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 30
SDC 2017 - Pywbem 30
Subscription Example
From pywbem import WBEMConnection, WBEMServer, SubscriptionManager
TEST_CLASS = 'Test_IndicationProviderClass'
TEST_CLASS_NAMESPACE = 'test/TestProvider'
Add
TEST_QUERY = 'SELECT * from %s' % TEST_CLASS Server
conn = WBEMConnection(url)
server = WBEMServer(conn) Add
sub_mgr = SubscriptionManager() Listener for
server_id = sub_mgr.add_server(server)
server
Sub_mgr.add_listener_url(server_id, listener_url)
Create a
filter_path = sub_mgr.add_filter(server_id,
TEST_CLASS_NAMESPACE, TEST_QUERY, Filter
query_language="DMTF:CQL")
subscription_paths = sub_mgr.add_owned_subscriptions(server_id,
filter_path)
. . . HERE User may wait
sub_mgr.remove_owned_subscriptions(url, subscription_paths)
sub_mgr.remove_owned_filter(server_id, filter_path)
sub_mgr.remove_server(server_id) Create
Subscription
Remove all
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 31
SDC 2017 - Pywbem 31
Pywbem and Registered Profiles
conn = WBEMConnection()
WBEMServer class access svr = WBEMServer(conn)
profile information myprof = svr.get_selected_profiles(“SNIA”,
“Array”
Get profiles, selected “1.6.1”)
profiles # get central instance of autonomous profile
ci = svr.get_central_instances(myprof[0].path)
Get central and scoping
classes
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 32
Using pywbem documentation
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 33
Pywbem Next Steps
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 34
34
Pywbem and automation
Orchestration Tools
• Ansible Scripts
Orchestration tools • …
pywbem
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 35
How Client Profile Implementation works
Get the server
Get the registered profile
Get the central/scoping classes
Get the resource class instances
Execute methods as python methods
Python methods/functions for more complex
actions (use cases), etc. configure, create etc.
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 36
pywbem support tools
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 37
37
pywbem availability and project
•Client package “pywbem” in PyPi • Each release is on PyPI (pywbem)
•Client package on some Linux • 1 – 2 releases per year
distributions • Documentation in public repository and
–Ex. Ubuntu as python-pywbem readthedocs
–NOTE: Some distros have • Pywbem uses github issues and pull
obsolete version requests processes.
• Engage with pywbem community, for:
–Directly from pywbem project on • Reporting issues (pywbem github issues)
Github: • Feature requests (pywbem github issues)
–pywbem is a github project with • Contributing (for example from github fork, new
tools, etc.)
several code repositories
–Separate repo for pywbemtools
–Pywbem.pywbem is client
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 38
2/17/16 38 38
More Information on pywbem
•pywbem public project github:
•https://github.com/pywbem We are always looking for
more ideas, workers,
•pywbem public client project github: comments.
•https://github.com/pywbem/pywbem
•pywbem client documentation online: Any help welcome.
– http://pywbem.readthedocs.io/en/stable/
•Includes installation, API documentation, usage
–http://pywbem.github.io/pywbem/
•pywbem Jupyter notebooks online:
• https://pywbem.readthedocs.io/en/latest/tutorial.html#executing-code-in-the-tutorials
•SNIA pywbem web page:
•https://www.snia.org/pywbem
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 39
2/17/16 39 39
These slides are available for discussions and background.
They are not part of the presentation.
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 40
40
The pywbem WBEM Class
Operations
operations
Methods of the pywbem class GetClass Iter…Operations
EnumerateClasses Merge original and
WBEMConnection CreateClass
pull
Instance operations ModifyClass
Pythonic
EnumerateInstances DeleteClass
QualifierDeclaration operations
EnumerateInstanceNames GetQualifier
Associators* EnumerateQualifiers
AssociatorNames* SetQualifier
References* DeleteQualifier
ReferenceNames*
GetInstance
• Pull operations
– OpenEnumerateInstances
CreateInstance
– OpenEnumerateInstanceNames
ModifyInstance
– OpenAssociators
DeleteInstance
– OpenReferences
InvokeMethod* – OpenExecQuery
ExecQuery – PullInstancesWithPaths
* Class and Instance – PullInstancePaths
– PullInstances
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 41
* Execute on either classes orSDC instances – CloseEnumeration
2017 - Pywbem 41
Some Relevant DMTF specifications
DSP0004 – Defines metamodel, model, major
characteristics, and MOF
DSP0201 – Defines WBEM Operations over CIM/XML
DSP0202 – XML for WBEM Operations over CIM/XML
DSP0223 – Generic Operations
Query Language(CQL) – DSP0202
Operation Query Language (FQL) – DSP0212
See the DMTF web page:
https://www.dmtf.org/standards/published_documents
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 42
CIMOperations Iter… methods
Merge Open/Pull and Enumerate into wrapper methods.
Moves decision on use of pull methods to infrastructure
Iter… for EnumerateInstances,
EnumerateInstanceNames, Associators,
AssociatorNames, References, ReferenceNames,
ExecQuery
Same input parameters as corresponding Open…
operation
User can force pull or non-pull operation usage
Use python iterator
2018 Storage model
Developer Conference. forCompany
© Insert Your responses
Name. All Rights Reserved. 43
SDC 2017 - Pywbem 43
Iter… Advantages
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 44
SDC 2017 - Pywbem 44
New Api Pattern
def IterEnumerateInstances(self, ClassName, namespace=None,
Enumerate
LocalOnly=None, Request
DeepInheritance=None, IncludeQualifiers=None, Parameters
IncludeClassOrigin=None, PropertyList=None,
Open
FilterQueryLanguage=None, FilterQuery=None, request
OperationTimeout=None, ContinueOnError=None, Extension
MaxObjectCount=DEFAULT_ITER_MAXOBJECTCOUNT, **extra): Parameters
• Change for
Conn = WBEMConnection(. . . , use_pull_operations=None, …)
Iter…
Returns for each type: • Zero illegal
• EnumerateInstances : List of instances • Defaults to
• OpenEnumerateInstances: Tuple of status and instances • 1000
• IterEnumerateInstances : Iteration object to be used by for • None: Pywbem choses
statement or genertor comprehenshion • True: force pull
2018 Storage Developer Conference. © Insert Your Company Name. •
All Rights Reserved. False: use old ops 45
SDC 2017 - Pywbem 45
Iter… functionality
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 46
SDC 2017 - Pywbem 46
Operation Comparison
Code that tries pull first BECOMES
If server_has _pull: conn = WBEMConnection(…)
try: iter_obj = conn.IterEnumerateInstances(‘myclass’)
result = conn.OpenEnumerateInstances(classname, for instance in iter_obj:
MaxObjectCount=max_open)
print(instance.tomof())
# save instances since we reuse result
insts = result.instances
# loop to make pull requests until end_of_sequence
received. Or to gather all instances with generator
pull_count = 0
while not result.eos: expression
pull_count += 1
result = conn.PullInstancesWithPath(result.context,
MaxObjectCount=max_pull) Instances = (inst for inst in
insts.extend(result.instances) conn.IterEnumerateInstances(‘myclass’)
except: CIMError as ce:
if ce.status != ce.status_code ==
CIM_ERR_NOT_SUPPORTED
raise
else:
insts = conn.EnumerateInstances(classname)
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 47
For inst in insts SDC 2017 - Pywbem 47
print(inst.tomof())
Iter… limitations
Use of queryfilters parameter
Since not supported in Enumerate, etc. Iter… oprations fail if fallback to
Enumerate with pull operations
Only do pull to server when local list empty
Delays may be visible to client user
The capability to delay in pull sequence lost
Full pull operations allowed request with 0 objects that just reset server
timer
Pywbem infrastructure does not have enough info to use that concept
ContinueOnError cannot be used (EnumerateInstances returns all or
nothing). Note that almost none of us ever implemented this feature
Cannot vary size of responses during session nor return zero for
OpenEnumerateInstances
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 48
SDC 2017 - Pywbem 48
CIMInstance PyWBEM Class
Class Attributes:
classname (string)
properties(NocaseDict) of CIMProperties
qualifiers(NocaseDict) of CIMQualifiers
path (CIMInstanceName) optional
property_list(list of Strings) -ptional for filter with some operations
Object Methods for things like
Comparison, copy, update, get property info, display
See: https://pywbem.readthedocs.io/en/latest/client.html#cim-objects for detailed api documentation
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 49
Inspect Instance
Get path
path = inst.path
Properties
Many ways to access properties (dict, api)
Access Properties
if inst.has_key(‘myPropName’):
value = inst.get(‘myPropName’)
properties = inst.properties
.. Inspect the properties dictionary
Etc.
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 50
Embedded Instances
Embedded Instances are the struct concept of CIM
Allow grouping properties within a larger entity
Normally have no unique identity. They are a component
of an instance
Within PyWBEM.
Data type string but with EmbeddedObject flag set.
Retrieve as value which is converted to CIMInstance
Create by creating CIMInstance and setting as value in
another instance
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 51
CIMInstance Methods (examples)
Create:
Required: PropertyName
Optional: properties, qualifiers, etc.
Inst = CIMInstance(‘PyWBEM_Foo’, properties=<properties
Copy
Inst2 = inst.copy()
Compare
If inst2 == inst1:
Get a property
Property_value = get(‘p1’)
Test for a property
If inst.has_key(‘p1’):
Display
Inst.tomof(), inst.tocimxmlst(indent=2), repr(inst), str(inst)
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 52
CIMProperty PyWBEM Class
Attributes:
name (unicode string) name of property
value (CIM data type) Value of property
type(unicode string) Name of data type
reference_class(unicode string) name of reference class for referenced properties
embedded_object indicator if this is embedded instance
is_array(bool) indicator if this is array of values
array_size(integer) – indicator of fixed size array
class_origin(bol)- indicates if property propagated from superclass
propagated(bool)
qualifiers((NocaseDict)
Methods for:
Copy, display/conversion compare, etc.
See: https://pywbem.readthedocs.io/en/latest/client.html#cim-objects
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 53
Example: create instances
props1 = {
‘s1’ : CIMPropertyName(name=‘u1’, type=‘Uint32’
value=Uint32(3456)
Inst3 = CIMInstance(‘CIM_Foo`,
properties={‘U1` :
CIMProperty(‘U1’,
Uint32(42)})
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 54