Infoblox::DHCP::OptionSpace - DHCP OptionSpace object.
An Option Space defines a namespace in which vendor options can be defined. To define a specific vendor option space, add an option space to DHCP.
my $option_space = Infoblox::DHCP::OptionSpace->new( name => $string, #Required comment => $string, #Optional, default is undefined );
This section describes all the methods in Infoblox::Session module that can be applied to a DHCP OptionSpace object.
Use this method to add a DHCP OptionSpace object to the Infoblox appliance. See Infoblox::Session->add() for parameters and return values.
#Construct a DHCP OptionSpace object my $option_space = Infoblox::DHCP::OptionSpace->new( name => "infospace", comment => "some comment" ); #Submit for addition my $response = $session->add($option_space)
Use this method to retrieve all the matching objects from the Infoblox appliance. See Infoblox::Session->get() for parameters and return values.
Apply the following attributes to get a specific DHCP OptionSpace object:
name - Required. Option space name in string format. comment - Optional. Option space comment.
#Get DHCP OptionSpace object through the session my @retrieved_objs = $session->get( object => "Infoblox::DHCP::OptionSpace", name => "infospace", );
Use this method to modify a DHCP OptionSpace object in the Infoblox appliance. See Infoblox::Session->modify() for parameters and return values.
#Use method to modify the name. $option_space->name("info_space"); #Submit modification my $response = $session->modify( $option_space );
Use this method to remove a DHCP OptionSpace object from the Infoblox appliance. See Infoblox::Session->remove() for parameters and return values.
To remove a specific object, first use get()
to retrieve the specific DHCP OptionSpace object, and then submit this object for removal.
#Get DHCP OptionSpace object through the session my @retrieved_objs = $session->get( object => "Infoblox::DHCP::OptionSpace", name => "info_space", ); #Find the desired object from the retrieved list. my $desired_option_space = $retrieved_objs[0]; #Submit for removal my $response = $session->remove( $desired_option_space );
Use this method to retrieve all the matching objects from the Infoblox appliance. See Infoblox::Session->search() for parameters and return values.
Apply the following attributes to get a specific DHCP OptionSpace object:
name - Optional. Option space name in string format (regular expression). comment - Optional. Option space comment (regular expression).
#Get DHCP OptionSpace object through the session my @retrieved_objs = $session->search( object => "Infoblox::DHCP::OptionSpace", comment => ".*comm.*" );
This section describes all the methods that can used to set and retrieve the attribute values of a DHCP OptionSpace object.
Use this method to set or retrieve name of option space object.
Include the specified parameter to set the attribute value. Omit the parameter to retrieve the attribute value.
Desired name in string format with a maximum of 256 bytes.
If parameter is specified, the method returns true when the modification succeeds, and returns false when the operation fails.
If parameter is not specified, the method returns the attribute value.
#Get name my $name = $option_space->name(); #Modify name $option_space->name("info_space");
Use this method to set or retrieve a comment about the option space object.
Include the specified parameter to set the attribute value. Omit the parameter to retrieve the attribute value.
Desired comment in string format with a maximum of 256 bytes.
If the parameter is specified, the method returns true when the modification succeeds, and returns false when the operation fails.
If the parameter is not specified, the method returns the attribute value.
#Get comment my $comment = $option_space->comment(); #Modify comment $option_space->comment("my comment");
Use this method to retrieve the type of this option space.
None.
The method returns the attribute value, which can be either 'predefined_dhcp' or 'vendor_space'.
#Get space_type my $space_type = $option_space->space_type();
The following sample code demonstrates the different functions that can be applied to an OptionSpace object, such as get, add, modify and remove. In addition, the sample includes error handling for the operations.
#Preparation prior to a DHCP OptionSpace object insertion
#PROGRAM STARTS: Include all the modules that will be used use strict; use Infoblox;
#Create a session to the Infoblox appliance
my $session = Infoblox::Session->new( master => "192.168.1.2", #appliance host ip username => "admin", #appliance user login password => "infoblox" #appliance password );
unless ($session) { die("Construct session failed: ", Infoblox::status_code() . ":" . Infoblox::status_detail()); } print "Session created successfully\n";
#Create an OptionSpace object
my $option_space = Infoblox::DHCP::OptionSpace->new ( "name" => "infospace" );
unless($option_space) { die("Construct option_space filter failed: ", Infoblox::status_code() . ":" . Infoblox::status_detail()); } print "OptionSpace object created successfully\n";
#Verify if the DHCP OptionSpace exists in the Infoblox appliance my $object = $session->get( object => "Infoblox::DHCP::OptionSpace", name => "infospace" ); unless ($object) { print "option space does not exist on server, safe to add the option_space\n"; $session->add($option_space) or die("Add option space failed: ", $session->status_code() . ":" . $session->status_detail()); } print "DHCP OptionSpace added successfully\n";
#Get and Modify an OptionSpace object
#Get OptionSpace object through the session my @retrieved_objs = $session->get( object => "Infoblox::DHCP::OptionSpace", name => "infospace" ); my $object = $retrieved_objs[0]; unless ($object) { die("Get OptionSpace object failed: ", $session->status_code() . ":" . $session->status_detail()); } print "Get OptionSpace object found at least 1 matching entry\n";
#Modify name of the obtained OptionSpace object $object->name("info_space");
#Apply the changes $session->modify($object) or die("Modify OptionSpace object failed: ", $session->status_code() . ":" . $session->status_detail()); print "OptionSpace object modified successfully \n";
#Remove an OptionSpace object
#Get OptionSpace object through the session my @retrieved_objs = $session->get( object => "Infoblox::DHCP::OptionSpace", name => "info_space" ); my $object = $retrieved_objs[0]; unless ($object) { die("Get OptionSpace object failed: ", $session->status_code() . ":" . $session->status_detail()); } print "Get OptionSpace object found at least 1 matching entry\n";
#Submit the object for removal $session->remove($object) or die("Remove OptionSpace object failed: ", $session->status_code() . ":" . $session->status_detail()); print "OptionSpace object removed successfully \n";
####PROGRAM ENDS####
Infoblox Inc. http://www.infoblox.com/
Infoblox::DHCP::OptionDefinition,Infoblox::Session->get(), Infoblox::Session->modify(), Infoblox::Session->remove(), Infoblox::Session
Copyright (c) 2017 Infoblox Inc.