Esempio n. 1
0
def run(provfile_path, server_name, password, extra_options):
    module_name = provyfile_module_from(provfile_path)
    prov = import_module(module_name)
    servers = get_servers_for(prov, server_name)

    build_prompt_options(servers, extra_options)

    for server in servers:
        provision_server(server, provfile_path, password, prov)
Esempio n. 2
0
 def gets_provyfile_module_from_nested_path_without_extenstion(self):
     self.assertEqual(provyfile_module_from('some/dir/provyfile'), 'some.dir.provyfile')
Esempio n. 3
0
 def gets_provyfile_module_from_nested_path(self):
     self.assertEqual(provyfile_module_from('some/dir/provyfile.py'), 'some.dir.provyfile')
Esempio n. 4
0
 def gets_provyfile_module_from_simple_path(self):
     self.assertEqual(provyfile_module_from('provyfile.py'), 'provyfile')
Esempio n. 5
0
def run(provfile_path, server_name, password, extra_options):
    module_name = provyfile_module_from(provfile_path)
    prov = import_module(module_name)
    servers = get_servers_for(prov, server_name)

    for server in servers:
        if 'options' in server:
            for option_name, option in server['options'].iteritems():
                if isinstance(option, AskFor):
                    if option.key in extra_options:
                        value = extra_options[option.key]
                    else:
                        value = option.get_value(server)
                    server['options'][option_name] = value

    for server in servers:
        host_string = "%s@%s" % (server['user'], server['address'].strip())

        context = {
            'abspath': dirname(abspath(provfile_path)),
            'path': dirname(provfile_path),
            'owner': server['user'],
            'cleanup': [],
            'registered_loaders': []
        }

        if 'options' in server and server['options']:
            for key, value in server['options'].iteritems():
                context[key] = value

        loader = ChoiceLoader([
            FileSystemLoader(join(context['abspath'], 'files'))
        ])
        context['loader'] = loader

        msg = "Provisioning %s..." % host_string
        print
        print "*" * len(msg)
        print msg
        print "*" * len(msg)

        settings_dict = dict(host_string=host_string, password=password)
        if 'ssh_key' in server and server['ssh_key']:
            settings_dict['key_filename'] = server['ssh_key']

        with _settings(**settings_dict):
            context['host'] = server['address']
            context['user'] = server['user']
            role_instances = []

            try:
                for role in server['roles']:
                    context['role'] = role
                    instance = role(prov, context)
                    role_instances.append(instance)
                    instance.provision()
            finally:
                for role in role_instances:
                    role.cleanup()

                for role in context['cleanup']:
                    role.cleanup()

        msg = "%s provisioned!" % host_string
        print
        print "*" * len(msg)
        print msg
        print "*" * len(msg)
        print