Forum Discussion

Puli's avatar
Puli
Icon for Nimbostratus rankNimbostratus
Feb 17, 2012

how to modify perl iControl script with V10.2 classes

I have been using the existing perl iControl script Query/add/delete string classes members, located here.

 

http://devcentral.f5.com/wiki/icontrol.perlqueryStringClass.ashx.

 

 

We recently changed the class structure to conform with version 10.2

 

The structure is now a key:=value pair.

 

name1:=value1

 

 

Can anybody share code in perl if they are able to successfully query/add/delete class entries in the new class structure in 10.2 ?

 

 

Appreciate if you can send me some sample code.

 

 

thanks,

 

Puli.

 

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus
    I'm on train at moment but inhave this on my laptop (no room on uk trains for this). I will post RSN...
  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus
    To Modify an existing entry...

    
    sub updateClass {
      my($classAPI, $className, %files)=@_;
    
      print "updateClass:\n";
      my @members=();
      foreach $filename (keys %files) {
        my $encode64=$files{$filename}->{BASE64};
    
        print "updateClass: pushing [$encode64]\n";
    
        push(@members, $encode64);
      }
    
      my $stringInfo = {name => $className, members => [@members]};
    
      $soapResponse=$classAPI->modify_string_class(SOAP::Data->name(classes => [$stringInfo]));
    
      my($status,$text)=&checkResponse($soapResponse);
      if(($status!=1)||($text ne "OK")) {
        print "updateClass: status $status error [$text] from modify_string_class()\n";
        exit(-1);
      }
      print "updateClass: status $status success [$text] from modify_string_class()\n";
    }
    

    To add a completely new entry

    
    sub addClassEntry {
      my($classAPI, $className, $classMembers, $classValues)=@_;
    
      print "addClassEntry: ($className) ($classMembers) ($classValues)\n";
    
      my $class_members = {name => $className, members => [$classMembers]};
    
      print "addClassEntry: calling class->set_string_class_member_data_value()\n";
    
      $soapResponse=$classAPI->add_string_class_member(SOAP::Data->name(class_members => [$class_members]));
      $soapResponse=$classAPI->set_string_class_member_data_value(SOAP::Data->name(class_members => [$class_members]), SOAP::Data->name(values => [[$classValues]]));
    
      my($status,$text)=&checkResponse($soapResponse);
    
      print "addClassEntry: status[$status] text [$text]\n";
      if(($status!=1)||($text ne "OK")) {
        print "addClassEntry: status $status error [$text] from add_string_class_member()\n";
        exit(-1);
      }
      print "addClassEntry: status $status success [$text] from add_string_class_member()\n";
    
    }
    

    To remove an entry

    
    sub removeClassEntry {
      my($classAPI, $className, $classEntry)=@_;
      my @stringInfoList=();
    
      print "removeClassEntry:\n";
    
      my $stringInfo = {name => $className, members => [$classEntry]};
      push(@stringInfoList, $stringInfo);
    
      print "removeClassEntry: calling class->delete_string_class_member()\n";
    
      $soapResponse=$classAPI->delete_string_class_member(SOAP::Data->name(class_members => [$stringInfo]));
    
      my($status,$text)=&checkResponse($soapResponse);
      if(($status!=1)||($text ne "OK")) {
        print "removeClassEntry: status $status error [$text] from delete_string_class_member()\n";
        return;
      }
      print "removeClassEntry: status $status success [$text] from delete_string_class_member()\n";
    
    }
    
    

    To iterate over a class and remove all entries (Using the remove funtion above)

    
    ----------------------------------------------------------------------------
     sub removeEntries
    ----------------------------------------------------------------------------
    sub removeEntries {
      my ($classAPI, $className) = @_;
    
      my $soapResponse = $classAPI->get_string_class(SOAP::Data->name(class_names => [$className]));
      &checkResponse($soapResponse);
      @StringClassList = @{$soapResponse->result};
      foreach $StringClass (@StringClassList) {
        $name = $StringClass->{"name"};
        print "removeEntries($className): Name : $name\n";
        @members = @{$StringClass->{"members"}};
        foreach $member (@members) {
    
          print "removeEntries($className):      : $member\n";
    
          print "removeEntries: Removing entry\n";
          removeClassEntry($classAPI, $className, $member);
        }
      }
      print "removeEntries($className):\n";
    
    
    }
    
    

    H