Beispiel #1
0
 def run_host(self, hostname):
     if hostname in ['127.0.0.1', 'localhost', 'localhost.localdomain']:
         server = Server.objects.first()
     else:
         server = get_object_or_none(Server, hostname=hostname)
     vars = {}
     if server:
         vars['vpn_network'] = str(server.network)
         vars['vpn_name'] = server.name
         vars['vpn_port'] = server.port
         vars['vpn_config'] = server.render_to_string()
         vars['ansible_ssh_user'] = '******'
     vars_json = json.dumps(vars, indent=4)
     print(vars_json)
Beispiel #2
0
 def client(self, name, owner_email):
     assert self._fixture.admin, 'Admin user is required'
     user = get_object_or_none(User, email=owner_email)
     assert user, 'Owner user {} doesnt exist'.format(owner_email)
     assert user in self._fixture.users or user == self._fixture.admin, 'User must be created by Given'
     assert self._fixture.server, 'Server is required'
     context = dict(owner=user, server=self._fixture.server)
     client_dto = dict(name=name)
     create_serializer = CreateClientSerializer(data=client_dto,
                                                context=context)
     create_serializer.is_valid(raise_exception=True)
     client = create_serializer.save()
     self._fixture.clients.append(client)
     return self
Beispiel #3
0
    def run(self, *args, **options):
        client = get_object_or_none(Client,
                                    cert__common_name=self.option_common_name)
        if not client:
            raise CommandError(
                "Client with CN={common_name} does not exist".format(
                    common_name=self.option_common_name))

        options = 'ifconfig-push 172.30.0.199 255.255.0.0\n'

        if self.option_output_file:
            self.write_to_file(options)
        else:
            print(options)
Beispiel #4
0
    def run(self, *args, **options):
        user_settings = UserSettings()
        if user_settings.has_settings_file and not self.option_preview and not self.option_force:
            self.warn('Config file already exist. Skipping.')
        else:
            admin = get_object_or_none(User, is_superuser=True)
            new_settings = DEFAULT_USER_SETTINGS.copy()
            new_settings['secret_key'] = self.create_secret_key()
            new_settings['development'] = self.option_development
            new_settings['email']['enabled'] = not self.option_no_smtp
            new_settings['email'][
                'server_from'] = admin.email if admin is not None else ''
            new_settings['email']['admin_emails'] = [
                admin.email
            ] if admin is not None else []
            new_settings['database'].update(
                **{
                    'ENGINE': 'django.db.backends.sqlite3',
                    'NAME': get_data_path('db/db.sqlite3'),
                })

            existing_email_settings = self._get_existing_email_settings()
            new_settings['email'].update(existing_email_settings)

            options_email_settings = self._get_options_email_settings()
            new_settings['email'].update(options_email_settings)

            if self.option_development:
                new_settings['configured'] = True
                new_settings['debug_toolbar_enabled'] = True

            if self.option_accept:
                self.log('Automatically accepting default configuration.')
                new_settings['configured'] = True

            if self.option_preview:
                settings_json = json.dumps(new_settings, indent=4)
                print(settings_json)
            else:
                user_settings = UserSettings(settings=new_settings)
                user_settings.write()

            if self.option_development:
                self.log(
                    'Created configuration file {file} (development)'.format(
                        file=user_settings.settings_file_path))
            else:
                self.log('Created configuration file {file}'.format(
                    file=user_settings.settings_file_path))