# # Copyright (c) 2015 NetApp, Inc., All Rights Reserved. # Any other use, modification, or distribution is prohibited # without prior written consent from NetApp, Inc. # ## @pod here ## @author dl-nacl-dev@netapp.com ## @summary The Xgen Service package NACL::Service::Xgen; use strict; use warnings; use NACL::Service::Xgen::Util qw(dumper); use NATE::Exceptions::Argument qw(:try); use parent qw(NACL::Service); use constant public_api => ( build_config => {worker_type => 0} ); sub build_config { my ($self, %args) = @_; $self->log()->enter(); my $config_module = delete($args{config_module}) // NATE::Exceptions::Argument->throw("Missing required argument 'config_module'"); my $config_path = $config_module; my $display_config = delete($args{display_config}) // 0; # see if we are being asked to use a cached config. my $use_cached_config = delete($args{use_cached_config}) // 0; if ($use_cached_config and $self->{cached_configs}) { if ($self->{cached_configs}->{$config_module}) { return $self->{cached_configs}->{$config_module}; } } $config_path =~ s/::/\//g; $config_path .= '.pm'; require $config_path; my $formatter_module = delete($args{service_formatter_module}) // "NACL::Service::Xgen::Formatter"; my $formatter_path = $formatter_module; $formatter_path =~ s/::/\//g; $formatter_path .= '.pm'; require $formatter_path; # create config object my $config_obj = $config_module->new(%args); # create formatter object my $formatter_obj = $formatter_module->new(%args); # run build $self->log()->comment("Building config '$config_module'..."); $config_obj->build(%args); $self->log()->comment("...Done"); # format config $self->log()->comment("Formatting config..."); my $formatted_config = $config_obj->run_formatter(formatter => $formatter_obj); $self->log()->comment("...Done"); # display the config to the logs if ($display_config) { if ($display_config > 1) { $self->log()->comment(dumper($formatted_config)); } foreach my $rtype (keys %{$formatted_config}) { $self->log()->comment("Resource: '$rtype' count: " . scalar(@{$formatted_config->{$rtype}})); } } # cache the config $self->{cached_configs}->{$config_module} = $formatted_config; $self->log()->exit(); return $formatted_config; } 1; __END__ =head1 NAME NACL::Service::Xgen =head1 DESCRIPTION C is a configuration service that is capable of dynamically generating resource lists that are keyed by a configuration module. Xgen does not do any sort of provisioning. All Xgen will do is generate the resource list that can later be fed into a task distribution library or system that will ultimately perform the provisioning tasks. Think of it more as a recipe builder than anything. This library should never be used directly. To use the Xgen service from your tests, please refer to the ServiceAPI library L|lib-NACL-ServiceAPI-Xgen-pm> instead. The documentation listed below is intended for users of the Xgen framework that wish to learn how to build configuration modules and/or resource modules. =head1 CONFIGURATION MODULES Configuration modules are derived classes (indirectly or directly) of the L|lib-NACL-Service-Xgen-Config-pm> abstract class. Configuration modules generate resource objects that comprise the resource list to be built. Configuration modules can be derived off of each other. This enables the ability to create a reusable hierarchy of configurations. Please see the L|lib-NACL-Service-Xgen-Config-pm> class for a list of all the APIs that a config module can inherit as well as a list of APIs that should be overridden. For details on how to implement a configuration module, please refer to an example: L|lib-NACL-Service-Xgen-Examples-ExampleConfig-pm>. =head1 RESOURCE MODULES Resources are derived classes of the L|lib-NACL-Service-Xgen-Resource-pm> abstract class and can represent any sort of entity that can describe a configuration. Resource lists are comprised of resource objects. Resource objects are created by the configuration module. The catalog of existing Xgen resources can be found in the L|lib-NACL-AppBuilder-Xgen-Resource> directory. To implement a resource module, first verify that there is not already a resource module that exists in the catalog before creating it. Please see the L|lib-NACL-Service-Xgen-Resource-pm> class for a list of all the APIs that a resource module can inherit as well as a list of APIs that should be overridden. For details on how to build a resource module, please refer to an example: L|lib-NACL-Service-Xgen-Examples-ExampleResource-pm>. =head1 FORMATTER MODULES Formatter modules are derived classes of the L|lib-NACL-Service-Xgen-Formatter-pm> abstract class. They are an optional component to using the Xgen service, but provide the ability to abstract away a translation layer that may be needed between the Xgen service and the system that will ultimately consume the resource list generated by the configuration module. An example of where a formatter would be needed is if the resources defined by a configuration module need to be morphed in anyway, or need to have certain attributes modified. Please see the L|lib-NACL-Service-Xgen-Formatter-pm> class for a list of all the APIs that a formatter module can inherit as well as a list of APIs that should be overridden. For details on how to build a formatter module, please refer to an example: L|lib-NACL-Service-Xgen-Examples-ExampleFormatter-pm>. =head1 SEE ALSO C is a derived class of L|lib-NACL-Service-pm>. Please refer to that library for additional inherited capabilities. =head1 AUTHOR/MAINTAINER =over =item NACL Development (dl-nacl-dev@netapp.com) =back =cut