Exemple #1
0
def enable_salt():
    print("Enabling salt module")
    # uitbreiden met een lamba waarmee we erdoorheen kunnen zoeken
    # module_cli_api.listModules()
    connection = Connection.get_connection()
    connection.module_cli_api.activateModule('rxsalt')
    connection.module_cli_api.createWizard('rxsalt_wizard', 'NEW')
Exemple #2
0
def apply_state(state, minion_id, test):
    #global SALT_API_MODE
    #SALT_API_MODE = 'PRODUCTION'
    connection = Connection.get_connection()
    salt_master = 'salt-master'
    sshport = connection.module_cli_api.get_setting_from_host(
        salt_master, 'sshport')[0]['value']
    saltapiport = connection.module_cli_api.get_setting_from_host(
        salt_master, 'saltapiport')[0]['value']
    salt_username = connection.module_cli_api.get_credentials_by_category(
        'Salt Settings')[0]['username']
    salt_password = connection.module_cli_api.get_credentials_by_category(
        'Salt Settings')[0]['password']

    salt_master = connection.module_cli_api.getHostByName(salt_master)
    statetype = connection.module_cli_api.getStatetypeByName('Salt-Run-State')
    settings_dict = {
        'dryrun': 'False',
        'salt-minion-id': minion_id,
        'api-mode': 'PRODUCTION',
        'salt-function': 'APPLYSTATE',
        'salt-formula': state,
        'sshport': sshport,
        'saltapiport': saltapiport,
        'salt-username': salt_username,
        'salt-password': salt_password,
        'test': test,
        'remoteuser': RemoteSettings.remoteuser
    }
    action = connection.action_factory\
        .create_action_from_host(salt_master, settings_dict, statetype)
    connection.scheduler_service.schedule_state(action)
Exemple #3
0
def send_salt_command(minion_id, command, salt_api_mode):
    # we need to get the saltmaster host object so we know where to send our commands
    connection = Connection.get_connection()
    salt_username = connection.module_cli_api.get_credentials_by_category(
        'Salt Settings')[0]['username']
    salt_password = connection.module_cli_api.get_credentials_by_category(
        'Salt Settings')[0]['password']

    settings_dict = {
        'dryrun': 'False',
        'salt-command': command,
        'salt-minion-id': minion_id,
        'api-mode': salt_api_mode,
        'salt-function': 'SALTCOMMAND',
        'sshport': '22',
        'saltapiport': '8080',
        'salt-username': salt_username,
        'salt-password': salt_password,
        'test': 'False',
        'remoteuser': RemoteSettings.remoteuser
    }
    salt_master = connection.module_cli_api.getHostByName('salt-master')
    statetype = connection.module_cli_api.getStatetypeByName('Salt-Run-State')
    action = connection.action_factory\
        .create_action_from_host(salt_master, settings_dict, statetype)
    connection.scheduler_service.schedule_state(action)
Exemple #4
0
def accept_minion(hostname):
    global SALT_API_MODE

    connection = Connection.get_connection()
    salt_username = connection.module_cli_api.get_credentials_by_category(
        'Salt Settings')[0]['username']
    salt_password = connection.module_cli_api.get_credentials_by_category(
        'Salt Settings')[0]['password']

    sshport = connection.module_cli_api.get_setting_from_host(
        hostname, 'sshport')[0]['value']
    saltapiport = connection.module_cli_api.get_setting_from_host(
        hostname, 'saltapiport')[0]['value']
    print('salt connection to: ' + hostname + ' at port: ' + saltapiport)
    salt_master = connection.module_cli_api.getHostByName(hostname)
    statetype = connection.module_cli_api.getStatetypeByName('Salt-Run-State')
    settings_dict = {
        'dryrun': 'False',
        'salt-minion-id': 'None',
        'api-mode': 'PRODUCTION',
        'salt-function': 'ACCEPTMINION',
        'sshport': sshport,
        'saltapiport': saltapiport,
        'salt-username': salt_username,
        'salt-password': salt_password,
        'test': 'False',
        'remoteuser': RemoteSettings.remoteuser
    }
    action = connection.action_factory\
            .create_action_from_host(salt_master, settings_dict, statetype)
    connection.scheduler_service.schedule_state(action)
Exemple #5
0
def sync_salt_formula(salt_formula):
    connection = Connection.get_connection()
    global SALT_API_MODE
    hostname = 'salt-master'
    sshport = connection.module_cli_api.get_setting_from_host(
        hostname, 'sshport')[0]['value']
    saltapiport = connection.module_cli_api.get_setting_from_host(
        hostname, 'saltapiport')[0]['value']

    settings_dict = {
        'dryrun': 'False',
        'salt-command': '',
        'salt-minion-id': '',
        'api-mode': SALT_API_MODE,
        'salt-formula': salt_formula,
        'salt-function': 'SYNCFORMULA',
        'sshport': sshport,
        'saltapiport': saltapiport
    }
    salt_master = connection.module_cli_api.getHostByName('salt-master')
    statetype = connection.module_cli_api.getStatetypeByName('Salt-Run-State')
    action = connection.action_factory\
        .create_action_from_host(salt_master, settings_dict, statetype)
    connection.scheduler_service.schedule_state(action)
Exemple #6
0
def enable_dockercompose():
    print("Enabling dockercompose module")
    # uitbreiden met een lamba waarmee we erdoorheen kunnen zoeken
    # module_cli_api.listModules()
    connection = Connection.get_connection()
    connection.module_cli_api.activateModule('rxdockercompose')
Exemple #7
0
def connect():
    global connection
    connection = Connection()
    connection.connect()
Exemple #8
0
import glob
from backend.rxrelease.rxbackend.core.cli.connection import Connection
from backend.rxrelease.rxbackend.core.cli.modulecli import ModuleCLI

c = Connection.get_connection()


def help():
    print("list_modules() -> Lists modules that are available")
    print("enable_salt() -> enables salt module")
    print(
        "reset_saltwizard() -> DEVELOPER, resets the state of the saltwizard, easy for testing"
    )
    print(
        "env = module_cli_api.getEnvironment(<hostname>,<statetype_name>) -> DEVELOPER, get an environment for a particular host,statetype combination, call runner.runStateHandlerJob(<statehandlername>,env)"
    )
    print(
        "example voor getEnvironment:  env = module_cli_api.getEnvironment('salt-master','Salt-Api')"
    )
    print(
        "execute statehandler without the scheduler, call runner.runStateHandlerJob('install-salt-api',env) "
    )
    print(
        "init_rxrelease_db() -> fill the database with default objects, run only once because it does not drop things"
    )
    print(
        "force_state(hostname,statetype_name,status) -> can be used to force a state, can be usefull for testing or recovering from a borked state"
    )
    print(
        "init_test_db() -> fills the database with mock statetypes that can be used to test functionality without having a VM "
    )