示例#1
0
def _init(dispatcher, plugin):
    # Register Schemas
    plugin.register_schema_definition('update', {
        'type': 'object',
        'properties': {
            'train': {'type': 'string'},
            'check_auto': {'type': 'boolean'},
            'update_server': {'type': 'string', 'readOnly': True},
        },
    })

    plugin.register_schema_definition('update-progress', h.object(properties={
        'operation': h.enum(str, ['DOWNLOADING', 'INSTALLING']),
        'details': str,
        'indeterminate': bool,
        'percent': int,
        'reboot': bool,
        'pkg_name': str,
        'pkg_version': str,
        'filename': str,
        'filesize': int,
        'num_files_done': int,
        'num_files_total': int,
        'error': bool,
        'finished': bool,
    }))

    plugin.register_schema_definition('update-ops', {
        'type': 'object',
        'properties': {
            'new_name': {'type': 'string'},
            'previous_version': {'type': 'string'},
            'operation': {
                'type': 'string',
                'enum': ['delete', 'install', 'upgrade']
            },
            'new_version': {'type': 'string'},
            'previous_name': {'type': 'string'},
        }
    })

    plugin.register_schema_definition('update-info', {
        'type': 'object',
        'properties': {
            'notes': {'type': 'object'},
            'notice': {'type': 'string'},
            'changelog': {'type': 'string'},
            'operations': {'$ref': 'update-ops'},
        }
    })

    plugin.register_schema_definition('update-train', {
        'type': 'object',
        'properties': {
            'name': {'type': 'string'},
            'description': {'type': 'string'},
            'sequence': {'type': 'string'},
            'current': {'type': 'boolean'},
        }
    })

    # Register providers
    plugin.register_provider("update", UpdateProvider)

    # Register task handlers
    plugin.register_task_handler("update.configure", UpdateConfigureTask)
    plugin.register_task_handler("update.check", CheckUpdateTask)
    plugin.register_task_handler("update.download", DownloadUpdateTask)
    plugin.register_task_handler("update.manual", UpdateManualTask)
    plugin.register_task_handler("update.update", UpdateApplyTask)
    plugin.register_task_handler("update.verify", UpdateVerifyTask)

    # Register Event Types
    plugin.register_event_type('update.in_progress', schema=h.ref('update-progress'))
    plugin.register_event_type('update.changed')

    # Register reources
    plugin.register_resource(Resource(update_resource_string), ['system'])

    # Get the Update Cache (if any) at system boot (and hence in init here)
    generate_update_cache(dispatcher)
示例#2
0
def _init(dispatcher, plugin):
    # Register Schemas
    plugin.register_schema_definition(
        'update', {
            'type': 'object',
            'properties': {
                'train': {
                    'type': 'string'
                },
                'check_auto': {
                    'type': 'boolean'
                },
                'update_server': {
                    'type': 'string',
                    'readOnly': True
                },
            },
        })

    plugin.register_schema_definition(
        'update-progress',
        h.object(
            properties={
                'operation': h.enum(str, ['DOWNLOADING', 'INSTALLING']),
                'details': str,
                'indeterminate': bool,
                'percent': int,
                'reboot': bool,
                'pkg_name': str,
                'pkg_version': str,
                'filename': str,
                'filesize': int,
                'num_files_done': int,
                'num_files_total': int,
                'error': bool,
                'finished': bool,
            }))

    plugin.register_schema_definition(
        'update-ops', {
            'type': 'object',
            'properties': {
                'new_name': {
                    'type': 'string'
                },
                'previous_version': {
                    'type': 'string'
                },
                'operation': {
                    'type': 'string',
                    'enum': ['delete', 'install', 'upgrade']
                },
                'new_version': {
                    'type': 'string'
                },
                'previous_name': {
                    'type': 'string'
                },
            }
        })

    plugin.register_schema_definition(
        'update-info', {
            'type': 'object',
            'properties': {
                'notes': {
                    'type': 'object'
                },
                'notice': {
                    'type': 'string'
                },
                'changelog': {
                    'type': 'string'
                },
                'operations': {
                    '$ref': 'update-ops'
                },
            }
        })

    plugin.register_schema_definition(
        'update-train', {
            'type': 'object',
            'properties': {
                'name': {
                    'type': 'string'
                },
                'description': {
                    'type': 'string'
                },
                'sequence': {
                    'type': 'string'
                },
                'current': {
                    'type': 'boolean'
                },
            }
        })

    # Register providers
    plugin.register_provider("update", UpdateProvider)

    # Register task handlers
    plugin.register_task_handler("update.configure", UpdateConfigureTask)
    plugin.register_task_handler("update.check", CheckUpdateTask)
    plugin.register_task_handler("update.download", DownloadUpdateTask)
    plugin.register_task_handler("update.manual", UpdateManualTask)
    plugin.register_task_handler("update.update", UpdateApplyTask)
    plugin.register_task_handler("update.verify", UpdateVerifyTask)

    # Register Event Types
    plugin.register_event_type('update.in_progress',
                               schema=h.ref('update-progress'))
    plugin.register_event_type('update.changed')

    # Register reources
    plugin.register_resource(Resource(update_resource_string), ['system'])

    # Get the Update Cache (if any) at system boot (and hence in init here)
    generate_update_cache(dispatcher)
示例#3
0
        try:
            if type(rc_scripts) is unicode:
                system("/usr/sbin/service", rc_scripts, 'onerestart')

            if type(rc_scripts) is list:
                for i in rc_scripts:
                    system("/usr/sbin/service", i, 'onerestart')
        except SubprocessException, e:
            pass


@description("Provides functionality to start, stop, restart or reload service")
@accepts(
    str,
    h.enum(str, ['start', 'stop', 'restart', 'reload'])
)
class ServiceManageTask(Task):
    def describe(self, name, action):
        return "{0}ing service {1}".format(action.title(), name)

    def verify(self, name, action):
        if not self.datastore.exists('service_definitions', ('name', '=', name)):
            raise VerifyException(errno.ENOENT, 'Service {0} not found'.format(name))

        return ['system']

    def run(self, name, action):
        service = self.datastore.get_one('service_definitions', ('name', '=', name))
        rc_scripts = service['rcng'].get('rc-scripts')
        try: