### pywbemcli Interactive Shell Session Example Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/cmdlineinterface.rst.txt Shows a typical session in the pywbemcli interactive shell, including starting the shell, executing commands like 'class enumerate' and 'class get', and exiting the shell. ```text $ pywbemcli -s http://localhost -d root/cimv2 -u username pywbemcli> class enumerate --no . . . pywbemcli> class get CIM_System . . . pywbemcli> :q ``` -------------------------------- ### Simple Log Configuration Examples Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/generaloptions.rst.txt Provides the simplest log configuration strings to enable logging for all components to either stderr or a file. These are useful for basic logging setup. ```text all=stderr all=file ``` -------------------------------- ### Define and Use a Mock WBEM Server Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/generaloptions.rst.txt This example demonstrates how to define a mock WBEM server using MOF and Python files, and then save and inspect the connection. The mock server definition speeds up loading when pywbemcli starts. ```text $ pywbemcli --mock-server classdefs.mof --mock-server insts.py --default-namespace root/myhome pywbemcli> connection show name: not-saved (current) server: mock-server: classdefs.mof, insts.py . . . pywbemcli> connection save mymockserver pywbemcli> connection show Connection status: name value (state) ----------------- ------------------------------------------ name mock1 (current) server default-namespace root/cimv2 user password timeout 30 use-pull pull-max-cnt 1000 verify True certfile keyfile mock-server tests/unit/pywbemcli/simple_mock_model.mof ca-certs pywbemcli>class enumerate --names-only CIM_BaseEmb CIM_BaseRef CIM_Foo CIM_FooAssoc pywbemcli> ``` -------------------------------- ### Setup Mock WBEM Server with Dependent Files Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/mock_support.html This example demonstrates how to set up a mock WBEM server by registering dependent files, including the script file itself. This is applicable for Python versions 3.5 and above using the `__file__` attribute. ```python def _setup(conn, server, verbose): ... # Note: this only works for new-style scripts interop_mof_file = 'mock_interop.mof' this_file_path = __file__ register_dependents(conn, this_file_path, interop_mof_file) ``` ```python def _setup(conn, server, verbose): . . . # Note: This only works for Python gt version 3.5 using __file__ this_file_path = __file__ # Register the script file itself and any other files used in the script. register_dependents(conn, this_file_path, ) ``` -------------------------------- ### Show Client Statistics with Mock Environment Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/commands.html Displays client-maintained statistics in interactive mode when connected to a mock environment. This example shows statistics for operations like compile_mof_file and CreateClass, with Server Time often reported as 0 in mock setups. ```shell $ pywbemcli -n mock1 pywbemcli> class enumerate --di --no CIM_Foo CIM_Foo_sub CIM_Foo_sub2 CIM_Foo_sub_sub pywbemcli> statistics show Client statistics Operation Count Errors Client Time Server Time Request Size Response Size [ms] [ms] [B] [B] ------------------------- ------- -------- ------------- ------------- -------------- --------------- compile_mof_file(ns=None) 1 0 149.862 0 0 0 CreateClass 4 0 4.075 0 0 0 CreateInstance 12 0 1.715 0 0 0 EnumerateClassNames 1 0 0.167 0 0 0 SetQualifier 10 0 0.139 0 0 0 ``` -------------------------------- ### INSTANCENAME Examples Source: https://pywbemtools.readthedocs.io/en/latest/_sources/appendix.rst.txt Examples of INSTANCENAME formats suitable for pywbemcli command-line arguments. Supports untyped WBEM URIs and wildcard keys. ```text CIM_RegisteredProfile.InstanceID="acme:1" CIM_System.CreationClassName="ACME_System",Name="MySystem" CIM_System.? ``` -------------------------------- ### Example pywbemcli Command with Server Option Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/commands.rst.txt A basic example of invoking a pywbemcli command, specifically setting the server URL using the `-s` option. ```text $ pywbemcli -s https:/blah ``` -------------------------------- ### Install Pywbemtools Prerequisites for Development Source: https://pywbemtools.readthedocs.io/en/latest/_sources/development.rst.txt Install necessary Python and OS-level packages for pywbemtools development using the Makefile. Ensure a Python virtual environment is active. ```bash $ make develop ``` -------------------------------- ### Example: Create Destination, Filter, and Subscription Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/commands.html This example demonstrates the complete process of creating an indication subscription. It first adds a destination, then a filter, and finally associates them using `add-subscription`. Use the `--owned` flag for temporary resources. ```bash $ pywbemcli -s https:/blah pywbemcli> subscription add-destinations odest1 --listener-url http://my-listener:5000 --owned Added owned destination: Name=pywbemdestination:defaultpywbemcliSubMgr:odest1 pywbemcli> subscription add-filter ofilter1 --query-language DMTF:CQL -q "SELECT * from CIM_blah" --owned Added owned filter: Name=pywbemfilter:defaultpywbemcliSubMgr:ofilter1 pywbemcli> subscription list-destinations Indication Destinations: submgr-id=defaultpywbemcliSubMgr, svr-id=http://FakedUrl:5988, type=all +-------------+------------+--------------------------------+-------------------+---------------+------------+----------------+ | Ownership | Identity | Name | Destination | Persistence | Protocol | Subscription | | | | Property | | Type | | Count | |-------------+------------+--------------------------------+-------------------+---------------+------------+----------------| | owned | odest1 | pywbemdestination:defaultpywbe | http://blah:5000 | 3 | 2 | 0 | | | | mcliSubMgr:odest1 | | | | | +-------------+------------+--------------------------------+-------------------+---------------+------------+----------------+ pywbemcli> subscription list-filters Indication Filters: submgr-id=defaultpywbemcliSubMgr, svr-id=http://FakedUrl:5988 type=all +-------------+------------+--------------------------------+----------------+------------+--------------+----------------+ | Ownership | identity | Name | Query | Query | Source | Subscription | | | | Property | | Language | Namespaces | Count | |-------------+------------+--------------------------------+----------------+------------+--------------+----------------| | owned | ofilter1 | pywbemfilter:defaultpywbemcliS | SELECT * from | WQL | root/cimv2 | 0 | | | | ubMgr:ofilter1 | CIM_Indication | | | | +-------------+------------+--------------------------------+----------------+------------+--------------+----------------+ pywbemcli> subscription add-subscription pdest1 pfilter1 --owned Added owned subscription: DestinationName=pywbemdestination:defaultpywbemcliSubMgr:odest1, FilterName=pywbemfilter:defaultpywbemcliSubMgr:ofilter1 ``` -------------------------------- ### Get CIM Class Example Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/cmdlineinterface.rst.txt An example of how to retrieve a CIM class definition. This command specifies the class name, namespace, and output format. ```text $ pywbemcli --output-format mof class get CIM_ManagedElement --namespace interop ``` -------------------------------- ### pywbemcli instance create Help Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/cmdshelp.html Displays help for the `pywbemcli instance create` command. Use this to understand how to create CIM instances, specify properties, and set the namespace. ```text Usage: pywbemcli [GENERAL-OPTIONS] instance create CLASSNAME [COMMAND-OPTIONS] Create an instance of a class in a namespace. Create a CIM instance of the specified creation class (CLASSNAME argument) in the specified CIM namespace (--namespace option), with the specified properties (--property options) and display the CIM instance path of the created instance. If no namespace was specified, the default namespace of the connection is used. The properties to be initialized and their new values are specified using the --property option, which may be specified multiple times. Pywbemcli retrieves the class definition from the server in order to verify that the specified properties are consistent with the property characteristics in the class definition. Example: pywbemcli instance create CIM_blah -P id=3 -P arr="bla bla",foo Command Options: -p, --property PROPERTYNAME=VALUE Initial property value for the new instance. May be specified multiple times. Array property values are specified as a comma-separated list; embedded instances are not supported. Default: No initial properties provided. -V, --verify Prompt for confirmation before performing a change, to allow for verification of parameters. Default: Do not prompt for confirmation. -n, --namespace NAMESPACE Namespace to use for this command, instead of the default namespace of the connection. -h, --help Show this help message. ``` -------------------------------- ### INSTANCENAME examples for UNIX-like shells Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/features.html Illustrates various ways to specify INSTANCENAME arguments on the command line for UNIX-like shells, including different key types and quoting. ```bash pywbemcli instance get root/cimv2:MY_Foo.ID=42 ``` ```bash pywbemcli instance get MY_Foo.ID=42 ``` ```bash pywbemcli instance get "MY_Foo.CharKey='x'" ``` ```bash pywbemcli instance get 'MY_Foo.InstanceID="foo1"' ``` ```bash pywbemcli instance get "MY_Foo.InstanceID=\"$\"" ``` ```bash pywbemcli instance get 'MY_CS.CreationClassName="MY_CS",Name="MyComp"' ``` ```bash pywbemcli instance get 'MY_LogEntry.Timestamp="20190901183853.762122+120"' ``` -------------------------------- ### Start a New WBEM Indication Listener (HTTPS) Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemlistener/commands.rst.txt Starts a new WBEM indication listener process in the background. This example demonstrates starting a listener for HTTPS, requiring certificate and key file paths. ```text $ pywbemlistener start lis1 --cert-file .../certs/server_cert.pem --key-file .../certs/server_key.pem # Running listener lis1 at https://localhost:25989 ``` -------------------------------- ### Pywbemcli Class Get Example Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/cmdlineinterface.html Retrieves a CIM class in MOF format from a specific namespace. ```bash $ pywbemcli --output-format mof class get CIM_ManagedElement --namespace interop ``` -------------------------------- ### Create MOF file and enumerate qualifiers Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/mock_support.rst.txt This example demonstrates creating a MOF file with qualifier declarations and then using pywbemcli to enumerate these qualifiers from the mock server. ```bash cat <> gualdecls.mof Qualifier Abstract : boolean = false, Scope(class, association, indication), Flavor(EnableOverride, Restricted); Qualifier Aggregate : boolean = false, Scope(reference), Flavor(DisableOverride, ToSubclass); EOT # start pywbemcli with the mof script and it displays the qualifiers pywbemcli -m qualdecl.mof qualifier enumerate Qualifier Abstract : boolean = false, Scope(class, association, indication), Flavor(EnableOverride, Restricted); Qualifier Aggregate : boolean = false, Scope(reference), Flavor(DisableOverride, ToSubclass); ``` -------------------------------- ### Get CIM instance with integer key Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/features.rst.txt Example of retrieving a CIM instance using its class name and an integer key property. ```bash pywbemcli instance get root/cimv2:MY_Foo.ID=42 ``` -------------------------------- ### Test pywbemlistener Tab-Completion Source: https://pywbemtools.readthedocs.io/en/latest/settingsandconfiguration.html Enter part of a command and press TAB to test tab-completion for pywbemlistener. This example shows completing 'star' to 'start'. ```shell $ pywbemlistener star ``` -------------------------------- ### Example of pywbemlistener command with general option Source: https://pywbemtools.readthedocs.io/en/latest/pywbemlistener/generaloptions.html Demonstrates how to use a general option like `--output-format` with a pywbemlistener sub-command. ```bash pywbemlistener --output-format simple list ``` -------------------------------- ### Get CIM instance with multiple string keys Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/features.rst.txt Example of retrieving a CIM instance that has multiple string key properties, specifying each key-value pair. ```bash pywbemcli instance get 'MY_CS.CreationClassName="MY_CS",Name="MyComp"' ``` -------------------------------- ### Get CIM instance without namespace Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/features.rst.txt Example of retrieving a CIM instance when the namespace is not explicitly specified in the INSTANCENAME argument, relying on the default or connection namespace. ```bash pywbemcli instance get MY_Foo.ID=42 ``` -------------------------------- ### Example Log Configuration Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/generaloptions.rst.txt Illustrates a complex log configuration string, logging API calls to a file with summary details and HTTP requests/responses to stderr. This demonstrates granular control over logging. ```bash $ pywbemcli --log api=file:summary,http=stderr ``` -------------------------------- ### New-style Mock Script Setup Function Signature Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/mock_support.html The `setup()` function is used in new-style mock scripts (Python >= 3.5) to provide the mock script with information about the mock environment. It receives a connection object, a server object, and a verbose flag. ```python def setup(conn, server, verbose): ``` -------------------------------- ### Get CIM instance with escaped string key Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/features.rst.txt Example of retrieving a CIM instance with a string key that requires escaping double quotes within the value. ```bash pywbemcli instance get "MY_Foo.InstanceID=\"foo1\"" ``` -------------------------------- ### Example pywbemcli Instance References Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/commands.rst.txt Demonstrates how to use pywbemcli to list references for a specific instance and select one from a list. This example shows interactive instance selection. ```text $ pywbemcli --name mymock instance references TST_Person.? --names-only Pick Instance name to process: 0 0: root/cimv2:TST_Person.name="Mike" 1: root/cimv2:TST_Person.name="Saara" 2: root/cimv2:TST_Person.name="Sofi" 3: root/cimv2:TST_Person.name="Gabi" 4: root/cimv2:TST_PersonSub.name="Mikesub" 5: root/cimv2:TST_PersonSub.name="Saarasub" 6: root/cimv2:TST_PersonSub.name="Sofisub" 7: root/cimv2:TST_PersonSub.name="Gabisub" Input integer between 0 and 7 or Ctrl-C to exit selection: 0 << entered by user //FakedUrl/root/cimv2:TST_Lineage.InstanceID="MikeSofi" //FakedUrl/root/cimv2:TST_Lineage.InstanceID="MikeGabi" //FakedUrl/root/cimv2:TST_MemberOfFamilyCollection.family="root/cimv2:TST_FamilyCollection.name=\"Family2\"",member="root/cimv2:TST_Person.name=\"Mike\"" ``` -------------------------------- ### Get CIM instance with string key Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/features.rst.txt Example of retrieving a CIM instance using its class name and a string key property, enclosed in single quotes. ```bash pywbemcli instance get 'MY_Foo.InstanceID="foo1"' ``` -------------------------------- ### Getting pywbemlistener help Source: https://pywbemtools.readthedocs.io/en/latest/pywbemlistener/generaloptions.html Displays help information for the pywbemlistener command and its general options. ```bash pywbemlistener --help ``` ```bash pywbemlistener -h ``` -------------------------------- ### Get CIM instance with character key Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/features.rst.txt Example of retrieving a CIM instance using its class name and a character key property, enclosed in single quotes. ```bash pywbemcli instance get "MY_Foo.CharKey='x'" ``` -------------------------------- ### Start pywbemcli REPL Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/commands.rst.txt Execute pywbemcli without arguments to enter the interactive REPL mode. Use 'help' for assistance or /':q' to exit. ```text $ pywbemcli Enter 'help' for help, or ':q' to exit pywbemcli. pywbemcli> ``` -------------------------------- ### Pywbemcli Tab Completion Examples Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/cmdlineinterface.html Demonstrates how tab completion works for general options, command groups, commands, and option values. ```bash $ pywbemcli -- ... ``` ```bash $ pywbemcli ... ``` ```bash $ pywbemcli clas ... completes the command group command ``class`` ``` ```bash $ pywbemcli class ... ``` ```bash $ pywbemcli -n moc ... returns ``mock`` ``` ```bash $ pywbemcli -n mock a ... returns list of defined connection names that start with ``a``. ``` -------------------------------- ### Starting Pywbemcli Interactive Mode Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/cmdlineinterface.rst.txt Shows how to start the pywbemcli interactive shell by invoking the command without any specific command group or by using the 'repl' command. ```text $ pywbemcli [GENERAL-OPTIONS] pywbemcli> _ ``` ```text $ pywbemcli [GENERAL-OPTIONS] repl pywbemcli> _ ``` -------------------------------- ### Install pywbemtools using pipx Source: https://pywbemtools.readthedocs.io/en/latest/_sources/introduction.rst.txt Use pipx to install the latest released version of pywbemtools system-wide. Ensure pipx is installed first. ```bash $ pipx install pywbemtools ``` -------------------------------- ### Install Development Dependencies Source: https://pywbemtools.readthedocs.io/en/latest/development.html Install pywbemtools and its development prerequisites using the Makefile. This command installs necessary Python and OS-level packages into the active Python environment. ```bash $ make develop ``` -------------------------------- ### Pywbemcli Tab-Completion Examples Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/cmdlineinterface.rst.txt Demonstrates various scenarios of using tab-completion with the pywbemcli command to explore options, commands, and connection names. ```text $ pywbemcli -- ... ``` ```text $ pywbemcli ... ``` ```text $ pywbemcli clas ... completes the command group command ``class`` ``` ```text $ pywbemcli class ... ``` ```text $ pywbemcli -n moc ... returns ``mock`` ``` ```text $ pywbemcli -n mock a ... returns list of defined connection names that start with ``a``. ``` -------------------------------- ### Update Local Repo and Start Tag Source: https://pywbemtools.readthedocs.io/en/latest/_sources/development.rst.txt After merging the start branch, use this command to update the local repository, delete the start branch, and create/push the initial tag for the new version. ```sh VERSION=M.N.U make start_tag ``` -------------------------------- ### Create MOF file with Qualifier Declarations Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/mock_support.html This example demonstrates how to create a MOF file containing qualifier declarations. The file can then be used to define the mock server's CIM model. ```shell cat <> gualdecls.mof Qualifier Abstract : boolean = false, Scope(class, association, indication), Flavor(EnableOverride, Restricted); Qualifier Aggregate : boolean = false, Scope(reference), Flavor(DisableOverride, ToSubclass); EOT ``` -------------------------------- ### Python module example Source: https://pywbemtools.readthedocs.io/en/latest/pywbemlistener/commands.html Example of a Python module file that can be called by pywbemlistener. ```python def func(indication, host): pass ``` -------------------------------- ### Set Server via Environment Variable Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/generaloptions.rst.txt This example demonstrates how to set the pywbemcli server using the PYWBEMCLI_SERVER environment variable. The command then retrieves class information. ```text $ export PYWBEMCLI_SERVER=http://localhost $ pywbemcli class get CIM_ManagedElement ``` -------------------------------- ### Show Statistics in Mock Environment Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/commands.rst.txt Illustrates the 'statistics show' command within a mock pywbemcli environment. This example shows how statistics are displayed when interacting with a mock server, including operations like 'compile_mof_file' and 'CreateClass'. ```text $ pywbemcli -n mock1 pywbemcli> class enumerate --di --no CIM_Foo CIM_Foo_sub CIM_Foo_sub2 CIM_Foo_sub_sub pywbemcli> statistics show Client statistics Operation Count Errors Client Time Server Time Request Size Response Size [ms] [ms] [B] [B] ------------------------- ------- -------- ------------- ------------- -------------- --------------- compile_mof_file(ns=None) 1 0 149.862 0 0 0 CreateClass 4 0 4.075 0 0 0 CreateInstance 12 0 1.715 0 0 0 EnumerateClassNames 1 0 0.167 0 0 0 ``` -------------------------------- ### Install virtualenv Source: https://pywbemtools.readthedocs.io/en/latest/_sources/introduction.rst.txt Install the 'virtualenv' package into your system Python. This is a prerequisite for creating virtual environments. ```bash $ pip install virtualenv ``` -------------------------------- ### Update Local Repo and Start Tag from Specific Stable Branch Source: https://pywbemtools.readthedocs.io/en/latest/_sources/development.rst.txt Use this command when the start branch was based on a specific stable branch. It ensures the local repo is updated correctly, deleting the start branch and creating the tag. ```sh VERSION=M.N.0 BRANCH=stable_M.N make start_tag ``` -------------------------------- ### Install Development Branch of pywbemtools Source: https://pywbemtools.readthedocs.io/en/latest/introduction.html Installs pywbemtools from a specific development branch, such as 'master', directly from a GitHub repository. ```bash (pywbemtools) $ pip install git+https://github.com/pywbem/pywbemtools.git@master ``` -------------------------------- ### New-style Setup Function Interface Source: https://pywbemtools.readthedocs.io/en/latest/_sources/pywbemcli/mock_support.rst.txt This is the interface for the setup() function in new-style mock scripts (Python 3.5+). It provides the mock script with connection and server objects, along with a verbose flag. ```python def setup(conn, server, verbose): pass ``` -------------------------------- ### CIMInstanceName Output Example Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/generaloptions.html Example of a CIMInstanceName (instance path) formatted as a UNICODE string. This is a specific string format, not MOF. ```text //ACME.com/cimv2/Test:CIM_RegisteredProfile.InstanceID=”Acme.1” ``` -------------------------------- ### Get Help for Instance Name Specification Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/commands.html Shows help message for specifying INSTANCENAME, including options like '--key' and '--namespace'. ```bash $ pywbemcli --help-instancename ``` -------------------------------- ### Start pywbemcli Shell and Execute Commands Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/cmdlineinterface.html Starts the pywbemcli shell in interactive mode, executes several commands, and then exits the shell. ```bash $ pywbemcli -s http://localhost -d root/cimv2 -u username pywbemcli> class enumerate --no . . . pywbemcli> class get CIM_System . . . pywbemcli> :q ``` -------------------------------- ### Text Plain Output Example Source: https://pywbemtools.readthedocs.io/en/latest/pywbemcli/generaloptions.html Example of plain text output for server namespaces. This format is minimal and suitable for piping to other commands. ```bash $ pywbemcli --mock-server tests/unit/testmock/wbemserver_mock.py -o text server namespaces interop ```