def create_cimnamespace_instance(conn, namespace, interop_namespace, klass): """ Build and execute CreateInstance for an instance of CIM_Namespace using the `namespace` parameter as the value of the name property in the instance. The instance is created in the `interop_namespace` Parameters: namespace (:term:`string`): Namespace that this instance defines. interop_namespace (:term:`string`): Interop namespace for this environment. klass (:class:`~pywbem.CIMClass`): The CIM class CIM_Namespace which is used to create the instance. Raises: :exc:`~pywbem.CIMError`: For errors encountered with CreateInstance """ properties = NocaseDict([ ('Name', namespace), ('CreationClassName', klass.classname), ('ObjectManagerName', OBJECTMANAGERNAME), ('ObjectManagerCreationClassName', OBJECTMANAGERCREATIONCLASSNAME), ('SystemName', SYSTEMNAME), ('SystemCreationClassName', SYSTEMCREATIONCLASSNAME) ]) new_instance = CIMInstance.from_class(klass, property_values=properties) conn.CreateInstance(new_instance, interop_namespace)
def inst_from_classname(self, class_name, namespace=None, property_list=None, property_values=None, include_missing_properties=True, include_path=True): # pylint: disable=too-many-arguments """ Build instance from classname using class_name property to get class from a repository. """ cls = self.conn.GetClass(class_name, namespace=namespace, LocalOnly=False, IncludeQualifiers=True, IncludeClassOrigin=True, PropertyList=property_list) return CIMInstance.from_class( cls, namespace=namespace, property_values=property_values, include_missing_properties=include_missing_properties, include_path=include_path)
def inst_from_classname(conn, class_name, namespace=None, property_list=None, property_values=None, include_missing_properties=True, include_path=True): # TODO AM 8/18 The inst_from_classname() method is not used. """ Build instance from class using class_name property to get class from a repository. """ cls = conn.GetClass(class_name, namespace=namespace, LocalOnly=False, IncludeQualifiers=True, include_class_origin=True, property_list=property_list) return CIMInstance.from_class( cls, namespace=namespace, property_values=property_values, include_missing_properties=include_missing_properties, include_path=include_path)
def build_elementconformstoprofile_inst(self, conn, profile_path, element_path): """ Build an instance of CIM_ElementConformsToProfile and insert into repository """ class_name = 'CIM_ElementConformsToProfile' element_conforms_dict = { 'ConformantStandard': profile_path, 'ManagedElement': element_path } # TODO modify this when issue #1540 (resolve qualifiers)fixed # inst = self.inst_from_classname(conn, class_name, # namespace=self.interop_ns, # property_values=element_conforms_dict, # include_missing_properties=False, # include_path=True) cls = conn.GetClass(class_name, namespace=self.interop_ns, LocalOnly=False, IncludeQualifiers=True, IncludeClassOrigin=True) for pvalue in cls.properties.values(): if pvalue.type == 'reference': if "key" not in pvalue.qualifiers: pvalue.qualifiers['Key'] = \ CIMQualifier('Key', True, propagated=True) inst = CIMInstance.from_class(cls, namespace=self.interop_ns, property_values=element_conforms_dict, include_missing_properties=False, include_path=True) # TODO end of temp code conn.add_cimobjects(inst, namespace=self.interop_ns) assert conn.EnumerateInstances(class_name, namespace=self.interop_ns) assert conn.GetInstance(inst.path)
def build_referenced_profile_insts(self, server, referenced_profiles): """ Build and install in repository the referemced profile instances defined by the referemces parameter. A dictionary of tuples where each tuple contains Antecedent and Dependent reference in terms of the profile name as a tuple (org, name, version). Parameters: conn: profiles (dict of tuples where each tuple defines the antecedent and dependent) """ class_name = 'CIM_ReferencedProfile' for profile_name in referenced_profiles: antecedent = profile_name[0] dependent = profile_name[1] antecedent_inst = server.get_selected_profiles( registered_org=antecedent[0], registered_name=antecedent[1], registered_version=antecedent[2]) dependent_inst = server.get_selected_profiles( registered_org=dependent[0], registered_name=dependent[1], registered_version=dependent[2]) assert len(antecedent_inst) == 1, \ "Antecedent: {0}".format(antecedent) assert len(dependent_inst) == 1, \ "Dependent: {0}".format(dependent) ref_profile_dict = { 'Antecedent': antecedent_inst[0].path, 'Dependent': dependent_inst[0].path } # TODO replace the setting of key qualifier with the commented # code with #issue 1540 is fixed, i.e the key qualifier is # included in the class. # inst = self.inst_from_classname(server.conn, class_name, # namespace=self.interop_ns, # property_values=ref_profile_dict, # include_missing_properties=False, # include_path=True) cls = server.conn.GetClass(class_name, namespace=self.interop_ns, LocalOnly=False, IncludeQualifiers=True, IncludeClassOrigin=True, PropertyList=None) for pvalue in cls.properties.values(): if pvalue.type == 'reference': if "key" not in pvalue.qualifiers: pvalue.qualifiers['Key'] = \ CIMQualifier('Key', True, propagated=True) inst = CIMInstance.from_class(cls, namespace=self.interop_ns, property_values=ref_profile_dict, include_missing_properties=False, include_path=True) # TODO end of code to drop for #1540 fix server.conn.add_cimobjects(inst, namespace=self.interop_ns) assert server.conn.EnumerateInstances(class_name, namespace=self.interop_ns) assert server.conn.GetInstance(inst.path)