LMI_NASProtocolEndpoint code

ganesh kumar ganeshkumar14 at gmail.com
Wed Oct 9 11:01:33 UTC 2013


Hi,

 We are implemented "NAS Network Ports" profile, Started with
ProtocolEndpoint class, we implemented "LMI_NASProtocolEndpoint" class,
please review our code.

And also i have some doubt, How to add a condition when ever NFS process
runs it has to create an instance in NASProtocolEndpoint class, what logic
should i use?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.fedorahosted.org/pipermail/openlmi-devel/attachments/20131009/d1697622/attachment-0001.html>
-------------- next part --------------
#include <konkret/konkret.h>
#include "LMI_NASProtocolEndpoint.h"

#include "globals.h"
#include "network.h"
#include "port.h"
#include "setting.h"
#include "connection.h"


static const CMPIBroker* _cb = NULL;

static void LMI_NASProtocolEndpointInitialize(
    CMPIInstanceMI *mi,
    const CMPIContext *ctx)
{
	mi->hdl = network_ref(_cb, ctx);
}

static CMPIStatus LMI_NASProtocolEndpointCleanup(
    CMPIInstanceMI* mi,
    const CMPIContext* cc,
    CMPIBoolean term)
{
	network_unref(mi->hdl);
    	mi->hdl = NULL;
	CMReturn(CMPI_RC_OK);
}

static CMPIStatus LMI_NASProtocolEndpointEnumInstanceNames(
    CMPIInstanceMI* mi,
    const CMPIContext* cc,
    const CMPIResult* cr,
    const CMPIObjectPath* cop)
{
    return KDefaultEnumerateInstanceNames(
        _cb, mi, cc, cr, cop);
}

static CMPIStatus LMI_NASProtocolEndpointEnumInstances(
    CMPIInstanceMI* mi,
    const CMPIContext* cc,
    const CMPIResult* cr,
    const CMPIObjectPath* cop,
    const char** properties)
{
    CMPIStatus res = { CMPI_RC_OK, NULL };
    Network *network = mi->hdl;
    const char *ns = KNameSpace(cop);

    size_t j;
    Port *port;

    network_lock(network);
    const Ports *ports = network_get_ports(network);
    for (size_t i = 0; i < ports_length(ports); ++i) {
        if (!KOkay(res)) {
            break;
        }
        port = ports_index(ports, i);

            
	    LMI_NASProtocolEndpoint w;  
	    LMI_NASProtocolEndpoint_Init(&w, _cb, ns);

            LMI_NASProtocolEndpoint_Set_SystemName(&w, get_system_name());

            LMI_NASProtocolEndpoint_Set_SystemCreationClassName(&w, get_system_creation_class_name());

            LMI_NASProtocolEndpoint_Set_CreationClassName(&w, LMI_NASProtocolEndpoint_ClassName);

            LMI_NASProtocolEndpoint_Set_Name(&w, port_get_id(port));
           

	    LMI_NASProtocolEndpoint_Set_NameFormat(&w, "NAS");

	    //LMI_NASProtocolEndpoint_Set_OperatingStatus_OK(&w);
	    LMI_NASProtocolEndpoint_Set_OperationalStatus(&w, 2, LMI_NASProtocolEndpoint_OperationalStatus_OK);

	    LMI_NASProtocolEndpoint_Set_Description(&w, "LMI_NASProtocolEndpoint class object is used for FileSharing purpose");

	    LMI_NASProtocolEndpoint_Set_ProtocolIFType_NFS(&w);
            LMI_NASProtocolEndpoint_Set_ProtocolIFType(&w, LMI_NASProtocolEndpoint_ProtocolIFType_NFS);
                 
            if (!ReturnInstance(cr, w)) {
                error("Unable to return instance of class " LMI_NASProtocolEndpoint_ClassName);
                CMSetStatus(&res, CMPI_RC_ERR_FAILED);
		break;
            }             
        }
    network_unlock(network);                   
    return res;    
}

static CMPIStatus LMI_NASProtocolEndpointGetInstance(
    CMPIInstanceMI* mi,
    const CMPIContext* cc,
    const CMPIResult* cr,
    const CMPIObjectPath* cop,
    const char** properties)
{
    return KDefaultGetInstance(
        _cb, mi, cc, cr, cop, properties);
}

static CMPIStatus LMI_NASProtocolEndpointCreateInstance(
    CMPIInstanceMI* mi,
    const CMPIContext* cc,
    const CMPIResult* cr,
    const CMPIObjectPath* cop,
    const CMPIInstance* ci)
{
    CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
}

static CMPIStatus LMI_NASProtocolEndpointModifyInstance(
    CMPIInstanceMI* mi,
    const CMPIContext* cc,
    const CMPIResult* cr,
    const CMPIObjectPath* cop,
    const CMPIInstance* ci,
    const char** properties)
{
    CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
}

static CMPIStatus LMI_NASProtocolEndpointDeleteInstance(
    CMPIInstanceMI* mi,
    const CMPIContext* cc,
    const CMPIResult* cr,
    const CMPIObjectPath* cop)
{
    CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
}

static CMPIStatus LMI_NASProtocolEndpointExecQuery(
    CMPIInstanceMI* mi,
    const CMPIContext* cc,
    const CMPIResult* cr,
    const CMPIObjectPath* cop,
    const char* lang,
    const char* query)
{
    CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
}

CMInstanceMIStub(
    LMI_NASProtocolEndpoint,
    LMI_NASProtocolEndpoint,
    _cb,
    LMI_NASProtocolEndpointInitialize(&mi, ctx))

static void LMI_NASProtocolEndpointMethodInitialize(
    CMPIMethodMI *mi,
    const CMPIContext *ctx)
{
    mi->hdl = network_ref(_cb, ctx);
}

static CMPIStatus LMI_NASProtocolEndpointMethodCleanup(
    CMPIMethodMI* mi,
    const CMPIContext* cc,
    CMPIBoolean term)
{
    network_unref(mi->hdl);
    mi->hdl = NULL;
    CMReturn(CMPI_RC_OK);
}

static CMPIStatus LMI_NASProtocolEndpointInvokeMethod(
    CMPIMethodMI* mi,
    const CMPIContext* cc,
    const CMPIResult* cr,
    const CMPIObjectPath* cop,
    const char* meth,
    const CMPIArgs* in,
    CMPIArgs* out)
{
    return LMI_NASProtocolEndpoint_DispatchMethod(
        _cb, mi, cc, cr, cop, meth, in, out);
}

CMMethodMIStub(
    LMI_NASProtocolEndpoint,
    LMI_NASProtocolEndpoint,
    _cb,
    LMI_NASProtocolEndpointMethodInitialize(&mi, ctx))

KUint32 LMI_NASProtocolEndpoint_RequestStateChange(
    const CMPIBroker* cb,
    CMPIMethodMI* mi,
    const CMPIContext* context,
    const LMI_NASProtocolEndpointRef* self,
    const KUint16* RequestedState,
    KRef* Job,
    const KDateTime* TimeoutPeriod,
    CMPIStatus* status)
{
    KUint32 result = KUINT32_INIT;

    KSetStatus(status, ERR_NOT_SUPPORTED);
    return result;
}

KUint32 LMI_NASProtocolEndpoint_BroadcastReset(
    const CMPIBroker* cb,
    CMPIMethodMI* mi,
    const CMPIContext* context,
    const LMI_NASProtocolEndpointRef* self,
    CMPIStatus* status)
{
    KUint32 result = KUINT32_INIT;

    KSetStatus(status, ERR_NOT_SUPPORTED);
    return result;
}

KONKRET_REGISTRATION(
    "root/cimv2",
    "LMI_NASProtocolEndpoint",
    "LMI_NASProtocolEndpoint",
    "instance method")
-------------- next part --------------
[ Provider("cmpi:cmpiLMI_Networking"), Version("0.1.0") ]
class LMI_NASProtocolEndpoint: CIM_ProtocolEndpoint
{
    [ Implemented(true), Description(
	"The Description property provides a textual description of the object."),
      MappingStrings { "MIB.IETF|IF-MIB.ifDescr" }]
      string Description;

    [ Implemented(true), Description(
	"A string that identifies this ProtocolEndpoint with either a port or an interface on a device. To ensure uniqueness, "
	"the Name property should be prepended or appended with information from the Type or OtherTypeDescription properties. "
	"The method selected is described in the NameFormat property of this class."),
      MaxLen ( 256 )]
      string Name;

    [ Implemented(true), Description(
	"NameFormat contains the naming heuristic that is selected to ensure that the value of the Name property is unique."
	"For example, you might choose to prepend the name of the port or interface with the Type of ProtocolEndpoint "
	"(for example, IPv4) of this instance followed by an underscore."),
      MaxLen (256)]
      string NameFormat;

    [ Implemented(true), Description(
	"Indicates the current statuses of the element. Various operational statuses are defined."
	"Many of the enumeration's values are self-explanatory. However, a few are not."),
      ArrayType("Indexed"),
      MappingStrings { "MIB.IETF|IF-MIB.ifOperStatus" },
      ModelCorrespondence { "CIM_ManagedSystemElement.StatusDescriptions" },
      ValueMap { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"},
      Values { "Unknown", "Other", "OK", "Degraded", "Stressed", "Predictive Failure", "Error", "Non-Recoverable Error", "Starting", "Stopping", "Stopped", "In Service", "No Contact", "Lost Communication", "Aborted", "Dormant", "Supporting Entity in Error", "Completed", "Power Mode", "Relocating" }]
      uint16 OperatingStatus;

    [ Implemented(true), Description(
          "ProtocolIFType is an enumeration that is synchronized with the IANA ifType MIB. The ifType MIB is maintained at the URL, "
          "http://www.iana.org/assignments/ianaiftype-mib. Also, additional values defined by the DMTF are included. The property is "
          "used to categorize and classify instances of the ProtocolEndpoint class. Note that if the ProtocolIFType is set to 1 (Other), then "
          "the type information should be provided in the OtherTypeDescription string property. "),
       ValueMap { "4200", "4201" },
       Values { "NFS", "CIFS" },
       MappingStrings { "MIB.IETF|IF-MIB.ifType" },
       ModelCorrespondence { "CIM_ProtocolEndpoint.OtherTypeDescription" } ]
    uint16 ProtocolIFType;
};


More information about the openlmi-devel mailing list