<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.safehaus.subutai.impl.lxcmanager;


import java.util.Set;

import org.safehaus.subutai.api.commandrunner.Command;
import org.safehaus.subutai.api.commandrunner.CommandsSingleton;
import org.safehaus.subutai.api.commandrunner.RequestBuilder;
import org.safehaus.subutai.shared.protocol.Agent;
import org.safehaus.subutai.shared.protocol.Util;


/**
 * Commands for lxc management
 */
public class Commands extends CommandsSingleton {

    public static Command getCloneCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand( new RequestBuilder(
                String.format( "/usr/bin/lxc-clone -o base-container -n %1$s && addhostlxc %1$s", lxcHostName ) )
                .withTimeout( 360 ), Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getCloneNStartCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand( new RequestBuilder( String.format(
                "/usr/bin/lxc-clone -o base-container -n %1$s && addhostlxc %1$s && /usr/bin/lxc-start -n %1$s -d &",
                lxcHostName ) ).withTimeout( 360 ), Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getLxcListCommand( Set<Agent> agents ) {
        return createCommand( new RequestBuilder( "/usr/bin/lxc-ls -f" ).withTimeout( 60 ), agents );
    }


    public static Command getLxcInfoCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand(
                new RequestBuilder( String.format( "/usr/bin/lxc-info -n %s", lxcHostName ) ).withTimeout( 60 ),
                Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getLxcStartCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand(
                new RequestBuilder( String.format( "/usr/bin/lxc-start -n %s -d &", lxcHostName ) ).withTimeout( 120 ),
                Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getLxcStopCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand(
                new RequestBuilder( String.format( "/usr/bin/lxc-stop -n %s &", lxcHostName ) ).withTimeout( 60 ),
                Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getLxcDestroyCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand( new RequestBuilder(
                String.format( "/usr/bin/lxc-destroy -n %1$s -f", lxcHostName ) )
                .withTimeout( 180 ), Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getMetricsCommand( Set<Agent> agents ) {
        return createCommand(
                new RequestBuilder( "free -m | grep buffers/cache ; df /dev/sda1 | grep /dev/sda1 ; uptime ; nproc" )
                        .withTimeout( 30 ), agents );
    }
}<commit_msg>refactored lxc manager to poll lxc-data in default lxc placement strategy instead of /dev/sda1<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.safehaus.subutai.impl.lxcmanager;


import java.util.Set;

import org.safehaus.subutai.api.commandrunner.Command;
import org.safehaus.subutai.api.commandrunner.CommandsSingleton;
import org.safehaus.subutai.api.commandrunner.RequestBuilder;
import org.safehaus.subutai.shared.protocol.Agent;
import org.safehaus.subutai.shared.protocol.Util;


/**
 * Commands for lxc management
 */
public class Commands extends CommandsSingleton {

    public static Command getCloneCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand( new RequestBuilder(
                String.format( "/usr/bin/lxc-clone -o base-container -n %1$s && addhostlxc %1$s", lxcHostName ) )
                .withTimeout( 360 ), Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getCloneNStartCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand( new RequestBuilder( String.format(
                "/usr/bin/lxc-clone -o base-container -n %1$s && addhostlxc %1$s && /usr/bin/lxc-start -n %1$s -d &",
                lxcHostName ) ).withTimeout( 360 ), Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getLxcListCommand( Set<Agent> agents ) {
        return createCommand( new RequestBuilder( "/usr/bin/lxc-ls -f" ).withTimeout( 60 ), agents );
    }


    public static Command getLxcInfoCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand(
                new RequestBuilder( String.format( "/usr/bin/lxc-info -n %s", lxcHostName ) ).withTimeout( 60 ),
                Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getLxcStartCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand(
                new RequestBuilder( String.format( "/usr/bin/lxc-start -n %s -d &", lxcHostName ) ).withTimeout( 120 ),
                Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getLxcStopCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand(
                new RequestBuilder( String.format( "/usr/bin/lxc-stop -n %s &", lxcHostName ) ).withTimeout( 60 ),
                Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getLxcDestroyCommand( Agent physicalAgent, String lxcHostName ) {
        return createCommand( new RequestBuilder(
                String.format( "/usr/bin/lxc-destroy -n %1$s -f", lxcHostName ) )
                .withTimeout( 180 ), Util.wrapAgentToSet( physicalAgent ) );
    }


    public static Command getMetricsCommand( Set<Agent> agents ) {
        return createCommand(
                new RequestBuilder( "free -m | grep buffers/cache ; df /lxc-data | grep /lxc-data ; uptime ; nproc" )
                        .withTimeout( 30 ), agents );
    }
}
{'fraction_non_alphanumeric': 0.10307767464582315, 'fraction_numerical': 0.008956196059273733, 'mean_word_length': 2.803095975232198, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4160305', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1732, 'n_words': 469}