Source code for LMIInstanceName

# Copyright (C) 2012-2013 Peter Hatina <phatina@redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import sys

from LMIBaseObject import LMIWrapperBaseObject
from LMIUtil import lmi_wrap_cim_instance

[docs]class LMIInstanceName(LMIWrapperBaseObject): """ LMI wrapper class representing :py:class:`CIMInstanceName`. :param LMIConnection conn: connection object :param CIMInstanceName cim_instance_name: wrapped object """ def __init__(self, conn, cim_instance_name): super(LMIInstanceName, self).__init__(conn) self._cim_instance_name = cim_instance_name def __getattr__(self, name): """ Simplifies the code. Key properties values can be retrieved by :samp:`object.key_property`. :param string name: class member or key property name :returns: class member or key property """ if name in self.__dict__: return self.__dict__[name] key_props = self.key_properties() if key_props and name in key_props: return self._cim_instance_name[name] raise AttributeError(name) def __repr__(self): """ :returns: pretty string for the object """ return "%s(...)" % self.__class__.__name__
[docs] def to_instance(self): """ Creates a new :py:class:`LMIInstance` object from :py:class:`LMIInstanceName`. :returns: :py:class:`LMIInstance` object if the object was retrieved successfully; None otherwise. **Usage:** :ref:`instance_names_conversion`. """ (cim_instance, _, errorstr) = self._conn._client._get_instance( self._cim_instance_name, LocalOnly=False) if not cim_instance: return None return lmi_wrap_cim_instance(self._conn, cim_instance, self._cim_instance_name.classname, self._cim_instance_name.namespace )
[docs] def key_properties(self): """ :returns: list of strings of key properties **Usage:** :ref:`instance_names_key_properties`. """ return self._cim_instance_name.keys()
[docs] def print_key_properties(self): """ Prints out the list of key properties. **Usage:** :ref:`instance_names_key_properties`. """ for name in self._cim_instance_name.keys(): sys.stdout.write("%s\n" % name)
[docs] def key_properties_dict(self): """ :returns: dictionary with key properties and corresponding values """ return self._cim_instance_name.keybindings.copy()
[docs] def key_property_value(self, prop_name): """ :param string prop_name: key property name :returns: key property value """ return getattr(self, prop_name)
@property
[docs] def classname(self): """ :returns: class name :rtype: string """ return self._cim_instance_name.classname
@property
[docs] def namespace(self): """ :returns: namespace name :rtype: string """ return self._cim_instance_name.namespace
@property
[docs] def path(self): """ :returns: path object :rtype: :py:class:`pywbem.CIMInstanceName` """ return self._cim_instance_name