예제 #1
0
 def __build(self, worker, user_args):
   fabric_env['pretty_host_string'] = worker.pretty_name
   with fabric_rcd(worker.build_location):
     #don't make a failed build a reason to abort
     with fabric_settings(warn_only=True):
       command = worker.generateBuildCommand(user_args)
       fabric_run(command)
예제 #2
0
 def __build(self, worker, user_args):
     fabric_env['pretty_host_string'] = worker.pretty_name
     with fabric_rcd(worker.build_location):
         #don't make a failed build a reason to abort
         with fabric_settings(warn_only=True):
             command = worker.generateBuildCommand(user_args)
             fabric_run(command)
예제 #3
0
def run_test(conn, ip_address, key_file_path):
    lgr.info('Bootstrapping a Cloudify manager...')
    os.system('cfy --version')
    lgr.info('Writing inputs file...')
    inputs = json.dumps(
        {
            'public_ip': ip_address,
            'private_ip': 'localhost',
            'ssh_user': USER,
            'ssh_key_filename': key_file_path,
            'agents_user': USER
        },
        indent=2)
    lgr.info('Bootstrap inputs: {0}'.format(inputs))
    with open('inputs.json', 'w') as f:
        f.write(inputs)

    execute('cfy init')
    execute('cfy bootstrap -p ../simple-manager-blueprint.yaml '
            '-i inputs.json --install-plugins')

    generated_key_path = '/root/.ssh/key.pem'
    lgr.info('Generating SSH keys for hello-world deployment...')
    with fabric_settings(host_string='{0}:{1}'.format(ip_address, 22),
                         user=USER,
                         key_filename=key_file_path,
                         timeout=30):
        fabric_run('sudo ssh-keygen -f {0} -q -t rsa -N ""'.format(
            generated_key_path))
        fabric_run('sudo cat {0}.pub >> ~/.ssh/authorized_keys'.format(
            generated_key_path))

    execute('git clone {0}'.format(HELLO_WORLD_URL))

    webserver_port = HELLO_WORLD_PORT
    hello_inputs = json.dumps({
        'server_ip': 'localhost',
        'agent_user': USER,
        'agent_private_key_path': generated_key_path,
        'webserver_port': webserver_port
    })
    with open('hello-inputs.json', 'w') as f:
        f.write(hello_inputs)

    execute('cfy blueprints upload -b {0} -p '
            'cloudify-hello-world-example/singlehost-blueprint.yaml'.format(
                BLUEPRINT_ID))
    execute('cfy deployments create -b {0} -d {1} -i hello-inputs.json'.format(
        BLUEPRINT_ID, DEPLOYMENT_ID))

    # Sleep some time because of CFY-4066
    lgr.info('Waiting for 15 seconds before executing install workflow...')
    time.sleep(15)
    execute('cfy executions start -d {0} -w install'.format(DEPLOYMENT_ID))

    url = 'http://{0}:{1}'.format(ip_address, webserver_port)
    lgr.info('Verifying deployment at {0}'.format(url))
    urllib2.urlopen(url).read()
    lgr.info('Deployment is running!')
def run_test(conn, ip_address, key_file_path):
    lgr.info('Bootstrapping a Cloudify manager...')
    os.system('cfy --version')
    lgr.info('Writing inputs file...')
    inputs = json.dumps({
        'public_ip': ip_address,
        'private_ip': 'localhost',
        'ssh_user': USER,
        'ssh_key_filename': key_file_path,
        'agents_user': USER
    }, indent=2)
    lgr.info('Bootstrap inputs: {0}'.format(inputs))
    with open('inputs.json', 'w') as f:
        f.write(inputs)

    execute('cfy init')
    execute('cfy bootstrap -p ../simple-manager-blueprint.yaml '
            '-i inputs.json --install-plugins')

    generated_key_path = '/root/.ssh/key.pem'
    lgr.info('Generating SSH keys for hello-world deployment...')
    with fabric_settings(host_string='{0}:{1}'.format(ip_address, 22),
                         user=USER,
                         key_filename=key_file_path,
                         timeout=30):
        fabric_run('sudo ssh-keygen -f {0} -q -t rsa -N ""'.format(
            generated_key_path))
        fabric_run('sudo cat {0}.pub >> ~/.ssh/authorized_keys'.format(
            generated_key_path))

    execute('git clone {0}'.format(HELLO_WORLD_URL))

    webserver_port = HELLO_WORLD_PORT
    hello_inputs = json.dumps({
        'server_ip': 'localhost',
        'agent_user': USER,
        'agent_private_key_path': generated_key_path,
        'webserver_port': webserver_port
    })
    with open('hello-inputs.json', 'w') as f:
        f.write(hello_inputs)

    execute('cfy blueprints upload -b {0} -p '
            'cloudify-hello-world-example/singlehost-blueprint.yaml'.format(
                BLUEPRINT_ID))
    execute('cfy deployments create -b {0} -d {1} -i hello-inputs.json'.format(
        BLUEPRINT_ID, DEPLOYMENT_ID))

    # Sleep some time because of CFY-4066
    lgr.info('Waiting for 15 seconds before executing install workflow...')
    time.sleep(15)
    execute('cfy executions start -d {0} -w install'.format(DEPLOYMENT_ID))

    url = 'http://{0}:{1}'.format(ip_address, webserver_port)
    lgr.info('Verifying deployment at {0}'.format(url))
    urllib2.urlopen(url).read()
    lgr.info('Deployment is running!')
예제 #5
0
def verify_connectivity_to_instance(ip_address, key_filename):
    port = 22
    try:
        lgr.info('Verifying SSH connectivity to: {0}:{1}'.format(
            ip_address, port))
        with fabric_settings(host_string='{0}:{1}'.format(ip_address, port),
                             user=USER,
                             key_filename=key_filename):
            fabric_run('echo "hello"', timeout=10)
    except Exception as e:
        lgr.warning('Unable to connect: {0}'.format(str(e)))
        raise
def verify_connectivity_to_instance(ip_address, key_filename):
    port = 22
    try:
        lgr.info('Verifying SSH connectivity to: {0}:{1}'.format(
            ip_address, port))
        with fabric_settings(host_string='{0}:{1}'.format(ip_address, port),
                             user=USER,
                             key_filename=key_filename):
            fabric_run('echo "hello"', timeout=10)
    except Exception as e:
        lgr.warning('Unable to connect: {0}'.format(str(e)))
        raise
예제 #7
0
  def __setup(self, worker):
    fabric_env['pretty_host_string'] = worker.pretty_name

    #make directory first
    with fabric_settings(warn_only=True):
      command = "mkdir -p " +  worker.build_location
      fabric_run(command)

    #run ccmake / cmake depending on user input
    run_configure = fabric_prompt('Would you like to run ccmake: ', default='y', validate=r'^(y|n)$')
    command = worker.generateSetupCommand(is_interactive=(run_configure=='y'))
    with fabric_rcd(worker.build_location):
      fabric_run(command)
예제 #8
0
파일: stargate.py 프로젝트: bmx0r/vpynup
def provision():
    _config_dict = _load_config()
    _instance_params = _config_dict['provider']['instance']

    _hostname = gate_hostname()
    _i = 0
    while(_i < 10 and _hostname == ''):
        _hostname = gate_hostname()
        _i = _i + 1
        time.sleep(5)
    _sshkeys = _instance_params['key_path']
    if 'user' not in _instance_params:
        _user = '******'
    else:
        _user = _instance_params['user']
    time.sleep(5)
    retdict = fabric_run(fabricant.provision, _hostname, _user, _sshkeys)

    if True in retdict.values():
        save(None, True)
        rval = True
    else:
        rval = False

    return rval
예제 #9
0
def run(command, shell=True, pty=True, combine_stderr=None, quiet=False,
        warn_only=False, stdout=None, stderr=None, timeout=None,
        shell_escape=None):
    result = None

    env.disable_known_hosts = True

    if (not stdout) and (not stderr):
        stdout, stderr = log.stdio()
    try:
        result = fabric_run(command, shell=shell, pty=pty,
                            combine_stderr=combine_stderr, quiet=quiet,
                            warn_only=warn_only, stdout=stdout,
                            stderr=stderr, timeout=timeout,
                            shell_escape=shell_escape)

    except:
        puts("[%s] %s %s" % (env.host_string, command, red("failed")))
        if hasattr(stdout, "print_recent"):
            stdout.print_recent()
        raise
    else:
        puts("[%s] %s %s" % (env.host_string, command, green("success")))

    return result
예제 #10
0
    def test_compute_network(self, *_):
        self.test_name = 'test_compute_network'
        self.blueprint_path = './examples/compute-network.yaml'
        self.inputs = dict(self.client_config)
        self.initialize_local_blueprint()
        self.addCleanup(self.cleanup_uninstall)
        self.install_blueprint()
        sleep(10)
        try:
            server_node_instance = \
                self.cfy_local.storage.get_node_instances('vm')[0]
            ip_address = \
                server_node_instance.runtime_properties['ip']
        except (KeyError, IndexError) as e:
            raise Exception('Missing Runtime Property: {0}'.format(str(e)))

        with fabric_settings(
                host_string=ip_address,
                key_filename=path.join(path.expanduser('~/'),
                                       '.ssh/vmware-centos.key'),
                user='******',
                abort_on_prompts=True):
            fabric_run_output = fabric_run('last')
            self.assertEqual(0, fabric_run_output.return_code)
        self.uninstall_blueprint()
예제 #11
0
 def run(self, command, **kwargs):
     if self.local_deployment:
         return self.local(command, **kwargs)
     if kwargs.get('user') or kwargs.get('use_sudo'):
         return self.sudo(command, **kwargs)
     else:
         return fabric_run(self.fmt(command, **kwargs), **self._expects(kwargs, self.run_expect))
예제 #12
0
    def __setup(self, worker):
        fabric_env['pretty_host_string'] = worker.pretty_name

        #make directory first
        with fabric_settings(warn_only=True):
            command = "mkdir -p " + worker.build_location
            fabric_run(command)

        #run ccmake / cmake depending on user input
        run_configure = fabric_prompt('Would you like to run ccmake: ',
                                      default='y',
                                      validate=r'^(y|n)$')
        command = worker.generateSetupCommand(
            is_interactive=(run_configure == 'y'))
        with fabric_rcd(worker.build_location):
            fabric_run(command)
예제 #13
0
def run(command, forward_agent=False, use_sudo=False, **kwargs):
    require('hosts')
    if 'localhost' in env.hosts:
        return local(command)
    elif forward_agent:
        if not env.host:
            abort("At least one host is required")
        return sshagent_run(command, use_sudo=use_sudo)
    else:
        return fabric_run(command, **kwargs)
예제 #14
0
def run(command, forward_agent=False, use_sudo=False, **kwargs):
    require('hosts')
    if 'localhost' in env.hosts:
        return local(command)
    elif forward_agent:
        if not env.host:
            abort("At least one host is required")
        return sshagent_run(command, use_sudo=use_sudo)
    else:
        return fabric_run(command, **kwargs)
    def test_blueprint_example(self, *_):
        self.test_name = 'test_blueprint_example'
        self.blueprint_path = './examples/local/blueprint.yaml'
        self.inputs = dict(self.client_config)
        self.inputs.update({
            'external_network_id': 'dda079ce-12cf-4309-879a-8e67aec94de4',
            'example_subnet_cidr': '10.10.0.0/24',
            'name_prefix': 'blueprint_',
            'image_id': 'e41430f7-9131-495b-927f-e7dc4b8994c8',
            'flavor_id': '3',
            'agent_user': '******'
        })
        self.initialize_local_blueprint()
        self.install_blueprint()
        time.sleep(10)
        private_key = StringIO.StringIO()
        try:
            server_floating_ip = \
                self.cfy_local.storage.get_node_instances(
                    'example-floating_ip_address')[0]
            server_key_instance = \
                self.cfy_local.storage.get_node_instances(
                    'example-keypair')[0]
            ip_address = \
                server_floating_ip.runtime_properties[
                    'floating_ip_address']
            private_key.write(
                server_key_instance.runtime_properties['private_key'])
            private_key.pos = 0
        except (KeyError, IndexError) as e:
            raise Exception('Missing Runtime Property: {0}'.format(str(e)))

        with fabric_settings(host_string=ip_address,
                             key=private_key.read(),
                             user=self.inputs.get('agent_user'),
                             abort_on_prompts=True):
            fabric_run_output = fabric_run('last')
            self.assertEqual(0, fabric_run_output.return_code)

        # execute uninstall workflow
        self.uninstall_blueprint()
예제 #16
0
    def test_existing_compute_storage(self, *_):
        # Install the Actual VM
        self.test_name = 'test_existing_compute'
        self.blueprint_path = './examples/compute-storage.yaml'
        self.inputs = dict(self.client_config)
        self.initialize_local_blueprint()
        self.addCleanup(self.cleanup_uninstall)
        self.install_blueprint()
        sleep(10)
        try:
            server_node_instance = \
                self.cfy_local.storage.get_node_instances('vm')[0]
            server_name = \
                server_node_instance.runtime_properties['name']
        except (KeyError, IndexError) as e:
            raise Exception('Missing Runtime Property: {0}'.format(str(e)))

        # "Install" the "External" VM
        new_inputs = deepcopy(self.inputs)
        new_inputs.update({'old_vm': True, 'server_name': server_name})
        _cfy_local = self.initialize_local_blueprint(self.test_name + '2',
                                                     new_inputs)
        self.install_blueprint(cfy_local=_cfy_local)
        try:
            server_node_instance = \
                _cfy_local.storage.get_node_instances('vm')[0]
            ip_address = \
                server_node_instance.runtime_properties['public_ip']
        except (KeyError, IndexError) as e:
            raise Exception('Missing Runtime Property: {0}'.format(str(e)))

        with fabric_settings(host_string=ip_address,
                             key_filename=path.join(path.expanduser('~/'),
                                                    '.ssh/vmware-centos.key'),
                             user='******',
                             abort_on_prompts=True):
            fabric_run_output = fabric_run('last')
            self.assertEqual(0, fabric_run_output.return_code)
        self.uninstall_blueprint()
예제 #17
0
def run(command,
        shell=True,
        pty=True,
        combine_stderr=None,
        quiet=False,
        warn_only=False,
        stdout=None,
        stderr=None,
        timeout=None,
        shell_escape=None):
    result = None

    env.disable_known_hosts = True

    if (not stdout) and (not stderr):
        stdout, stderr = log.stdio()
    try:
        result = fabric_run(command,
                            shell=shell,
                            pty=pty,
                            combine_stderr=combine_stderr,
                            quiet=quiet,
                            warn_only=warn_only,
                            stdout=stdout,
                            stderr=stderr,
                            timeout=timeout,
                            shell_escape=shell_escape)

    except:
        puts("[%s] %s %s" % (env.host_string, command, red("failed")))
        if hasattr(stdout, "print_recent"):
            stdout.print_recent()
        raise
    else:
        puts("[%s] %s %s" % (env.host_string, command, green("success")))

    return result
예제 #18
0
def demo(name=None):
    put('src/demos/%s.py' % name, '~', mode=0755)
    fabric_run(os.path.expanduser('~/%s.py' % name))
예제 #19
0
 def doit():
     if is_local(env.host_string):
         return local(cmd, capture=True)
     else:
         return fabric_run(cmd)
예제 #20
0
 def _fabric_run(cmd):
     return fabric_run(cmd)
예제 #21
0
def run(command, shell=True, pty=True):
    return fabric_run(command % (env), shell=shell, pty=pty)
예제 #22
0
 def doit():
     if is_local(env.host_string):
         return local(cmd, capture=True)
     else:
         return fabric_run(cmd)
예제 #23
0
 def __test(self, worker, user_args):
   fabric_env['pretty_host_string'] = worker.pretty_name
   with fabric_rcd(worker.build_location):
     with fabric_settings(warn_only=True):
       command = worker.generateTestCommand(user_args)
       fabric_run(command)
예제 #24
0
파일: fabutil2.py 프로젝트: amrik/fabutil
def run(command, **kwargs):
    return fabric_run(command, **kwargs)
예제 #25
0
    def run(*args, **kwargs):
        if is_localhost(env.host_string):
            return nofabric.run(*args, **kwargs)

        else:
            return fabric_run(*args, **kwargs)
예제 #26
0
 def __test(self, worker, user_args):
     fabric_env['pretty_host_string'] = worker.pretty_name
     with fabric_rcd(worker.build_location):
         with fabric_settings(warn_only=True):
             command = worker.generateTestCommand(user_args)
             fabric_run(command)
예제 #27
0
    def run(*args, **kwargs):
        if is_localhost(env.host_string):
            return nofabric.run(*args, **kwargs)

        else:
            return fabric_run(*args, **kwargs)