示例#1
0
 def to_dict(cls, app):
     ret = super(Get, cls).to_dict(app)
     configure = get_action('configure')
     ret['config'] = configure.list_config(app)
     ret['is_running'] = app_is_running(app)
     ret['autostart'] = ucr_get('%s/autostart' % app.id, 'yes')
     return ret
 def _set_config_via_tool(self, app, set_vars):
     if not app.docker:
         return super(Configure, self)._set_config_via_tool(app, set_vars)
     if not app_is_running(app):
         self.warn('Cannot write settings while %s is not running' % app)
         return
     docker = self._get_docker(app)
     if not docker.execute('which', 'ucr').returncode == 0:
         self.warn(
             'ucr cannot be found, falling back to changing the database file directly'
         )
         self._set_config_directly(app, set_vars)
         return
     self.log('Setting registry variables for %s' % app.id)
     set_args = []
     unset_args = []
     for key, value in set_vars.iteritems():
         if value is None:
             unset_args.append(key)
         else:
             set_args.append('%s=%s' % (key, value))
     if set_args:
         docker.execute('ucr', 'set', *set_args)
     if unset_args:
         docker.execute('ucr', 'unset', *unset_args)
 def _run_configure_script(self, app, action):
     success = super(Configure, self)._run_configure_script(app, action)
     if success is not False and app.docker and app_is_running(app):
         success = self._execute_container_script(app,
                                                  'configure',
                                                  credentials=False,
                                                  cmd_args=[action])
     return success
示例#4
0
 def _set_config(self, app, set_vars):
     if not app_is_running(app):
         self.fatal('%s is not running. Cannot configure the app' % app.id)
         return
     if not set_vars:
         return
     self._set_config_via_tool(app, set_vars)
     self._run_configure_script(app)
示例#5
0
 def set_value(self, app, value, together_config_settings, part):
     if part == 'outside':
         return self._write_file_content(self.filename, value)
     else:
         if not app_is_running(app):
             settings_logger.error(
                 'Cannot write %s while %s is not running' %
                 (self.name, app))
             return
         from univention.appcenter.docker import Docker
         docker = Docker(app)
         return self._write_file_content(docker.path(self.filename), value)
示例#6
0
 def get_value(self, app, phase='Settings'):
     if self.is_outside(app):
         value = self._read_file_content(self.filename)
     else:
         if app_is_running(app):
             from univention.appcenter.docker import Docker
             docker = Docker(app)
             value = self._read_file_content(docker.path(self.filename))
         else:
             settings_logger.info('Cannot read %s while %s is not running' %
                                  (self.name, app))
             value = None
     if value is None and phase == 'Install':
         settings_logger.info('Falling back to initial value for %s' %
                              self.name)
         value = self.get_initial_value(app)
     return value
示例#7
0
	def config(self, app, phase):
		self.ucr.load()
		autostart = self.ucr.get('%s/autostart' % app.id, 'yes')
		is_running = app_is_running(app)
		values = {}
		for setting in app.get_settings():
			if phase in setting.show or phase in setting.show_read_only:
				value = setting.get_value(app, phase)
				if isinstance(setting, FileSetting) and not isinstance(setting, PasswordFileSetting):
					if value:
						value = encodestring(value).rstrip()
				values[setting.name] = value
		return {
			'autostart': autostart,
			'is_running': is_running,
			'values': values,
		}
 def main(self, args):
     docker = self._get_docker(args.app)
     docker_exec = ['docker', 'exec', '-u', args.user]
     commands = args.commands[:]
     if not commands:
         commands = shlex.split(args.app.docker_shell_command)
         args.interactive = True
         args.tty = True
     if args.interactive:
         docker_exec.append('-i')
     if args.tty:
         docker_exec.append('-t')
     if not commands:
         raise ShellNoCommandError()
     if not app_is_running(args.app):
         raise ShellAppNotRunning(args.app)
     self.debug('Calling %s' % commands[0])
     return subprocess.call(docker_exec + [docker.container] + commands)
 def _get_config(self, app, phase):
     autostart = self.ucr.get('%s/autostart' % app.id, 'yes')
     is_running = app_is_running(app)
     values = {}
     for setting in app.get_settings():
         if phase in setting.show or phase in setting.show_read_only:
             value = setting.get_value(app, phase)
             if isinstance(setting, FileSetting) and not isinstance(
                     setting, PasswordFileSetting):
                 if value:
                     value = b64encode(
                         value.encode('utf-8')).decode('ascii')
             values[setting.name] = value
     return {
         'autostart': autostart,
         'is_running': is_running,
         'values': values,
     }
示例#10
0
 def main(self, args):
     docker = self._get_docker(args.app)
     docker_exec = ['docker', 'exec']
     commands = args.commands[:]
     if not commands:
         commands = shlex.split(args.app.docker_shell_command)
         args.interactive = True
         args.tty = True
     if args.interactive:
         docker_exec.append('-i')
     if args.tty:
         docker_exec.append('-t')
     if not commands:
         raise Abort('Cannot run command: No command specified')
     if not app_is_running(args.app):
         raise Abort(
             'Cannot run command: %s is not running in a container' %
             args.app.id)
     self.debug('Calling %s' % commands[0])
     return subprocess.call(docker_exec + [docker.container] + commands)
示例#11
0
 def get_value(self, app, phase='Settings'):
     '''Get the current value for this Setting. Easy implementation'''
     if self.is_outside(app):
         value = ucr_get(self.name)
     else:
         if app_is_running(app):
             from univention.appcenter.actions import get_action
             configure = get_action('configure')
             ucr = configure._get_app_ucr(app)
             value = ucr.get(self.name)
         else:
             settings_logger.info('Cannot read %s while %s is not running' %
                                  (self.name, app))
             value = None
     try:
         value = self.sanitize_value(app, value)
     except SettingValueError:
         settings_logger.info('Cannot use %r for %s' % (value, self.name))
         value = None
     if value is None and phase == 'Install':
         settings_logger.info('Falling back to initial value for %s' %
                              self.name)
         value = self.get_initial_value(app)
     return value