Sunteți pe pagina 1din 54

pywbem

Overview for SMI Client


Developers
Karl Schopmeyer
Inova Development Inc.
V 0.8.0, Sept 7 2018 2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 1
V 0.8.1 Sept 14 2018
Presentation Goals

 Help WBEM and especially SMI client users use


pywbem
 How to implement SMI automation with pywbem
 Present real usage examples
 Present overview of technology as required by the
client. (Eliminate what is not important to the client)
 Introduce working examples of client usage

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

CIM Infrastructure • SNIA Specifications


Meta schema, Schema, Rules, Initiatives, MOF
• SMI-S Initiative

2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 3
What is pywbem?

 What is it?  Why is it important?


 Python package for  Complete, verified
communicating with WBEM implementation of WBEM
and SMI servers Client infrastructure
(implements DMTF WBEM  Maintained with regular
operations and CIM releases
Objects)  Adheres to DMTF/SNIA
 Client platform on which to WBEM/SMIS specifications
build SMI client scripts, and  Well documented
applications
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 4
pywbem Overview
 Python implementation of DMTF CIM/XML client Pywbem Availabilty
 Python 2.6, 2.7, 3.4 – 3.7
• PyPi package ‘pywbem’
 Supports DMTF CIM-XML protocol and CIM Model
– WBEM Client library with a pythonic API for communication with • Github project ‘pywbem/pywbem’
WBEM servers
– Indication listener
 Open source and freely available PyWBEM Public API
 Multiplatform
 Linux, windows, etc. WBEM WBEM Indication
 Maintained
 Growing functionality, regular releases, fix issues Server Subscription Listener
 Next release: Q4 2018 Class Manager Class Class
 Complete, tested, compatible with DMTF and SMI specifications
 User ready
pywbem Connection pywbem
 Download and install with Python pip MOF
 pip install pywbem CIM & Request CIM
Compiler
 LGPL 2.1 license
 This license causes No problems with pip installed code
Objects Methods Objects
 Uses:
 Writing python based apps for WBEM/SMI clients
Common
HTTP/HTTPS
 Writing WBEM/SMI admin scripts elements CIM/XML HTTPS/HTTP
 Testing WBEM/SMI implementations Requests and WBEM
 Core library for a set of python based WBEM Tools Responses Indications
 Includes diagnostic and support tools
PyWBEMClient
Python Package
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 5
5
Pywbem project future directions
 Release CLI browser (Q4)
 Release pywbem next
release (Q4) Pywbem tools SMI Profile
(pywbemcli) Implementations
 Improve performance and Github: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

profile implementations Python Package

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

pywbem Connection pywbem


MOF
CIM & Request CIM
Compiler
Objects Methods Objects
Common
elements HTTP/HTTPS
HTTPS/HTTP
CIM/XML
Requests and WBEM
Responses Indications

You don’t need to know about the protocol, We do it. PyWBEMClient


Python Package

2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 8
CIMProperty CIMParameter
The CIM Schema •

Name
CIMValue


Name
CIM Value
• CIMQualifiers • CIMQualifiers

WBEM CIMClass CIMMethod CIMValue


Profiles • Name • Name • CIM data
WBEM Infrastructure • Superclass • CIM Qualifiers type
Operations, Events, Query Languages,
Namespaces • CIM Qualifiers • Return value • Arrayness
Profiles • CIM • CIMParameters • Value(s)
WBEM Protocols • Systems Properties
CIM-XML, etc. • Devices • CIM Methods CIMQualifier
• Software
• Name
• Scope
CIM Schema • Flavor(inheritance)
CIM Models, classes, etc. • Value
• Datatype
CIM Infrastructure
Meta schema, Schema, Rules, Initiatives, MOF CIMObjects as pywbem classes
CIMClass CIMProperty
CIMClassName CIMParameter
CIMInstance CIMQualifier
CIMInstanceName CIMQualifierDeclaration

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

Boolean Python bool

Char16 Python string

string Python string

Uint/Sint(8,16,32,64) pywbem class for each

Real (32,64) pywbem classes

CIMDateTime pywbem datetime

Array Python list

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

A single subscription is instances CIM_IndicationSubscription


the 3 classes above Association relates the
• All must exist for a subscription indicationFilter to Destination
• They are persistent in the server instances
• Normally in server interop
namespace
16
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 16
Profiles – The Heart of SMI-S
• Subset of schema to represent a
WBEM management domain
Profiles • What is managed by a server and how
WBEM Infrastructure
Operations, Events, Query Languages, to access the data in the profile
Namespaces
Profiles • Defines resource classes,
WBEM Protocols • Systems associations, indications, methods,
CIM-XML, etc. • Devices
• Software scripts
• Define constraints not in schema for
CIM Schema the domain
CIM Models, classes, etc. • Adaptations of classes
CIM Infrastructure • May be autonomous or components of
Meta schema, Schema, Rules, Initiatives, MOF other profiles

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

DMTF SCHEMA Class adaptations for


• Define classes that represent
MOF resources the profile
• CIMQualifiers • Define Class
properties/methods important
• CIMCLasses for this use of class
• Group information into levels of Indication/subscription
profile Definitions
• Auto vs component profiles

Central and/or Scoping Class


Usage for The profile definitions
• Resources Managed
• Management
Use Cases and example scripts
characteristics (FCAP)
• Use cases

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())

# Get the names only


inames = CONN.EnumerateInstances (
‘CIM_ComputerSystem’)
for iname in inames:
print(‘%s’% iname)
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 28
28
Higher Level objects: WBEM Server
conn = WBEMConnection(…)
svr = WBEMServer(conn)
 WBEM Server
 Interop namespace print(‘interop %s’ svr.interop.ns)
 Namespaces print(‘ns %s’% svr.namespaces
for inst in svr.profiles:
 Registered profiles
org = org_vm.tovalues(…)
 Server brand name = inst[‘RegisteredName’
 Server version vers = inst[‘RegisteredVersion`]
print(‘ %s %s %s’ % (org, name,
 Central/scoping
vers))
instances
2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 29
pywbem indications support
 pywbem SubscriptionManager Pywbem WBEM Server
creates/deletes indication Client
Create/Delete
subscriptions for multiple Filters, Dest, SMI Profile
WBEM Class SMI Profile
servers/listeners Subscriptions
Subscriptions
SMI Profile
 Supports persistence
differences between server
and client
Listener
Indications
 pywbem listener implements (separate
Threads)
functionality of a WBEM
indication listener

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

 pywbem well documented


 Documented with sphinx on readthedocs
 APIs
 Jupyter Notebook examples
 General usage, installation, developer support
 Change log

2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 33
Pywbem Next Steps

 More specific function classes in pywbem


 Ex. Job Control
 Integrate with specific profile implementations
 User direct access to profile level required to
implement automation, scripts, etc.

2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 34
34
Pywbem and automation
Orchestration Tools
• Ansible Scripts
 Orchestration tools • …

 Ansible, etc. Python Profile Definitions


• Python class to manage the profile
 Cmd line scripts • Get central/scoping instances
• Resource classes and associations for
 Python or script the profile
• Profile methods
languages • Indication subscription definitions

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

 pywbem package  pywbem tools package


 Operation Logging  Part of pywbem project
 Last operation capture  pywbemtools repo
 Operation Recorder  pywbemcli
 Cmd line browser
 MOF Compiler
 Near release now.
 wbemcli
 WBEM server mock

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

 Simpler client code


 Eliminates intermediate variables like end_of_sequence,
enum_context
 Matches pythonic pattern of iteration
 The call returns a generator
 Removes decision making on pull vs. non-pull from users to
optimize memory use on servers and clients.
 Returns decisions like enum size, etc. to system level
decisions.

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

 Iter… method determines if pull can be used by response to first request. If


CIM_ERR_NOT_SUPPORTED returned, assumes no pull operations
 Always prefers pull if it exists.
 First call determines if pull exists on server
 Subsequent requests use pull if initial request works.
 WBEMConnection attribute (use_pull_operations) allows caller to override
system decisions (force pull or non-pull)
 Allows pull on some request types with non pull on others if the server only
supports pull on some.
 Response can be terminated early with iter.close() statement

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)

props2 = {‘UI8’ : True, ‘UI8’ : Uint8(33))}

Inst1 = CIMInstance(‘CIM_foo`, properties=props1)


Inst2 = CIMInstance(‘CIM_foo`, properties=props2)

Inst3 = CIMInstance(‘CIM_Foo`,
properties={‘U1` :
CIMProperty(‘U1’,
Uint32(42)})

2018 Storage Developer Conference. © Insert Your Company Name. All Rights Reserved. 54

S-ar putea să vă placă și