Infoblox::Grid::CSVImportStatus - CSV import status object


NAME

Infoblox::Grid::CSVImportStatus - CSV import status object


DESCRIPTION

This object is used to represent the status of the current CSV import task. All methods are read-only.


MODULE METHODS

The following functions can be applied to a Grid::CSVImportStatus object.

Infoblox::Session->get( )

Use this method to retrieve matching objects from the Infoblox appliance. See Infoblox::Session->get() for parameters and return values.

Key Reference
 Apply the following attributes to get a specific CSV import status object
  object    - Required. It must be set to "Infoblox::Grid::CSVImportStatus".
  import_id - Optional. ID of the import task that the status object is describing. If not specified, 
              the status of the first import task is returned.
Example
 my $import_id = $session->import_data(
                                       type => 'csv',
                                       path => "/tmp/zone.csv",
                                       separator   => 'semicolon',
                                      );
 unless($import_id){
     die("Import failed: ",
         Infoblox::status_code(). ":" .Infoblox::status_detail());
 }
 my @retrieved_objs = $session->get(
     object    => "Infoblox::Grid::CSVImportStatus",
     import_id => $import_id,
     );


METHODS

This section describes all the methods that you can use to retrieve the status of a CSV import operation.

admin( )

Use this method to retrieve the name of the administrator that started the import.

Returns

The method returns the attribute value.

Example
 #Get admin
 my $admin = $service_status->admin();

end_time( )

Use this method to retrieve the time the CSV import ended.

Returns

The method returns the attribute value.

Example
 #Get end_time
 my $end_time = $service_status->end_time();

file_name( )

Use this method to retrieve the name of the file used for the CSV import.

Returns

The method returns the attribute value.

Example
 #Get file_name
 my $file_name = $service_status->file_name();

import_id( )

Use this method to retrieve the ID of the import task that the status object is describing.

Returns

The method returns the attribute value.

Example
 #Get import_id
 my $import_id = $service_status->import_id();

lines_failed( )

Use this method to retrieve the number of lines that had failures in the CSV file used for the current CSV import.

Returns

The method returns the attribute value.

Example
 #Get lines_failed
 my $lines_failed = $service_status->lines_failed();

lines_processed( )

Use this method to retrieve the number of lines processed in the CSV file used for the current CSV import.

Returns

The method returns the attribute value.

Example
 #Get lines_processed
 my $lines_processed = $service_status->lines_processed();

lines_total( )

Use this method to retrieve the total number of lines read from the CSV file during the current CSV import.

Returns

The method returns the attribute value.

Example
 #Get lines_total
 my $lines_total = $service_status->lines_total();

lines_warning( )

Use this method to retrieve the number of lines that had warnings in the CSV file used for the current CSV import.

Returns

The method returns the attribute value.

Example
 #Get lines_warning
 my $lines_warning = $service_status->lines_warning();

start_time( )

Use this method to retrieve the time the CSV import started.

Returns

The method returns the attribute value.

Example
 #Get start_time
 my $start_time = $service_status->start_time();

status( )

Use this method to retrieve the status of the current CSV import. The returned status is one of the following: 'Uploaded', 'Pending', 'Running', 'Failed', 'Stopped' or 'Completed'.

Returns

The method returns the attribute value.

Example
 #Get status
 my $status = $service_status->status();


SAMPLE CODE

The following sample code demonstrates how to export / import data by using CSV files.

 #PROGRAM STARTS: Include all the modules that will be used
 use strict;
 use Infoblox;
 #Create a session to the Infoblox appliance
 my $host_ip =  "192.168.1.2";
 my $session = Infoblox::Session->new(
                                      master   => $host_ip,
                                      username => "admin",
                                      password => "infoblox"
                                     );
 unless($session){
     die("Constructor for session failed: ",
         Infoblox::status_code(). ":" . Infoblox::status_detail());
 }
 print "Session created successfully.\n";
 #Create a DNS zone
 my $memberns1 = Infoblox::DNS::Member->new(
                                            name     => "infoblox.localdomain",
                                            ipv4addr => $host_ip,
                                            lead     => "false",
                                            stealth  => "false"
                                           );
 #Add the zone
 my $firstzone = Infoblox::DNS::Zone->new(
                                          name        => "test.com",
                                          email       => "admin\@infoblox.com",
                                          comment     => "add a zone test.com",
                                          primary     => $memberns1,
                                         );
 unless($firstzone){
     die("Construct test.com zone object failed: ",
         Infoblox::status_code(). ":" .Infoblox::status_detail());
 }
 print "test.com zone object created successfully.\n";
 $session->add($firstzone)
   or die("Add zone for test.com failed: ",
          $session->status_code(). ":" .$session->status_detail());
 print"Zone test.com added successfully.\n";
 #Export the newly created zone
 $session->export_data(
                       type        => 'csv',
                       path        => '/tmp/zone.csv',
                       object_type => 'Infoblox::DNS::Zone',
                       separator   => 'semicolon',
                       # search parameters
                       name        => '.*test.com',
                                             )
                          or die("Export zone for test.com failed: ",
                                 $session->status_code(). ":" .$session->status_detail());
 # Wait for the export to complete
 sleep(5);
 print "The zone was exported\n";
 # Remove the zone from the database
 $session->remove($firstzone)
   or die("Remove zone for test.com failed: ",
          $session->status_code(). ":" .$session->status_detail());
 print "The zone was removed\n";
 # Import the zone by using the CSV file that was exported
 my $import_id = $session->import_data(
                                       type => 'csv',
                                       path => "/tmp/zone.csv",
                                       separator   => 'semicolon',
                                      );
 unless($import_id){
     die("Import failed: ",
         Infoblox::status_code(). ":" .Infoblox::status_detail());
 }
 # Wait for the import to complete
 sleep(5);
 my $status = $session->get(
                            object  => 'Infoblox::Grid::CSVImportStatus',
                           );
 unless($status){
     die("Failed to fetch the import status: ",
         Infoblox::status_code(). ":" .Infoblox::status_detail());
 }
 print "The zone was re-imported\n";
 # The code should be cycling to sleep, fetch and wait until the import is finished.
 unless($status->status() eq 'Completed'){
     die("The import took too long to complete: " . $status->status());
 }
 unless($status->lines_failed() == 0){
     die("There were some import failures: " . $status->lines_failed());
 }
 print "The zone re-import was successful\n";
 # The zone was re-imported. If we import the file again without merging,
 # an error occurs.
 $import_id = $session->import_data(
                                    type => 'csv',
                                    path => "/tmp/zone.csv",
                                    separator   => 'semicolon',
                                   );
 unless($import_id){
     die("Import failed: ",
         Infoblox::status_code(). ":" .Infoblox::status_detail());
 }
 # Wait for the import to complete
 sleep(5);
 print "The zone re-re-import was completed\n";
 my $status = $session->get(
                            object  => 'Infoblox::Grid::CSVImportStatus',
                           );
 unless($status){
     die("Failed to fetch the import status: ",
         Infoblox::status_code(). ":" .Infoblox::status_detail());
 }
 # The code should be cycling to sleep, fetch and wait until the import is finished.
 unless($status->status() eq 'Completed'){
     die("The import took too long to complete: " . $status->status());
 }
 if($status->lines_failed() == 0){
     die("There were no import failures: " . $status->lines_failed());
 }
 print "The zone re-re-import correctly failed\n";
 # Review the  failure
 $session->export_data(
                       type        => 'csv_error_log',
                       path        => '/tmp/error_log.txt',
                       import_id   => $import_id,
                      )
   or die("Export error log failed: ",
          $session->status_code(). ":" .$session->status_detail());
 # The failure is in this file
 print "Error log for the failed import\n-------\n";
 print `cat /tmp/error_log.txt`;
 #Remove the zone
 $session->remove(
                  object => "Infoblox::DNS::Zone",
                  name   => "test.com",
                 )
   or die("Remove zone test.com failed: ",
          $session->status_code(). ":" .$session->status_detail());
 print "The zone was removed\n";
 ####PROGRAM ENDS####


AUTHOR

Infoblox Inc. http://www.infoblox.com/


SEE ALSO

Infoblox::Session,Infoblox::Session->get()


COPYRIGHT

Copyright (c) 2017 Infoblox Inc.