Discover Device (C# code sample)

Problem this snippet solves:

This C# client code sample uses Enterprise Manager's device inventory to discover a list of devices managed by the referenced Enterprise Manager.

Code :

using System;

using iControl;


/**
 * A class for testing the Management::EM::discover_devices iControl interface.
 */

class ManagementEMDiscoverDevices {

    private static int MIN_ARGS = 3;
    private static int NUM_DEVICE_ARGS = 3;
    private static string USAGE =
"ManagementEMDiscoverDevices    " +
"[  ] ...";
    private static int EM_PORT = 443;


    /**
     * The main method.
     *
     * @param args command line arguments
     */

    static void Main(string[] args)
    {

if ((args.Length < MIN_ARGS) ||
        (((args.Length - MIN_ARGS) % NUM_DEVICE_ARGS) != 0)) {
    Console.WriteLine("Usage: " + USAGE);
    Environment.Exit(1);
}

string emAddress = args[0];
string emUsername = args[1];
string emPassword = args[2];

int numDevices = (args.Length - MIN_ARGS) / NUM_DEVICE_ARGS;

        string[] deviceAddresses = new string[numDevices];
        string[] deviceUsernames = new string[numDevices];
        string[] devicePasswords = new string[numDevices];


        for (int i = 0; i < deviceAddresses.Length; i++) {
            int index = MIN_ARGS + (i * NUM_DEVICE_ARGS);

            deviceAddresses[i] = args[index];
            deviceUsernames[i] = args[index + 1];
            devicePasswords[i] = args[index + 2];
        }

        string taskId = null;

try {
    Interfaces ic = new Interfaces();
    ic.initialize(emAddress, EM_PORT, emUsername, emPassword);

        taskId = ic.ManagementEM.discover_devices(deviceAddresses,
                                                  deviceUsernames,
                                                  devicePasswords);
}
catch (Exception e) {
    Console.WriteLine("Failed to discover devices: " + e.Message);
    Environment.Exit(1);
}

Console.WriteLine("Discovery task started with task ID: " + taskId);

    } // Main

} // class ManagementEMDiscoverDevices
Published Mar 07, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment