Start a Conversation

Unsolved

This post is more than 5 years old

1180

May 24th, 2013 14:00

Create a Object in a Ionix Server Using a Perl Script

Hi to all, I have some questions about Perl API, because I have some problems at the moment of try to create an Object in a Ionix 9.1 Server using a Perl Scrip.

I have the next Perl Script, this script created a Object in Ionix Server 9.1 and after that update some attributes.

use InCharge::session;

my $session = InCharge::session->new(                                                           broker=>$brokerPort,                                                       domain=>$domainName,                                                        username=>$user, password=>$password);     

                                                      

my $ipObjectName = "IP_Object_Test01";

my $attributeName = "DisplayName";

my $attributeValue = "my ip object display name";

my $attributeName01 = "Address";

my $attributeValue01 = "192.168.1.2";

my $className ="IP";

                                                                          

$session->transactionStart(0);

CreateObject($className, $ipObjectName);

$session->transactionCommit();

Set_Put_Property($className, $ipObjectName, $attributeName01, $attributeValue01);

Set_Put_Property($className, $ipObjectName, $attributeName, $attributeValue);

$session->detach( );

#Subroutine Create new Object

sub CreateObject

{      print "\nCreate Object Called...";

       my($class, $objectName) = @_;

       my $object = $session->create( $class, $objectName);

       print "\nThe Object: $objectName was created successfully";

}

#Sub routine put/set a Property

sub Set_Put_Property()

{      my($className, $instanceName, $propertyName, $propertyValue)= @_;

      

       $access = $session->getPropAccess($className,$propertyName);

       $decrip = $session->getPropDescription($className,$propertyName);

       $type = $session->getPropType($className,$propertyName);

       $isRequired = $session->getPropIsRequired($className,$propertyName);

       $isReadOnly = $session->getPropIsReadonly($className,$propertyName);

       print "\n-->Property to Update.\nName:".$propertyName."\nAccess:".$access."\nType:".$type."\nIsRequired:".$isRequired."\nIsReadOnly:".$isReadOnly."\nDescription:".$decrip."\n\n";

       if(!$isReadOnly)

       {      my $object = $session->object( $className, $instanceName );

              $object->put( $propertyName, $propertyValue );

              print "\n".$propertyName." property is update successfully."        

       }

       else

       {             print "\n".$propertyName." property is read only."           

       }

}

  1. The problem is when I try to update some attributes apparently not Read only the script fail and say me that this attribute is read only L

This is the Console output of this script:

Create Object Called...

The Object: IP_Object_Test01 was created successfully

-->Property to Update.

Name:Address

Access:1

Type:13

IsRequired:0

IsReadOnly:0

Description:The IP address.

Address property is update successfully.

-->Property to Update.

Name:DisplayName

Access:2

Type:13

IsRequired:0

IsReadOnly:0

Description:The string shown in the GUI when this object's name is displayed.

[15] MR-E-WRITE_TO_READONLY-Tried to write to a read-only attribute??? at c:\InCharge\CONSOLE\smarts\perl\5.8.8/InCharge/remote.pm line 300. 

In this console output I first created a Object in a IP class successfully after that I start update some attributes, the first attribute is the Address that updated successfully (in yellow) after that I try to update the DisplayName attribute (in red), but this operation is not completed show me a read only message error(in green).

Anybody could you please help me with this problem, I try with other classes and I get the same problem.

What is the correct Validation in order to determine if the attribute is writable/updateable?

  1. Thanks.

6 Posts

August 23rd, 2013 09:00

Anybody may help me with this?

5 Practitioner

 • 

274.2K Posts

August 26th, 2013 22:00

Hello,

I would request you to please get in touch with Professional services for this through your Account manager for script related questions and queries.

Thanks

8 Posts

November 6th, 2013 01:00

Just another note: Some objects that DO seem to be fine being deleted with "delete" and created with "create" is ICS_User objects on the SAM.... Often it is useful to find an ASL that create / delete / import the type of objects that you want to create and check there what the safe method is... (for deleting most things, the remove() method is often necessary to properly delete related objects)

8 Posts

November 6th, 2013 01:00

I had a bit of luck, but couldn't get the objects to poll... (Haven't tried very hard either...) (It would have its uses to do a single-discovery topology split among other things...)

Have a look through some of the ASL scripts to see how discovery creates objects....

The $session->create() is probably not what you want to use... There are "factory" classes and objects that are used to create objects... (ICIM_ObjectFactory probably). (get a listing with dmctl -s MY-AM getC|grep -i factory)

Try doing this to find examples of ASL scripts creating objects using it: (Assuming a *nix install to /opt/InCharge)

$ find /opt/InCharge -name '*.asl' -exec grep -l ObjectFactory {} +

(Just about everything done in ASL is possible with the Perl API, the syntax just differs a bit from the ASL)

Once the object is created, most changes should probably be done using the methods that are available.

To get the methods for a class use "dmctl -s MY-AM getO UnitaryComputerSystem" (as example, change class as needed...)

No Events found!

Top