if not os.path.exists(disk['path']):
            with open(disk['path'], 'w') as f:
                f.truncate(disk['mediasize'])

        self.datastore.insert('simulator.disks', disk)
        self.dispatcher.call_sync('etcd.generation.generate_group', 'ctl')
        self.dispatcher.call_sync('service.reload', 'ctl')


@description("Configures the given Simulated Disk ID with the specified parameters")
@accepts(
    str,
    h.all_of(
        h.ref('simulator-disk'),
        h.no(h.required('id'))
    )
)
class ConfigureFakeDisk(Task):
    def verify(self, id, updated_params):
        if not self.datastore.exists('simulator.disks', ('id', '=', id)):
            raise VerifyException(errno.ENOENT, 'Disk {0} not found'.format(id))

        return ['system']

    def run(self, id, updated_params):
        disk = self.datastore.get_by_id('simulator.disks', id)
        disk.update(updated_params)
        self.datastore.update('simulator.disks', id, disk)
        self.dispatcher.call_sync('etcd.generation.generate_group', 'ctl')
        self.dispatcher.call_sync('service.reload', 'ctl')

@description('Provides information about calendar tasks')
class CalendarTasksProvider(Provider):
    @query('CalendarTask')
    @generator
    def query(self, filter=None, params=None):
        return q.query(self.dispatcher.call_sync('scheduler.management.query'),
                       *(filter or []),
                       stream=True,
                       **(params or {}))


@accepts(
    h.all_of(h.ref('CalendarTask'), h.required('name'),
             h.no(h.required('status'))))
@returns(str)
@description('Creates a calendar task')
class CreateCalendarTask(Task):
    @classmethod
    def early_describe(cls):
        return "Creating calendar task"

    def describe(self, task):
        return TaskDescription("Creating calendar task {name}",
                               name=task['name'])

    def verify(self, task):
        return ['system']

    def run(self, task):
from freenas.dispatcher.rpc import RpcException, description, accepts, returns
from freenas.dispatcher.rpc import SchemaHelper as h
from task import Provider, Task, VerifyException, TaskException, query
from lib.system import system, SubprocessException


class CalendarTasksProvider(Provider):
    @query('calendar-task')
    def query(self, filter=None, params=None):
        return self.dispatcher.call_sync('scheduler.management.query', filter, params)


@accepts(
    h.all_of(
        h.ref('calendar-task'),
        h.no(h.required('status'))
    )
)
@returns(str)
class CreateCalendarTask(Task):
    def verify(self, task):
        return ['system']

    def run(self, task):
        try:
            tid = self.dispatcher.call_sync('scheduler.management.add', task)
        except RpcException:
            raise

        self.dispatcher.dispatch_event('calendar_task.changed', {
            'operation': 'create',
Beispiel #4
0
            return obj

        return q.query(
            self.dispatcher.call_sync('scheduler.management.query'),
            *(filter or []),
            stream=True,
            **(params or {}),
            callback=extend
        )


@accepts(
    h.all_of(
        h.ref('CalendarTask'),
        h.required('name'),
        h.no(h.required('status'))
    )
)
@returns(str)
@description('Creates a calendar task')
class CreateCalendarTask(Task):
    @classmethod
    def early_describe(cls):
        return "Creating calendar task"

    def describe(self, task):
        return TaskDescription("Creating calendar task {name}", name=task['name'])

    def verify(self, task):
        return ['system']
Beispiel #5
0
        if not os.path.exists(disk['path']):
            with open(disk['path'], 'w') as f:
                f.truncate(disk['mediasize'])

        self.datastore.insert('simulator.disks', disk)
        self.dispatcher.call_sync('etcd.generation.generate_group', 'ctl')
        self.dispatcher.call_sync('service.reload', 'ctl')


@description("Configures the given Simulated Disk ID with the specified parameters")
@accepts(
    str,
    h.all_of(
        h.ref('SimulatorDisk'),
        h.no(h.required('id'))
    )
)
class ConfigureFakeDisk(Task):
    @classmethod
    def early_describe(cls):
        return "Updating simulated disk"

    def describe(self, id, updated_params):
        disk = self.datastore.get_by_id('simulator.disks', id)
        return TaskDescription("Updating simulated disk {name}", name=disk.get('path', id) if disk else id)

    def verify(self, id, updated_params):
        return ['system-dataset']

    def run(self, id, updated_params):
Beispiel #6
0
        os.close(fd)

    def get_status(self):
        if not self.started:
            return TaskStatus(0, 'Erasing disk...')

        return TaskStatus((self.mediasize - self.remaining) / float(self.mediasize), 'Erasing disk...')


@description("Configures online disk parameters")
@accepts(
    str,
    h.all_of(
        h.ref('disk'),
        h.no(h.required('name', 'serial', 'path', 'id', 'mediasize', 'status', 'description'))
    )
)
class DiskConfigureTask(Task):
    def verify(self, id, updated_fields):
        disk = self.datastore.get_by_id('disks', id)
        errors = []

        if not disk:
            raise VerifyException(errno.ENOENT, 'Disk {0} not found'.format(id))

        if not self.dispatcher.call_sync('disks.is_online', disk['path']):
            raise VerifyException(errno.EINVAL, 'Cannot configure offline disk')

        if not disk['status']['smart_capable']:
            if 'smart' in updated_fields: