<commit_before>#!/usr/bin/perl -w

use strict;

# Purpose: create a machine instance, base on a given base machine and template.
# TODO provide template name in CLI.

# Steps:
#  Generate the machine definition in /opt/gas/


# TODO split this into three PMs: reading data, handling the data, writing the output and generating the actual clone.

use FindBin;
BEGIN{
	  push( @INC, "$FindBin::RealBin" );    ## Path to local modules
}

use Data::Dumper;
use ExecuteAndTrace;


use ConfiguredNetworks;
use Default;
use InstanceConfiguration;
use InfoGather;
use InfoProcessing;
use InfoExecute;




my %f_hVirmanConfiguration;
my $f_szVirmanConfigurationFile = "/etc/virman/default.xml";

my $f_szInstanceNumber = "001";

my $szTemplatePath = "$FindBin::RealBin/../templates";
my $szFilesPath = "$FindBin::RealBin/../files";

# TODO C put this in a protected directory.
my $f_szGeneralContainerKeyFile;

# TODO V read this from the /etc/virman/defaults. 
my $szVirshFilePoolPath = '/virt_images';

my %f_hMachineConfiguration;

# TODO V Read the networks that have been configured to validate the ones
#         the apps are asking for.



# ======================================= FUNCTIONS ================================



# ====================================== MAIN ============================================ 

my $szDomainName = shift || die("!!! You must provide a role name.");


# TODO Support list the supported roles.
# TODO Support manual instance number?

IGLoadVirmanConfiguration(\%f_hVirmanConfiguration, $f_szVirmanConfigurationFile);

my $szXmlConfigurationFilename = "$f_hVirmanConfiguration{'InstanceCfgBasePath'}/${szDomainName}/${szDomainName}.xml";

if ( ! -f "$szXmlConfigurationFilename" ) {
  die("!!! Domain name '$szDomainName' does not have a role.xml file in $f_hVirmanConfiguration{'RolesRelativePath'}");
}

my %hInstanceConfiguration;
IGReadInstanceConfiguration(\%hInstanceConfiguration, $szXmlConfigurationFilename);

# If an install wrapper has been defined then use it.
if ( exists($hInstanceConfiguration{'InstallWrapper'}) && $hInstanceConfiguration{'InstallWrapper'} ne "" ) {
  my %hInstallWrapperConfiguration;
  InstWrapLoadInstallWrapperConfiguration(\%hInstallWrapperConfiguration, "$f_hVirmanConfiguration{'InstallWrapperPath'}/$hInstanceConfiguration{'InstallWrapper'}");
  IPMergeInstanceAndWrapperInfo(\%hInstanceConfiguration, \%hInstallWrapperConfiguration);
}

IPSetMachineConfiguration(\%f_hMachineConfiguration, \%f_hVirmanConfiguration, \%hInstanceConfiguration, $szDomainName, $f_szInstanceNumber);


# TODO C Read the InstallWrapper is given.
# ReadInsatllWrapper

# TODO C Merge the InstallWrapper hash and the instance configuration.

# TODO Return the path to the domain xml file.
IEGenerateCloudInitIsoImage(\%hInstanceConfiguration, \%f_hVirmanConfiguration, \%f_hMachineConfiguration, $f_szInstanceNumber);

my $szBackingFileQcow2 = IEGetBackingFile(\%hInstanceConfiguration);

IECreateInstance(\%hInstanceConfiguration, \%f_hVirmanConfiguration, \%f_hMachineConfiguration, $szTemplatePath, $szBackingFileQcow2);

Log("III Done.\n");
<commit_msg>virman-clone.pl: Includes the post nic conf.<commit_after>#!/usr/bin/perl -w

use strict;

# Purpose: create a machine instance, base on a given base machine and template.
# TODO provide template name in CLI.

# Steps:
#  Generate the machine definition in /opt/gas/


# TODO split this into three PMs: reading data, handling the data, writing the output and generating the actual clone.

use FindBin;
BEGIN{
	  push( @INC, "$FindBin::RealBin" );    ## Path to local modules
}

use Data::Dumper;
use ExecuteAndTrace;


use ConfiguredNetworks;
use Default;
use InstanceConfiguration;
use InfoGather;
use InfoProcessing;
use InfoExecute;
use InstallWrapper;




my %f_hVirmanConfiguration;
my $f_szVirmanConfigurationFile = "/etc/virman/default.xml";

my $f_szInstanceNumber = "001";

my $szTemplatePath = "$FindBin::RealBin/../templates";
my $szFilesPath = "$FindBin::RealBin/../files";

# TODO C put this in a protected directory.
my $f_szGeneralContainerKeyFile;

# TODO V read this from the /etc/virman/defaults. 
my $szVirshFilePoolPath = '/virt_images';

my %f_hMachineConfiguration;

# TODO V Read the networks that have been configured to validate the ones
#         the apps are asking for.



# ======================================= FUNCTIONS ================================



# ====================================== MAIN ============================================ 

my $szDomainName = shift || die("!!! You must provide a role name.");


# TODO Support list the supported roles.
# TODO Support manual instance number?

IGLoadVirmanConfiguration(\%f_hVirmanConfiguration, $f_szVirmanConfigurationFile);

my $szXmlConfigurationFilename = "$f_hVirmanConfiguration{'InstanceCfgBasePath'}/${szDomainName}/${szDomainName}.xml";

if ( ! -f "$szXmlConfigurationFilename" ) {
  die("!!! Domain name '$szDomainName' does not have a role.xml file in $f_hVirmanConfiguration{'RolesRelativePath'}");
}

my %hInstanceConfiguration;
IGReadInstanceConfiguration(\%hInstanceConfiguration, $szXmlConfigurationFilename);

# If an install wrapper has been defined then use it.
if ( exists($hInstanceConfiguration{'InstallWrapper'}) && $hInstanceConfiguration{'InstallWrapper'} ne "" ) {
  my %hInstallWrapperConfiguration;
  InstWrapLoadInstallWrapperConfiguration(\%hInstallWrapperConfiguration, "$f_hVirmanConfiguration{'InstallWrapperPath'}/$hInstanceConfiguration{'InstallWrapper'}.xml");
  IPMergeInstanceAndWrapperInfo(\%hInstanceConfiguration, \%hInstallWrapperConfiguration);
}

IPSetMachineConfiguration(\%f_hMachineConfiguration, \%f_hVirmanConfiguration, \%hInstanceConfiguration, $szDomainName, $f_szInstanceNumber);


# TODO C Read the InstallWrapper is given.
# ReadInsatllWrapper

# TODO C Merge the InstallWrapper hash and the instance configuration.

# TODO Return the path to the domain xml file.
IEGenerateCloudInitIsoImage(\%hInstanceConfiguration, \%f_hVirmanConfiguration, \%f_hMachineConfiguration, $f_szInstanceNumber);

my $szBackingFileQcow2 = IEGetBackingFile(\%hInstanceConfiguration);

IECreateInstance(\%hInstanceConfiguration, \%f_hVirmanConfiguration, \%f_hMachineConfiguration, $szTemplatePath, $szBackingFileQcow2);

Log("III Done.\n");

{'fraction_non_alphanumeric': 0.147475712693104, 'fraction_numerical': 0.0015926102882624622, 'mean_word_length': 6.5299760191846525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 9}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4510368', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1719, 'n_words': 491}