The general approach to writing a script that uses the Remote Perl API is to follow these basic steps:

  1. Open a session.

    Initialize a session, and obtain a reference to it, by using either InCharge::session->init() or InCharge::session->new(), as appropriate.

      use InCharge::session;
      $session = InCharge::session->init( );
  2. Work with the domain.

    Call the primitives required, by using the session reference obtained in step 1, and manipulate the data. For example,

      foreach $class ( sort $session->getClasses() ) {
       foreach $inst (
        sort $session->getInstances($class))
        print $class . "::" . $inst . "\n”;
  3. Close the session.

    Once the script has finished working with the domain, the session should be closed.

      $session->detach( );

    Where access to the operations or properties of domain objects (such as routers and interfaces) is required, you use the features of the InCharge::object module. The script obtains an InCharge::object reference, and then uses it to access the required information. For example.

  4. Establish a session.

      use InCharge::session;
      $session = InCharge::session->init();
  5. Obtain an object reference.

    Before an object in the domain can be accessed, the script needs to obtain an InCharge::object reference to the object of interest, by using the object() method of the session handle.

      $obj = $session->object( "Router::gw1" );
  6. Manipulate the object.

    The reference obtained in step 2 can now be used to access the properties and operations of the object. Properties can be accessed, by using Perl's hashing syntax and operations can be invoked, by using Perl's object-oriented syntax conventions.

      $type = $obj->{Type};
      $obj->{Vendor} = "Cisco";
      $fan1 = $obj->findFan( 1 );
  7. Close the session.

    As before, the session should be closed when no longer required.

      $session->detach( );