def CreateInstance(self, NewInstance, namespace=None, **extra):
        # pylint: disable=invalid-name
        """
        Create an instance in a namespace.

        This method performs the CreateInstance operation
        (see :term:`DSP0200`). See :ref:`WBEM operations` for a list of all
        methods performing such operations.

        If the operation succeeds, this method returns.
        Otherwise, this method raises an exception.

        The creation class for the new instance is taken from the `classname`
        attribute of the `NewInstance` parameter.

        The namespace for the new instance is taken from these sources, in
        decreasing order of priority:

          * `namespace` parameter of this method, if not `None`,
          * namespace in `path` attribute of the `NewInstance` parameter, if
            not `None`,
          * default namespace of the connection.

        Parameters:

          NewInstance (:class:`~pywbem.CIMInstance`):
            A representation of the CIM instance to be created.

            The `classname` attribute of this object specifies the creation
            class for the new instance.

            Apart from utilizing its namespace, the `path` attribute is ignored.

            The `properties` attribute of this object specifies initial
            property values for the new CIM instance.

            Instance-level qualifiers have been deprecated in CIM, so any
            qualifier values specified using the `qualifiers` attribute
            of this object will be ignored.

          namespace (:term:`string`):
            Name of the CIM namespace to be used (case independent).

            *New in pywbem 0.9.*

            If `None`, defaults to the namespace in the `path` attribute of the
            `NewInstance` parameter, or to the default namespace of the
            connection.

            Leading and trailing slash characters will be stripped. The lexical
            case will be preserved.

          **extra :
            Additional keyword arguments are passed as additional operation
            parameters to the WBEM server.
            Note that :term:`DSP0200` does not define any additional parameters
            for this operation.

        Returns:

            A :class:`~pywbem.CIMInstanceName` object that is the instance
            path of the new instance, with classname, keybindings and
            namespace set.

        Raises:

            Exceptions described in :class:`~pywbem.WBEMConnection`.
        """

        exc = None
        instancename = None
        method_name = 'CreateInstance'

        if self._operation_recorders:
            self.operation_recorder_reset()
            self.operation_recorder_stage_pywbem_args(
                method=method_name,
                NewInstance=NewInstance,
                namespace=namespace,
                **extra)

        try:

            stats = self.statistics.start_timer(method_name)
            if namespace is None and \
               getattr(NewInstance.path, 'namespace', None) is not None:
                namespace = NewInstance.path.namespace
            namespace = self._iparam_namespace_from_namespace(namespace)

            instance = NewInstance.copy()

            # Strip off path to avoid producing a VALUE.NAMEDINSTANCE element
            # instead of the desired INSTANCE element.
            instance.path = None

            result = self._imethodcall(
                method_name,
                namespace,
                NewInstance=instance,
                **extra)

            if result is None:
                raise CIMXMLParseError(
                    "Expecting a child element below IMETHODRESPONSE, "
                    "got no child elements", conn_id=self.conn_id)
            result = result[0][2]  # List of children of IRETURNVALUE

            if not result:
                raise CIMXMLParseError(
                    "Expecting a child element below IRETURNVALUE, "
                    "got no child elements", conn_id=self.conn_id)
            instancename = result[0]  # CIMInstanceName object

            if not isinstance(instancename, CIMInstanceName):
                raise CIMXMLParseError(
                    _format("Expecting CIMInstanceName object in result, got "
                            "{0} object", instancename.__class__.__name__),
                    conn_id=self.conn_id)

            # The CreateInstance CIM-XML operation returns an INSTANCENAME
            # element, so the resulting CIMInstanceName object does not have
            # namespace or host. We want to return an instance path with
            # namespace, so we set it to the effective target namespace.
            instancename.namespace = namespace

            return instancename

        except (CIMXMLParseError, XMLParseError) as exce:
            exce.request_data = self.last_raw_request
            exce.response_data = self.last_raw_reply
            exc = exce
            raise
        except Exception as exce:
            exc = exce
            raise
        finally:
            self._last_operation_time = stats.stop_timer(
                self.last_request_len, self.last_reply_len,
                self.last_server_response_time, exc)
            if self._operation_recorders:
                self.operation_recorder_stage_result(instancename, exc)
def CreateInstance ( self , NewInstance , namespace = None , ** extra ) : exc = None instancename = None method_name = 'CreateInstance' if self . _operation_recorders : self . operation_recorder_reset ( ) self . operation_recorder_stage_pywbem_args ( method = method_name , NewInstance = NewInstance , namespace = namespace , ** extra ) try : stats = self . statistics . start_timer ( method_name ) if namespace is None and getattr ( NewInstance . path , 'namespace' , None ) is not None : namespace = NewInstance . path . namespace namespace = self . _iparam_namespace_from_namespace ( namespace ) instance = NewInstance . copy ( ) instance . path = None result = self . _imethodcall ( method_name , namespace , NewInstance = instance , ** extra ) if result is None : raise CIMXMLParseError ( "Expecting a child element below IMETHODRESPONSE, " "got no child elements" , conn_id = self . conn_id ) result = result [ 0 ] [ 2 ] if not result : raise CIMXMLParseError ( "Expecting a child element below IRETURNVALUE, " "got no child elements" , conn_id = self . conn_id ) instancename = result [ 0 ] if not isinstance ( instancename , CIMInstanceName ) : raise CIMXMLParseError ( _format ( "Expecting CIMInstanceName object in result, got " "{0} object" , instancename . __class__ . __name__ ) , conn_id = self . conn_id ) instancename . namespace = namespace return instancename except ( CIMXMLParseError , XMLParseError ) as exce : exce . request_data = self . last_raw_request exce . response_data = self . last_raw_reply exc = exce raise except Exception as exce : exc = exce raise finally : self . _last_operation_time = stats . stop_timer ( self . last_request_len , self . last_reply_len , self . last_server_response_time , exc ) if self . _operation_recorders : self . operation_recorder_stage_result ( instancename , exc )
Create an instance in a namespace.

        This method performs the CreateInstance operation
        (see :term:`DSP0200`). See :ref:`WBEM operations` for a list of all
        methods performing such operations.

        If the operation succeeds, this method returns.
        Otherwise, this method raises an exception.

        The creation class for the new instance is taken from the `classname`
        attribute of the `NewInstance` parameter.

        The namespace for the new instance is taken from these sources, in
        decreasing order of priority:

          * `namespace` parameter of this method, if not `None`,
          * namespace in `path` attribute of the `NewInstance` parameter, if
            not `None`,
          * default namespace of the connection.

        Parameters:

          NewInstance (:class:`~pywbem.CIMInstance`):
            A representation of the CIM instance to be created.

            The `classname` attribute of this object specifies the creation
            class for the new instance.

            Apart from utilizing its namespace, the `path` attribute is ignored.

            The `properties` attribute of this object specifies initial
            property values for the new CIM instance.

            Instance-level qualifiers have been deprecated in CIM, so any
            qualifier values specified using the `qualifiers` attribute
            of this object will be ignored.

          namespace (:term:`string`):
            Name of the CIM namespace to be used (case independent).

            *New in pywbem 0.9.*

            If `None`, defaults to the namespace in the `path` attribute of the
            `NewInstance` parameter, or to the default namespace of the
            connection.

            Leading and trailing slash characters will be stripped. The lexical
            case will be preserved.

          **extra :
            Additional keyword arguments are passed as additional operation
            parameters to the WBEM server.
            Note that :term:`DSP0200` does not define any additional parameters
            for this operation.

        Returns:

            A :class:`~pywbem.CIMInstanceName` object that is the instance
            path of the new instance, with classname, keybindings and
            namespace set.

        Raises:

            Exceptions described in :class:`~pywbem.WBEMConnection`.