Infoblox::DNS::Record::MX - DNS MX record object
An MX (mail exchanger) record maps a domain name to a mail exchanger. A mail exchanger is a server that either delivers or forwards mail. You can specify one or more mail exchangers for a zone, as well as the priority for using each mail exchanger. A standard MX record applies to a particular domain or subdomain. A wildcard MX record applies to a domain and all its subdomains.
Note that you must specify only one view for the attribute "views".
my $mx = Infoblox::DNS::Record::MX->new( exchanger => $fqdn, # Required name => $fqdn, # Required pref => $num, # Required comment => $string, # Optional / Default is empty disable => "true" | "false", # Optional / Default "false" extattrs => { $string => $extattr, ... }, # Optional / Default is undefined extensible_attributes => { $string => $string|$num, $string => [ $string|$num, ...], ... }, # Optional / Default is undefined ttl => $num | undef, # Optional / Default is undefined views => [$View1] # Optional / Default is "default" view creator => "DYNAMIC" | "STATIC", # Optional / Default is "STATIC" ddns_protected => "true" | "false", # Optional / Default is "false" ddns_principal => $string, # Optional / Default is undefined forbid_reclamation => "true" | "false", # Optional / Default is "false" );
You cannot set both extattrs and extensible_attributes attributes at the same time.
This section describes all the methods in Infoblox::Session module that you can apply to a DNS MX object.
Use this method to add an object to the Infoblox appliance. See Infoblox::Session->add() for parameters and return values.
#Construct an object my $bindmx = Infoblox::DNS::Record::MX->new( name => "bind_mx.domain.com", comment => "add mx bind_mx.domain.com", pref => 1, exchanger => "exchanger.domain.com", ); # Submit for addition my $response = $session->add( $bindmx );
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 DNS MX object:
name - Optional. A domain name in string format view - Optional. The DNS view in which the MX record is located. By default, all DNS views are searched. But if you omit this attribute and specify a zone, the appliance searches the 'default' view only. zone - Optional. A zone name in FQDN format. exchanger - Optional. The exchanger of the MX record. pref - Optional. The Preference of the MX record. creator - Optional. Record creator. ddns_principal - Optional. GSS-TSIG principal that owns the record. reclaimable - Optional. The flag that indicates whether the record is reclaimable or not. extattrs - Optional. A hash reference containing extensible attributes. extensible_attributes - Optional. A hash reference containing extensible attributes.
my @retrieved_objs = $session->get( object => "Infoblox::DNS::Record::MX", name => "bind_mx.domain.com", view => "default" );
# get all DNS MX records in the "domain.com" zone of the default view my @retrieved_objs = $session->get( object => "Infoblox::DNS::Record::MX", zone => "domain.com", view => "default" );
# get all DNS MX records with a given extensible attribute my @retrieved_objs = $session->get( object => "Infoblox::DNS::Record::MX", extensible_attributes => { 'Site' => 'Santa Clara' });
Use this method to modify an object in the Infoblox appliance. See Infoblox::Session->modify() for parameters and return values.
#Use method to modify the comment. $bindmx->comment("this is a modified comment"); # Submit modification my $response = $session->modify( $bindmx );
Use this method to remove an object from the Infoblox appliance. See Infoblox::Session->remove() for parameters and return values.
To remove a specifc object, first use get()
or search()
to retrieve the specific object, and then submit this object for removal.
# Get the object under the same name my @retrieved_objs = $session->get( name => "bind_mx.domain.com", comment => "add mx bind_mx.domain.com", pref => 1, exchanger => "exchanger.domain.com", view => "default" ); # find the desired object from retrieved list. my $desired_mx = $retrieved_objs[0]; # Submit for removal my $response = $session->remove( $desired _mx );
Use this method to search for DNS MX record objects in the Infoblox appliance. See Infoblox::Session->search() for parameters and return values.
Apply the following attributes to search for a DNS MX record object:
name - Optional. A domain name in string format (regular expression). view - Optional. The DNS view in which the MX record is located. By default, all DNS views are searched. But if you omit this attribute and specify a zone, the appliance searches the 'default' view only. zone - Optional. A zone name in FQDN format. comment - Optional. A comment in string format (regular expression). exchanger - Optional. The exchanger of the MX record (regular expression). pref - Optional. The Preference of the MX record (regular expression). creator - Optional. Record creator. ddns_principal - Optional. GSS-TSIG principal that owns the record. reclaimable - Optional. The flag that indicates whether the record is reclaimable or not. extattrs - Optional. A hash reference containing extensible attributes. extensible_attributes - Optional. A hash reference containing extensible attributes.
For more information about searching extensible attributes, see Infoblox::Grid::ExtensibleAttributeDef/Searching Extensible Attributes.
# search for all DNS MX objects that match "domain.com" in the default DNS view my @retrieved_objs = $session->search( object => "Infoblox::DNS::Record::MX", name => 'domain\.com', view => "default" );
# search for all DNS MX objects in the domain.com zone of the default DNS view my @retrieved_objs = $session->search( object => "Infoblox::DNS::Record::MX", zone => "domain.com", view => "default" );
# search all DNS MX records with a given extensible attribute 'Site' my @retrieved_objs = $session->search( object => "Infoblox::DNS::Record::MX", extensible_attributes => { 'Site' => 'Santa Clara' });
This section describes all the methods that you can use to configure and retrieve the attribute values of an MX record
Use this method to add or retrieve a descriptive comment.
Include the specified parameter to set the attribute value. Omit the parameter to retrieve the attribute value.
Enter a descriptive comment for this record in string format with a maximum of 256 bytes.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
# Getting comment my $comment = $bindmx->comment(); # Modifying comment $bindmx->comment("add mx2.domain.com");
Use this method to retrieve cloud API related information for the Infoblox::DNS::Record::MX object.
None
The method returns the attribute value.
# Get cloud_info my $cloud_info = $object->cloud_info();
Use this method to set or retrieve the record creator.
Note that changing creator from or to 'SYSTEM' value is not allowed.
Include the specified parameter to set the attribute value. Omit the parameter to retrieve the attribute value.
The valid values are 'STATIC' and 'DYNAMIC'. The default value is 'STATIC'.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
#Get creator value my $creator = $object->creator();
#Modify creator value $object->creator("DYNAMIC");
Use this method to retrieve the creation time for the record. This is a read-only attribute.
None
The valid return value is a number of seconds that have elapsed since January 1st, 1970 UTC.
#Get creation_time value my $creation_time = $object->creation_time();
Use this method to set or retrive the GSS-TSIG principal that owns this record.
Note that you cannot set ddns_principal for 'STATIC' and 'SYSTEM' records.
Include the specified parameter to set the attribute value. Omit the parameter to retrieve the attribute value.
The GSS-TSIG principal FQDN (Fully Qualified Domain Name) format. The FQDN consists of the hostname followed by the domain name (example: abc.com). A hostname can have a maximum of 256 characters.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
#Get ddns_principal value my $ddns_principal = $object->ddns_principal();
#Modify ddns_principal value $object->ddns_principal('foo.com');
Use this method to set or retrieve the flag that indicates whether DDNS updates for this record are allowed or not.
Include the specified parameter to set the attribute value. Omit the parameter to retrieve the attribute value.
Specify 'true' to protect record from DDNS updates and 'false' to allow DDNS updates for the specified record.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
#Get ddns_protected value my $ddns_protected = $object->ddns_protected();
#Modify ddns_protected value $object->ddns_protected('true');
Use this method to set or retrieve the disable flag of a DNS record.
Include the specified parameter to set the attribute value. Omit the parameter to retrieve the attribute value.
The default value for this field is false. The DNS record is enabled.
Specify "true" to set the disable flag or "false" to deactivate/unset it.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
# Getting disable my $disable = $bindmx->disable() # Modifying disable $bindmx->disable("true");
Use this method to retrieve the exchanger in punycode format. This is a read-only attribute.
None
The method returns the attribute value.
# Get attribute value my $value = $bindmx->dns_exchanger();
Use this method to retrieve the domain name in punycode format. This is a read-only attribute.
None
The method returns the attribute value.
# Get attribute value my $value = $bindmx->dns_name();
Use this method to set or retrieve the exchanger.
The name of the mail exchanger in Fully Qualified Domain Name (FQDN) format.
The attribute value can be in unicode format.
Text with the name of the mail exchanger for the DNS MX record.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails. If you did not specify a parameter, the method returns the attribute value.
# Getting exchanger my $exchanger = $bindmx->exchanger(); # Modifying exchanger $bindmx->exchanger("exchanger2.domain.com");
Use this method to set or retrieve the extensible attributes associated with a DNS MX record object.
Valid value is a hash reference containing the names of extensible attributes and their associated values ( Infoblox::Grid::Extattr objects ).
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
#Get extattrs my $ref_extattrs = $bindmx->extattrs(); #Modify extattrs $bindmx->extattrs({ 'Site' => $extattr1, 'Administrator' => $extattr2 });
Use this method to set or retrieve the extensible attributes associated with a DNS MX record.
Include the specified parameter to set the attribute value. Omit the parameter to retrieve the attribute value.
For valid values for extensible attributes, see Infoblox::Grid::ExtensibleAttributeDef/Extensible Attribute Values.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
#Get extensible attributes my $ref_extensible_attributes = $bindmx->extensible_attributes(); #Modify extensible attributes $bindmx->extensible_attributes({ 'Site' => 'Santa Clara', 'Administrator' => [ 'Peter', 'Tom' ] });
Use this method to set or retrieve the flag that indicates whether the reclamation is allowed for the record or not.
Include the specified parameter to set the attribute value. Omit the parameter to retrieve the attribute value.
Specify 'true' to forbid reclamation for the record and 'false' to allow it. The default value is 'false'.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
#Get forbid_reclamation my $forbid_reclamation = $object->forbid_reclamation(); #Modify forbid_reclamation $object->forbid_reclamation('true');
Use this method to retrieve the time when the associated record was last queried. This is a read-only attribute.
None
The method returns the attribute value. The number of seconds that have elapsed since January 1st, 1970 UTC.
#Get last_queried my $last_queried = $bindmx->last_queried();
Use this method to set or retrieve the domain name.
The name of the DNS MX object in Fully Qualified Domain Name (FQDN) format. If you want to define an MX record for a domain whose name matches the zone in which you define the MX record, leave this field empty. If you want to define an MX record for a subdomain, enter that subdomain name here. If you want to define an MX record for a domain and all its subdomains, enter an asterisk ( * ) here to create a wildcard MX record.
The attribute value can be in unicode format.
Text with the name for the DNS MX record.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
#Getting name my $name = $bindmx->name(); # Modifying name $bindmx->name("mx2.domain.com");
Use this method to set or retrieve the Preference value.
The preference value of the DNS MX object. Preference value of MX record for the zone range from 0 to 65535. Low values are more preferred.
Enter an unsigned integer between 0-65535. The priority determines the order in which a client attempts to contact the target mail exchanger. The highest priority is 0 and is queried first.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
# Getting pref my $pref = $bindmx->pref(); # Modifying pref $bindmx->pref(3);
Use this method to retrieve the flag that indicates whether the record is reclaimable or not.
None
The method returns the attribute value.
#Get reclaimable my $reclaimable = $object->reclaimable();
Use this method to configure or retrieve the Time to Live (TTL) value.
Include the specified parameter to set the attribute value. Omit the parameter to retrieve the attribute value.
The default value is undefined which indicates that the record inherits the TTL value of the zone.
Specify a TTL value to override the TTL value at the zone level.
A 32-bit integer (range from 0 to 4294967295) that represents the duration in seconds that the record is cached. Zero indicates that the record should not be cached.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
#Get ttl my $ttl = $bindmx->ttl(); #Modify ttl $bindmx->ttl(1800); #Un-override ttl $bindmx->ttl(undef);
Use this method to specify or retrieve the view of the MX record.
Include the specified parameter to set the attribute value. Omit the parameter to retrieve the attribute value.
The default value is the 'default' view, which means the MX record is located under the default view.
Array reference of defined Infoblox::DNS::View objects.
Note that the array size must be 1.
If you specified a parameter, the method returns true when the modification succeeds, and returns false when the operation fails.
If you did not specify a parameter, the method returns the attribute value.
#Get views my $ref_views = $bindmx->views(); #Modify views, list of Infoblox::DNS::View objects $bindmx->views([$view1]);
Use this method to retrieve the zone name of a DNS MX record. This method is read-only and cannot be set.
None
Returns the attribute value.
# Get zone my $zone = $bindmx->zone();
The following sample code demonstrates the different functions that can be applied to an object, such as add, search, modify, and remove. This sample also includes error handling for the operations.
#Preparation prior to a DNS MX record 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", username => "admin", password => "infoblox" ); unless ($session) { die("Construct session failed: ", Infoblox::status_code() . ":" . Infoblox::status_detail()); } print "Session created successfully\n";
#Create the zone prior to MX record insertion my $zone = Infoblox::DNS::Zone->new(name => "domain.com"); unless ($zone) { die("Construct zone failed: ", Infoblox::status_code() . ":" . Infoblox::status_detail()); } print "Zone object created successfully\n";
#Verify if the zone exists my $object = $session->get(object => "Infoblox::DNS::Zone", name => "domain.com"); unless ($object) { print "Zone does not exist on server, safe to add the zone\n"; $session->add($zone) or die("Add zone failed: ", $session->status_code() . ":" . $session->status_detail()); } print "Zone added successfully\n";
#Create a DNS MX record
#Construct a DNS MX object my $bindmx = Infoblox::DNS::Record::MX->new( name => "bind_mx.domain.com", comment => "add mx bind_mx.domain.com", pref => 1, exchanger => "exchanger.domain.com", );
unless ($bindmx) { die("Construct DNS record MX failed: ", Infoblox::status_code() . ":" . Infoblox::status_detail()); } print "DNS MX object created successfully\n"; #Add the DNS MX record object to Infoblox appliance through a session $session->add($bindmx) or die("Add record MX failed: ", $session->status_code() . ":" . $session->status_detail()); print "DNS MX object added to server successfully\n";
#Search for a specific DNS MX record
#Search all MX records that match "domain.com" my @retrieved_objs = $session->search( object => "Infoblox::DNS::Record::MX", name => 'domain\.com' ); my $object = $retrieved_objs[0]; unless ($object) { die("Search record MX failed: ", $session->status_code() . ":" . $session->status_detail()); } print "Search DNS MX object found at least 1 matching entry\n";
#Search all MX records that start with "bind" and end with "domain.com" my @retrieved_objs = $session->search( object => "Infoblox::DNS::Record::MX", name => '^bind.*\.domain\.com\$' ); my $object = $retrieved_objs[0]; unless ($object) { die("Search record MX failed: ", $session->status_code() . ":" . $session->status_detail()); } print "Search DNS MX object using regexp found at least 1 matching entry\n";
#Get and modify a DNS MX record
#Get MX record through the session my @retrieved_objs = $session->get( object => "Infoblox::DNS::Record::MX", name => "bind_mx.domain.com", pref => 1, exchanger => "exchanger.domain.com", );
my $object = $retrieved_objs[0]; unless ($object) { die("Get record MX failed: ", $session->status_code() . ":" . $session->status_detail()); } print "Get DNS MX object found at least 1 matching entry\n";
#Modify one of the attributes of the specified MX record $object->exchanger("exc.domain.com");
#Apply the changes $session->modify($object) or die("Modify record MX failed: ", $session->status_code() . ":" . $session->status_detail()); print "DNS MX object modified successfully \n";
#Remove a DNS MX record
#Get MX record through the session my @retrieved_objs = $session->get( object => "Infoblox::DNS::Record::MX", name => "bind_mx.domain.com" ); my $object = $retrieved_objs[0]; unless ($object) { die("Get record MX failed: ", $session->status_code() . ":" . $session->status_detail()); } print "Get DNS MX object found at least 1 matching entry\n";
#Submit the object for removal $session->remove($object) or die("Remove record MX failed: ", $session->status_code() . ":" . $session->status_detail()); print "DNS MX object removed successfully \n";
####PROGRAM ENDS####
Infoblox Inc. http://www.infoblox.com/
Infoblox::DNS::View, Infoblox::DNS::Zone, Infoblox::Session, Infoblox::Session->get(), Infoblox::Session->search(), Infoblox::Session->add(), Infoblox::Session->remove(), Infoblox::Session->modify()
Copyright (c) 2017 Infoblox Inc.