{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using pywbem with pywbem_mock" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "import pywbem\n", "# The default namespace is root/cimv2\n", "from pywbem_mock import FakedWBEMConnection\n", "\n", "conn = FakedWBEMConnection()\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create the data in the repository" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# @hidden_cell\n", "# The following is MOF definition of some simple qualifier declarations, classes, and\n", "# instances\n", "initial_mof = \"\"\"\n", "// A simple mof model that creates the qualifier declarations,\n", "// classes, and instances for a very simplistic model to be used in the\n", "// pywbemcli mock test environment.\n", "\n", "#pragma locale (\"en_US\")\n", "Qualifier Association : boolean = false,\n", " Scope(association),\n", " Flavor(DisableOverride, ToSubclass);\n", "\n", "Qualifier Indication : boolean = false,\n", " Scope(class, indication),\n", " Flavor(DisableOverride, ToSubclass);\n", "\n", "Qualifier Abstract : boolean = false,\n", " Scope(class, association, indication),\n", " Flavor(EnableOverride, Restricted);\n", "\n", "Qualifier Aggregate : boolean = false,\n", " Scope(reference),\n", " Flavor(DisableOverride, ToSubclass);\n", "\n", "Qualifier Description : string = null,\n", " Scope(any),\n", " Flavor(EnableOverride, ToSubclass, Translatable);\n", "\n", "Qualifier In : boolean = true,\n", " Scope(parameter),\n", " Flavor(DisableOverride, ToSubclass);\n", "\n", "Qualifier Key : boolean = false,\n", " Scope(property, reference),\n", " Flavor(DisableOverride, ToSubclass);\n", "\n", "Qualifier Out : boolean = false,\n", " Scope(parameter),\n", " Flavor(DisableOverride, ToSubclass);\n", "\n", "Qualifier Override : string = null,\n", " Scope(property, reference, method),\n", " Flavor(EnableOverride, Restricted);\n", "\n", " [Description (\"Simple CIM Class\")]\n", "class CIM_Foo {\n", " [Key, Description (\"This is key property.\")]\n", " string InstanceID;\n", "\n", " [Description (\"This is Uint32 property.\")]\n", " uint32 IntegerProp;\n", "\n", " [Description (\"Method with in and out parameters\")]\n", " uint32 Fuzzy(\n", " [IN, Description(\"FuzzyMethod Param\")]\n", " string FuzzyParameter,\n", "\n", " [IN, OUT, Description ( \"Test of ref in/out parameter\")]\n", " CIM_Foo REF Foo,\n", "\n", " [IN ( false ), OUT, Description(\"TestMethod Param\")]\n", " string OutputParam);\n", "\n", " [ Description(\"Method with no Parameters\") ]\n", " uint32 DeleteNothing();\n", "};\n", "\n", " [Description (\"Subclass of CIM_Foo\")]\n", "class CIM_Foo_sub : CIM_Foo {\n", " string cimfoo_sub;\n", "};\n", "\n", " [Description (\"Subclass of CIM_Foo_sub\")]\n", "class CIM_Foo_sub_sub : CIM_Foo_sub {\n", " string cimfoo_sub_sub;\n", " [Description(\"Sample method with input and output parameters\")]\n", " uint32 Method1(\n", " [IN ( false), OUT, Description(\"Response param 2\")]\n", " string OutputParam2);\n", "};\n", "\"\"\"\n", "\n", "conn.compile_mof_string(initial_mof)\n", "# conn.display_repository()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "## get classes" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cls = conn.GetClass('CIM_Foo')\n", "print(cls.tomof())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Show the properties in the class as a list" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('Keys in class %s are %s' % (cls.classname, cls.properties.keys()))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# get instances of a class" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cls = conn.EnumerateInstances('CIM_Foo')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# TODO extend this demo to more complex operations" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.14" } }, "nbformat": 4, "nbformat_minor": 2 }