{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# GetInstance"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"#\" onclick=\"history.back()\">&lt;--- Back</a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The [`GetInstance()`](https://pywbem.readthedocs.io/en/latest/client.html#pywbem.WBEMConnection.GetInstance) method returns a [`pywbem.CIMInstance`](https://pywbem.readthedocs.io/en/latest/client.html#pywbem.CIMInstance) object, given a [`pywbem.CIMInstanceName`](https://pywbem.readthedocs.io/en/latest/client.html#pywbem.CIMInstanceName) object that references the desired CIM instance.\n",
    "\n",
    "The following code extends the [EnumerateInstanceNames](https://nbviewer.jupyter.org/github/pywbem/pywbem/blob/master/docs/notebooks/enuminstnames.ipynb) example by the use of `GetInstance` on each of the returned instance paths."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "import sys\n",
    "import pywbem\n",
    "\n",
    "username = 'user'\n",
    "password = 'password'\n",
    "classname = 'CIM_ComputerSystem'\n",
    "namespace = 'root/cimv2'\n",
    "server = 'http://localhost'\n",
    "\n",
    "conn = pywbem.WBEMConnection(server, (username, password),\n",
    "                             default_namespace=namespace,\n",
    "                             no_verification=True)\n",
    "try:\n",
    "    cs_paths = conn.EnumerateInstanceNames(classname, namespace)\n",
    "except pywbem.Error as exc:\n",
    "    print('EnumerateInstanceNames failed: %s' % exc)\n",
    "    sys.exit(1)\n",
    "\n",
    "for cs_path in cs_paths:\n",
    "\n",
    "    print('Instance at: %s' % cs_path)\n",
    "\n",
    "    try:\n",
    "        cs_inst = conn.GetInstance(cs_path)\n",
    "    except pywbem.Error as exc:\n",
    "        print('GetInstance failed: %s' % exc)\n",
    "        sys.exit(1)\n",
    "\n",
    "    for prop_name, prop_value in cs_inst.items():\n",
    "        print('  %s: %r' % (prop_name, prop_value))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<a href=\"#\" onclick=\"history.back()\">&lt;--- Back</a>"
   ]
  }
 ],
 "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.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
