<commit_before># -*- coding: utf-8 -*-
# @COPYRIGHT_begin
#
# Copyright [2015] <NAME>, M4GiK Software
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @COPYRIGHT_end

import sys

from fabric.api import run, task
from core.settings.config import VM_IMAGE_ROOT_PASSWORD
from virtual_controller.juju_core.ssh_connector import SSHConnector
from ilogue.fexpect import expect, expecting, run

sys.stderr = open('/dev/null')
sys.stderr = sys.__stderr__


@task
def init_juju_on_vm():
    """
    Exec procedure on remote server to initialize juju environment.
    """
    SSHConnector.check_status(
        run('juju generate-config && juju switch local',
            warn_only=True,
            stderr=sys.stderr,
            combine_stderr=True)
    )

    # SSHConnector.check_status(
    #     sudo('chmod 777 /home/devcloud/.juju/ -R',
    #          shell=True,
    #          warn_only=True,
    #          stderr=sys.stderr,
    #          combine_stderr=True)
    # )

    prompts = []
    prompts += expect('[sudo] password for devcloud:', VM_IMAGE_ROOT_PASSWORD)

    with expecting(prompts):
        SSHConnector.check_status(
            run('juju bootstrap',
                warn_only=True,
                stderr=sys.stderr,
                combine_stderr=True)
        )<commit_msg>#33 Improve configuration for paramiko<commit_after># -*- coding: utf-8 -*-
# @COPYRIGHT_begin
#
# Copyright [2015] <NAME>, M4GiK Software
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @COPYRIGHT_end

import sys

from fabric.api import task, run
from core.settings.config import VM_IMAGE_ROOT_PASSWORD
from virtual_controller.juju_core.ssh_connector import SSHConnector

sys.stderr = open('/dev/null')
sys.stderr = sys.__stderr__


@task
def init_juju_on_vm():
    """
    Exec procedure on remote server to initialize juju environment.
    """
    SSHConnector.check_status(
        run('juju generate-config && juju switch local',
            warn_only=True,
            stderr=sys.stderr,
            combine_stderr=True)
    )

    # prompts = []
    # prompts += expect('[sudo] password for devcloud:', VM_IMAGE_ROOT_PASSWORD)

    # with expecting(prompts):
    SSHConnector.check_status(
        run('echo ' + VM_IMAGE_ROOT_PASSWORD + ' | sudo -S apt-get update && juju bootstrap',
            warn_only=True,
            stderr=sys.stderr,
            combine_stderr=True)
    )
{'fraction_non_alphanumeric': 0.09336099585062241, 'fraction_numerical': 0.007409602845287492, 'mean_word_length': 3.090909090909091, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '139764', 'n_tokens_mistral': 1005, 'n_tokens_neox': 959, 'n_words': 311}