<commit_before>import os
import os.path

from stratuslab.BaseInstallator import BaseInstallator
from stratuslab.CloudConnectorFactory import CloudConnectorFactory
from stratuslab.Util import fileGetContent
from stratuslab.Util import filePutContent
from stratuslab.Util import modulePath
from stratuslab.Util import printError

class OneInstallator(BaseInstallator):
    
    def runInstall(self, options, config):
        self.privateKey = (True and options.privateKey) or (config.get('node_private_key'))
        self.infoDriver = (True and options.infoDriver) or ('im_%s' % config.get('hypervisor'))
        self.virtDriver = (True and options.virtDriver) or ('vmm_%s' % config.get('hypervisor'))
        self.transfertDriver = (True and options.transfertDriver) or ('tm_%s' % config.get('share_type'))
        
        self.onedConfTemplate = options.onedTpl
        
        super(OneInstallator, self).runInstall(options, config)

    # -------------------------------------------
    #    Cloud admin management
    # -------------------------------------------
    
    def createCloudAdmin(self, system):
        system.createCloudGroup(self.config.get('one_group'),
                                self.config.get('one_gid'))
        system.createCloudAdmin(self.config.get('one_username'),
                                self.config.get('one_uid'),
                                self.config.get('one_home'),
                                self.config.get('one_password'))

    def configureCloudAdminNode(self):
        self.node.configureNetwork(self.config.get('node_network_interface'),
                                   self.config.get('node_bridge_name'))
        self.node.configureCloudAdminSshKeysNode()

    def configureCloudAdminFrontend(self):
        self.frontend.configureCloudAdminEnv(self.config.get('one_port'))
        self.frontend.configureCloudAdminAccount()
        self.frontend.configureCloudAdminSshKeys()

        if self.config.get('vm_dir') != '':
            self.frontend.createDirsCmd(self.config.get('vm_dir'))
            self.frontend.setOwnerCmd(self.config.get('vm_dir'))
        
    # -------------------------------------------
    #    Cloud installation management
    # -------------------------------------------

    def installCloudSystem(self):
        self.frontend.installFrontendDependencies()
        self.frontend.cloneGitRepository(self.config.get('one_build_dir'),
                                         self.config.get('one_git_repo'),
                                         self.config.get('one_clone_name'),
                                         self.config.get('one_branch'))
        self.frontend.buildCloudSystem()
        self.frontend.installCloudSystem()
        self._copyContextualizationScript(self.config.get('one_home'))
        
    # -------------------------------------------
    #    Cloud configuration management
    # -------------------------------------------

    def configureCloudSystem(self):
        if not os.path.isfile(self.onedConfTemplate):
            printError('ONe daemon configuration template '
                       '%s does not exists' % self.onedConfTemplate)
    
        filePutContent('%s/etc/oned.conf' % self.config.get('one_home'),
                       fileGetContent(self.onedConfTemplate) % self.config)
    
    def addCloudNode(self):
        self.cloud.hostCreate(self.nodeAddr, self.infoDriver, self.virtDriver, self.transfertDriver)
        
    def addDefaultNetworks(self):
        for vnet in self.defaultNetworks:
            if self.config.get('one_%s_network_addr' % vnet, '') == '':
                self.cloud.networkCreate(self._buildRangedNetworkTemplate(vnet))
            else:
                self.cloud.networkCreate(self._buildFixedNetworkTemplate(vnet))
        
    def _buildFixedNetworkTemplate(self, networkName):
        vnetTpl = fileGetContent('%s/share/vnet/fixed.net' % modulePath)
        
        leases = ['LEASES = [ IP="%s"]' % i for i in self.config.get('one_%s_network_addr' % networkName).split(' ')]
        
        vnetTpl = vnetTpl % ({'network_name': networkName,
                             'bridge': self.config.get('node_bridge_name'),
                             'leases': '\n'.join(leases)})
        return vnetTpl<commit_msg>Set VM directory default value<commit_after>import os
import os.path

from stratuslab.BaseInstallator import BaseInstallator
from stratuslab.CloudConnectorFactory import CloudConnectorFactory
from stratuslab.Util import fileGetContent
from stratuslab.Util import filePutContent
from stratuslab.Util import modulePath
from stratuslab.Util import printError

class OneInstallator(BaseInstallator):
    
    def runInstall(self, options, config):
        self.privateKey = (True and options.privateKey) or (config.get('node_private_key'))
        self.infoDriver = (True and options.infoDriver) or ('im_%s' % config.get('hypervisor'))
        self.virtDriver = (True and options.virtDriver) or ('vmm_%s' % config.get('hypervisor'))
        self.transfertDriver = (True and options.transfertDriver) or ('tm_%s' % config.get('share_type'))
        
        self.onedConfTemplate = options.onedTpl
        
        super(OneInstallator, self).runInstall(options, config)

    # -------------------------------------------
    #    Cloud admin management
    # -------------------------------------------
    
    def createCloudAdmin(self, system):
        system.createCloudGroup(self.config.get('one_group'),
                                self.config.get('one_gid'))
        system.createCloudAdmin(self.config.get('one_username'),
                                self.config.get('one_uid'),
                                self.config.get('one_home'),
                                self.config.get('one_password'))

    def configureCloudAdminNode(self):
        self.node.configureNetwork(self.config.get('node_network_interface'),
                                   self.config.get('node_bridge_name'))
        self.node.configureCloudAdminSshKeysNode()

    def configureCloudAdminFrontend(self):
        self.frontend.configureCloudAdminEnv(self.config.get('one_port'))
        self.frontend.configureCloudAdminAccount()
        self.frontend.configureCloudAdminSshKeys()

        if self.config.get('vm_dir') != '':
            self.frontend.createDirsCmd(self.config.get('vm_dir'))
            self.frontend.setOwnerCmd(self.config.get('vm_dir'))
        
    # -------------------------------------------
    #    Cloud installation management
    # -------------------------------------------

    def installCloudSystem(self):
        self.frontend.installFrontendDependencies()
        self.frontend.cloneGitRepository(self.config.get('one_build_dir'),
                                         self.config.get('one_git_repo'),
                                         self.config.get('one_clone_name'),
                                         self.config.get('one_branch'))
        self.frontend.buildCloudSystem()
        self.frontend.installCloudSystem()
        self._copyContextualizationScript(self.config.get('one_home'))
        
    # -------------------------------------------
    #    Cloud configuration management
    # -------------------------------------------

    def configureCloudSystem(self):
        if not os.path.isfile(self.onedConfTemplate):
            printError('ONe daemon configuration template '
                       '%s does not exists' % self.onedConfTemplate)

        conf = self.config.copy()
        if conf.get('vm_dir') == '':
            conf['vm_dir'] = '%s/var' % conf.get('one_home')

        filePutContent('%s/etc/oned.conf' % self.config.get('one_home'),
                       fileGetContent(self.onedConfTemplate) % conf)
    
    def addCloudNode(self):
        self.cloud.hostCreate(self.nodeAddr, self.infoDriver, self.virtDriver, self.transfertDriver)
        
    def addDefaultNetworks(self):
        for vnet in self.defaultNetworks:
            if self.config.get('one_%s_network_addr' % vnet, '') == '':
                self.cloud.networkCreate(self._buildRangedNetworkTemplate(vnet))
            else:
                self.cloud.networkCreate(self._buildFixedNetworkTemplate(vnet))
        
    def _buildFixedNetworkTemplate(self, networkName):
        vnetTpl = fileGetContent('%s/share/vnet/fixed.net' % modulePath)
        
        leases = ['LEASES = [ IP="%s"]' % i for i in self.config.get('one_%s_network_addr' % networkName).split(' ')]
        
        vnetTpl = vnetTpl % ({'network_name': networkName,
                             'bridge': self.config.get('node_bridge_name'),
                             'leases': '\n'.join(leases)})
        return vnetTpl
{'fraction_non_alphanumeric': 0.16215289681179293, 'fraction_numerical': 0.0, 'mean_word_length': 1.938885157824043, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '799805', 'n_tokens_mistral': 2286, 'n_tokens_neox': 2253, 'n_words': 348}