Forum Discussion

Brian_Herr_1028's avatar
Brian_Herr_1028
Icon for Nimbostratus rankNimbostratus
Dec 07, 2004

Perl: How to get the values of enumerated types

It seems that any enumerated value queried using SOAP::Lite and iControlTypeCast.pm (from the SDK) returns the value of 1.

 

 

I'm not able to get any value other than 1 from LocalLB/PoolMember functions like object_status->enabled_status or object_status->availability_status.

 

 

Here is a snippet:

 

 

$soap = SOAP::Lite

 

->uri('urn:iControl:LocalLB/PoolMember')

 

->proxy(url);

 

$soapResponse = $soap->get_object_status (

 

SOAP::Data->name(pool_names => [@pool])

 

);

 

&checkResponse($soapResponse);

 

 

my $member_object_status = $soapResponse->result;

 

 

for (my $index = 0; $index < @{$member_object_status}; $index++) {

 

my $member_top = $member_object_status->[$index];

 

print $pool[$index] . ":\n";

 

foreach my $member_bottom (@{$member_top}) {

 

print "\t" . $member_bottom->{member}->{address} . ":" .

 

$member_bottom->{member}->{port} . "\t" .

 

$member_bottom->{object_status}->{enabled_status} . "\n";

 

}

 

}

 

 

This expression always equals 1 regardless of the actual status:

 

$member_bottom->{object_status}->{enabled_status}

 

 

Any ideas?
  • Loc_Pham_101863's avatar
    Loc_Pham_101863
    Historic F5 Account
    If the object is actually enabled, then the "enabled_status" will be 1. You should do a cross check via other iControl call or CLI/GUI to see if the object is really enabled or not.

     

    However, the object may be enabled, but its real status might be different. Therefore, you'll have to also look at the "availability_status" to really know if the object is actually available for service or not. The "availability_status" will return some color status to indicate the various conditions, as described by LocalLB::AvailabilityStatus in the SDK. If this availability status indicates any color status other than AVAILABILITY_STATUS_GREEN, you may also check the "status_description" field for the reason string.

     

    Loc
  • Here's the prototype for the LocalLB::PoolMember::get_object_status

     

    method.

     

     

    struct IPPortDefinition { 
       String address; 
       long port 
     }; 
      
     struct ObjectStatus { 
       AvailabilityStatus availability_status; 
       EnabledStatus enabled_status; 
       String status_description; 
     }; 
      
     struct MemberObjectStatus { 
       IPPortDefinition member; 
       ObjectStatus object_status; 
     }; 
      
     MemberObjectStatus[][] get_object_status( 
         in String[] pool_names 
     );

     

     

    The method takes as input an array of pool names and returns a two dimensional array. This is an array of pool member object status for each pool passed in. Thus you need to peel off both layers of this array to get at the data.

     

     

    Here's some code that illustrates the usage (feel free to change the way the arrays are accessed, etc). It takes as input an array of pool names and prints out the object status of the members in those pools.

     

     

    ---------------------------------------------------------------- 
      getMemberStatus 
     ---------------------------------------------------------------- 
     sub getMemberStatus() 
     { 
       my @pool_list = @_; 
      
       $soapResponse = $PoolMember->get_object_status 
       ( 
         SOAP::Data->name(pool_names => [@pool_list]) 
       ); 
       &checkResponse($soapResponse); 
      
       @MemberObjectStatusAofA = @{$soapResponse->result}; 
      
        Loop over pools 
       for $i ( 0 .. $MemberObjectStatusAofA ) 
       { 
         print "Member status for pool @pool_list[$i]\n"; 
      
          Loop over pool members within the pool 
         $MemberObjectStatusArray = $MemberObjectStatusAofA[$i]; 
         for $j ( 0 .. ${$MemberObjectStatusArray} ) 
         { 
           $MemberObjectStatus = $MemberObjectStatusAofA[$i][$j]; 
      
           $member = $MemberObjectStatus->{"member"}; 
           $address = $member->{"address"}; 
           $port = $member->{"port"}; 
      
           $object_status = $MemberObjectStatus->{"object_status"}; 
           $availability_status = $object_status->{"availability_status"}; 
           $enabled_status = $object_status->{"enabled_status"}; 
           $status_description = $object_status->{"status_description"}; 
      
           print "\tMember: $address:$port\n"; 
           print "\t\tavailability: $availability_status\n"; 
           print "\t\tenabled: $enabled_status\n"; 
           print "\t\tdescription: $status_description\n"; 
         } 
       } 
     }

     

     

    If you need a good primer for multi-dimensional arrays, check this document out.

     

     

    BTW, all enums in 9.0 are now by string value which should make them much easier to work with.

     

     

    -Joe