Exemplo n.º 1
0
 def run(self, context, args, kwargs, opargs):
     if self.up:
         context.submit_task(
             'network.interface.up',
             self.parent.primary_key,
             callback=lambda s, t: post_save(self.parent, s, t))
     else:
         context.submit_task(
             'network.interface.down',
             self.parent.primary_key,
             callback=lambda s, t: post_save(self.parent, s, t))
Exemplo n.º 2
0
 def run(self, context, args, kwargs, opargs):
     if self.up:
         context.submit_task(
             'network.interface.up',
             self.parent.primary_key,
             callback=lambda s, t: post_save(self.parent, s, t)
         )
     else:
         context.submit_task(
             'network.interface.down',
             self.parent.primary_key,
             callback=lambda s, t: post_save(self.parent, s, t)
         )
Exemplo n.º 3
0
Arquivo: boot.py Projeto: surajrav/cli
 def save(self, this, new=False):
     if new:
         return self.context.submit_task(
             'boot.environment.clone',
             this.entity['id'],
             callback=lambda s, t: post_save(this, s, t),
         )
     else:
         return self.context.submit_task(
             'boot.environment.update',
             this.orig_entity['id'],
             this.get_diff(),
             callback=lambda s, t: post_save(this, s, t))
Exemplo n.º 4
0
    def post_save(self, this, status, task, new):
        if status == 'FINISHED' and this.entity:
            service = self.context.call_sync('service.query',
                                             [('name', '=', self.type_name)],
                                             {'single': True})
            if service['state'] != 'RUNNING':
                action = 'created' if new else 'updated'
                self.context.output_queue.put(
                    _("Share '{0}' has been {1} but the service '{2}' is not currently "
                      "running, please enable the service with '/ service {2} config set enable=yes'"
                      .format(this.entity[self.primary_key_name], action,
                              self.type_name)))

        post_save(this, status, task)
Exemplo n.º 5
0
 def save(self, this, new=False):
     if new:
         self.context.submit_task(
             'boot.environment.clone',
             this.entity['id'],
             callback=lambda s, t: post_save(this, s, t),
             )
     else:
         self.context.submit_task(
             'boot.environment.update',
             this.orig_entity['id'],
             this.get_diff(),
             callback=lambda s, t: post_save(this, s, t)
             )
Exemplo n.º 6
0
    def save(self, this, new=False):
        if new:
            if 'timezone' not in this.entity['schedule']:
                this.entity['schedule']['timezone'] = self.context.call_sync(
                    'system.general.get_config')['timezone']
            self.context.submit_task(
                self.create_task,
                this.entity,
                callback=lambda s, t: post_save(this, s, t))
            return

        self.context.submit_task(self.update_task,
                                 this.orig_entity[self.save_key_name],
                                 this.get_diff(),
                                 callback=lambda s, t: post_save(this, s, t))
Exemplo n.º 7
0
    def save(self, this, new=False):
        if new:
            self.context.submit_task(
                self.create_task,
                this.entity,
                this.password,
                callback=lambda s, t: post_save(this, s, t))
            return

        self.context.submit_task(
            self.update_task,
            this.orig_entity[self.save_key_name],
            this.get_diff(),
            this.password,
            callback=lambda s, t: post_save(this, s, t))
Exemplo n.º 8
0
    def save(self, this, new=False):
        if new:
            self.context.submit_task(
                self.create_task,
                this.entity,
                this.password,
                callback=lambda s, t: post_save(this, s, t))
            return

        self.context.submit_task(
            self.update_task,
            this.orig_entity[self.save_key_name],
            this.get_diff(),
            this.password,
            callback=lambda s, t: post_save(this, s, t))
Exemplo n.º 9
0
    def save(self, this, new=False):
        if new:
            if 'timezone' not in this.entity['schedule']:
                this.entity['schedule']['timezone'] = self.context.call_sync('system.general.get_config')['timezone']
            self.context.submit_task(
                self.create_task,
                this.entity,
                callback=lambda s, t: post_save(this, s, t))
            return

        self.context.submit_task(
            self.update_task,
            this.orig_entity[self.save_key_name],
            this.get_diff(),
            callback=lambda s, t: post_save(this, s, t))
Exemplo n.º 10
0
 def post_save(self, this, status, task, new):
     if status == 'FINISHED' and this.entity:
         service = self.context.call_sync('service.query', [('name', '=', self.type_name)], {'single': True})
         if service['state'] != 'RUNNING':
             action = 'created' if new else 'updated'
             self.context.output_queue.put(_(
                 "Share '{0}' has been {1} but the service '{2}' is not currently "
                 "running, please enable the service with '/ service {2} config set enable=yes'".format(
                     this.entity[self.primary_key_name],
                     action,
                     self.type_name
                 )
             ))
             
     post_save(this, status, task)
Exemplo n.º 11
0
Arquivo: boot.py Projeto: surajrav/cli
    def run(self, context, args, kwargs, opargs):
        tid = context.submit_task(
            'boot.environment.activate',
            self.parent.entity['id'],
            callback=lambda s, t: post_save(self.parent, s, t))

        return TaskPromise(context, tid)
Exemplo n.º 12
0
    def run(self, context, args, kwargs, opargs):
        tid = context.submit_task(
            'network.interface.renew',
            self.parent.primary_key,
            callback=lambda s, t: post_save(self.parent, s, t))

        return TaskPromise(context, tid)
Exemplo n.º 13
0
 def run(self, context, args, kwargs, opargs):
     context.submit_task(
         'service.manage',
         self.parent.primary_key,
         self.action,
         callback=lambda s: post_save(self.parent, s)
     )
Exemplo n.º 14
0
    def save(self, this, new=False):
        assert not new

        self.context.submit_task('ipmi.update',
                                 this.entity['channel'],
                                 this.get_diff(),
                                 callback=lambda s, t: post_save(this, s, t))
Exemplo n.º 15
0
    def run(self, context, args, kwargs, opargs):
        name = self.parent.entity['name']
        tid = context.submit_task(
            'replication.sync',
            name,
            callback=lambda s, t: post_save(self.parent, s, t))

        return TaskPromise(context, tid)
Exemplo n.º 16
0
    def run(self, context, args, kwargs, opargs):
        tid = context.submit_task(
            'network.interface.renew',
            self.parent.primary_key,
            callback=lambda s, t: post_save(self.parent, s, t)
        )

        return TaskPromise(context, tid)
Exemplo n.º 17
0
 def save(self, this, new=False):
     if new:
         self.context.submit_task(
             'boot.environments.create',
             this.entity['id'],
             callback=lambda s: post_save(this, s),
             )
     else:
         return
Exemplo n.º 18
0
Arquivo: vm.py Projeto: 650elx/cli
 def run(self, context, args, kwargs, opargs):
     try:
         name = args[0]
     except IndexError:
         raise CommandException(_("Please specify the name of VM."))
     volume = kwargs.get('volume', None)
     if not volume:
         raise CommandException(_("Please specify which volume is containing a VM being imported."))
     context.submit_task('container.import', name, volume, callback=lambda s, t: post_save(self.parent, t))
Exemplo n.º 19
0
    def post_save(self, this, status, task, new):
        service_name = 'simulator'
        if status == 'FINISHED':
            service = self.context.call_sync('service.query',
                                             [('name', '=', service_name)],
                                             {'single': True})
            if service['state'] != 'RUNNING':
                if new:
                    action = "created"
                else:
                    action = "updated"

                self.context.output_queue.put(
                    _("Disk '{0}' has been {1} but the service '{2}' is not currently running, "
                      "please enable the service with '/ service {2} config set enable=yes'"
                      .format(this.entity['id'], action, service_name)))

        post_save(this, status, task)
Exemplo n.º 20
0
    def run(self, context, args, kwargs, opargs):
        id = self.parent.entity['id']
        tid = context.submit_task(
            'replication.sync',
            id,
            callback=lambda s, t: post_save(self.parent, s, t)
        )

        return TaskPromise(context, tid)
Exemplo n.º 21
0
    def save(self, this, new=False):
        assert not new

        self.context.submit_task(
            'ipmi.update',
            this.entity['channel'],
            this.get_diff(),
            callback=lambda s, t: post_save(this, s, t)
        )
Exemplo n.º 22
0
    def save(self, this, new=False):
        if new:
            newname = this.entity['id']
            if len(newname.split('/')) < 2:
                raise CommandException(_("Please specify name as a relative path starting from the dataset's parent volume."))

            self.context.submit_task(
                'volume.dataset.create',
                extend(this.entity, {'volume': self.parent.entity['id']}),
                callback=lambda s, t: post_save(this, s, t)
            )
            return

        self.context.submit_task(
            'volume.dataset.update',
            this.orig_entity['id'],
            this.get_diff(),
            callback=lambda s, t: post_save(this, s, t)
        )
Exemplo n.º 23
0
Arquivo: system.py Projeto: jceel/cli
    def run(self, context, args, kwargs, opargs):
        vol = kwargs.get('volume', None)
        if not vol:
            raise CommandException(_('Please specify a volume name'))

        tid = context.submit_task(
            'system_dataset.import',
            vol,
            callback=lambda s, t: post_save(self.parent, s, t))
        return TaskPromise(context, tid)
Exemplo n.º 24
0
    def save(self, this, new=False):
        if new:
            newname = this.entity['id']
            if len(newname.split('/')) < 2:
                raise CommandException(_("Please specify name as a relative path starting from the dataset's parent volume."))

            self.context.submit_task(
                'volume.dataset.create',
                extend(this.entity, {'volume': self.parent.entity['id']}),
                callback=lambda s, t: post_save(this, s, t)
            )
            return

        self.context.submit_task(
            'volume.dataset.update',
            this.orig_entity['id'],
            this.get_diff(),
            callback=lambda s, t: post_save(this, s, t)
        )
Exemplo n.º 25
0
    def run(self, context, args, kwargs, opargs):
        if not args and not kwargs:
            raise CommandException(_("Create requires more arguments, see 'help create' for more information"))
        if len(args) > 1:
            raise CommandException(_("Wrong syntax for create, see 'help create' for more information"))

        if len(args) == 1:
            kwargs[self.parent.primary_key.name] = args.pop(0)

        if 'name' not in kwargs:
            raise CommandException(_('Please specify a name for your replication link'))
        else:
            name = kwargs.pop('name')

        master = kwargs.pop('master')
        slave = kwargs.pop('slave')
        partners = [master, slave]

        for ip in context.call_sync('network.config.get_my_ips'):
            if ip in partners:
                break
        else:
            raise CommandException(_(
                'None of provided replication link partners {0}, {1} match any of machine\'s IPs'.format(master, slave)
            ))

        datasets = kwargs.pop('datasets', [])
        if isinstance(datasets, six.string_types):
            datasets = [datasets]
        bidirectional = read_value(kwargs.pop('bidirectional', False), ValueType.BOOLEAN)
        recursive = read_value(kwargs.pop('recursive', False), ValueType.BOOLEAN)
        replicate_services = read_value(kwargs.pop('replicate_services', False), ValueType.BOOLEAN)

        if replicate_services and not bidirectional:
            raise CommandException(_(
                'Replication of services is available only when bi-directional replication is selected'
            ))

        ns = SingleItemNamespace(None, self.parent)
        ns.orig_entity = query.wrap(copy.deepcopy(self.parent.skeleton_entity))
        ns.entity = query.wrap(copy.deepcopy(self.parent.skeleton_entity))

        ns.entity['name'] = name
        ns.entity['master'] = master
        ns.entity['partners'] = partners
        ns.entity['datasets'] = datasets
        ns.entity['bidirectional'] = bidirectional
        ns.entity['recursive'] = recursive
        ns.entity['replicate_services'] = replicate_services

        context.submit_task(
            self.parent.create_task,
            ns.entity,
            callback=lambda s, t: post_save(ns, s, t)
        )
Exemplo n.º 26
0
    def post_save(self, this, status, task, new):
        service_name = 'simulator'
        if status == 'FINISHED':
            service = self.context.call_sync('service.query', [('name', '=', service_name)], {'single': True})
            if service['state'] != 'RUNNING':
                if new:
                    action = "created"
                else:
                    action = "updated"

                self.context.output_queue.put(_(
                    "Disk '{0}' has been {1} but the service '{2}' is not currently running, "
                    "please enable the service with '/ service {2} config set enable=yes'".format(
                        this.entity['id'],
                        action,
                        service_name
                    )
                ))

        post_save(this, status, task)
Exemplo n.º 27
0
    def save(self, this, new=False, callback=None):
        if new:
            recursive = this.entity.pop('recursive', False)
            self.context.submit_task(
                self.create_task,
                this.entity, recursive,
                callback=callback or (lambda s, t: post_save(this, s, t))
            )
            return

        super(SnapshotsNamespace, self).save(this, new, callback)
Exemplo n.º 28
0
    def save(self, this, new=False, callback=None):
        if new:
            recursive = this.entity.pop('recursive', False)
            self.context.submit_task(
                self.create_task,
                this.entity, recursive,
                callback=callback or (lambda s, t: post_save(this, s, t))
            )
            return

        super(SnapshotsNamespace, self).save(this, new, callback)
Exemplo n.º 29
0
    def save(self, this, new=False, callback=None):
        if callback is None:
            callback = lambda s, t: post_save(this, s, t)

        if new:
            return self.context.submit_task(self.create_task,
                                            *this.get_create_args(),
                                            callback=callback)

        return self.context.submit_task(self.update_task,
                                        this.orig_entity[self.save_key_name],
                                        *this.get_update_args(),
                                        callback=callback)
Exemplo n.º 30
0
    def run(self, context, args, kwargs, opargs):
        try:
            name = args[0]
        except IndexError:
            raise CommandException(_("Please specify the name of VM."))
        volume = kwargs.get('volume', None)
        if not volume:
            raise CommandException(_("Please specify which volume is containing a VM being imported."))

        ns = get_item_stub(context, self.parent, name)

        tid = context.submit_task('vm.import', name, volume, callback=lambda s, t: post_save(ns, s, t))
        return EntityPromise(context, tid, ns)
Exemplo n.º 31
0
 def run(self, context, args, kwargs, opargs):
     try:
         name = args[0]
     except IndexError:
         raise CommandException(_("Please specify the name of VM."))
     volume = kwargs.get('volume', None)
     if not volume:
         raise CommandException(
             _("Please specify which volume is containing a VM being imported."
               ))
     context.submit_task('vm.import',
                         name,
                         volume,
                         callback=lambda s, t: post_save(self.parent, t))
Exemplo n.º 32
0
    def run(self, context, args, kwargs, opargs):
        try:
            name = args[0]
        except IndexError:
            raise CommandException(_("Please specify the name of share."))
        path = kwargs.get('path', None)
        if not path:
            raise CommandException(
                _("Please specify a valid path to your share."))

        context.submit_task('share.import',
                            path,
                            name,
                            self.parent.type_name.lower(),
                            callback=lambda s, t: post_save(self.parent, s, t))
Exemplo n.º 33
0
    def save(self, this, new=False, callback=None):
        if callback is None:
            callback = lambda s, t: post_save(this, s, t)

        if new:
            return self.context.submit_task(
                self.create_task,
                *this.get_create_args(),
                callback=callback)

        return self.context.submit_task(
            self.update_task,
            this.orig_entity[self.save_key_name],
            *this.get_update_args(),
            callback=callback)
Exemplo n.º 34
0
    def run(self, context, args, kwargs, opargs):
        try:
            name = args[0]
        except IndexError:
            raise CommandException(_("Please specify the name of share."))
        path = kwargs.get('path', None)
        if not path:
            raise CommandException(_("Please specify a valid path to your share."))

        context.submit_task(
            'share.import',
            path,
            name,
            self.parent.type_name.lower(),
            callback=lambda s, t: post_save(self.parent, s, t)
        )
Exemplo n.º 35
0
 def run(self, context, args, kwargs, opargs):
     try:
         new_be_name = args.pop(0)
     except IndexError:
         raise CommandException('Please provide a target name for the renaming')
     entity = self.parent.entity
     name_property = self.parent.get_mapping('name')
     old_be = entity['id']
     name_property.do_set(entity, new_be_name)
     self.parent.modified = True
     context.submit_task(
         'boot.environments.rename',
         old_be,
         new_be_name,
         callback=lambda s: post_save(self.parent, s)
     )
    def run(self, context, args, kwargs, opargs):
        if not self.parent.entity.get('bidirectional'):
            raise CommandException('This replication link is not bi-directional')

        name = self.parent.entity['name']
        partners = self.parent.entity['partners']
        master = self.parent.entity['master']
        for partner in partners:
            if partner != master:
                master = partner

        context.submit_task(
            'replication.update',
            name,
            {'master': master},
            callback=lambda s, t: post_save(self.parent, s, t)
        )
Exemplo n.º 37
0
    def run(self, context, args, kwargs, opargs):
        if not self.parent.entity.get('bidirectional'):
            raise CommandException('This replication link is not bi-directional')

        name = self.parent.entity['name']
        partners = self.parent.entity['partners']
        master = self.parent.entity['master']
        for partner in partners:
            if partner != master:
                master = partner
                break

        context.submit_task(
            'replication.update',
            name,
            {'master': master},
            callback=lambda s, t: post_save(self.parent, s, t)
        )
Exemplo n.º 38
0
    def save(self, this, new=False, callback=None):
        if callback is None:
            callback = lambda s: post_save(this, s)
        if new:
            self.context.submit_task(
                'network.interface.create',
                this.entity['type'],
                callback=callback
            )
            this.modified = False
            return

        self.context.submit_task(
            'network.interface.configure',
            this.entity['id'], this.get_diff(),
            callback=callback
        )
        this.modified = False
Exemplo n.º 39
0
    def run(self, context, args, kwargs, opargs):
        if len(args) == 0:
            raise CommandException(_("Please specify a disk"))
        disk = args[0]
        volume = self.parent.entity

        disk = correct_disk_path(disk)

        vdevs = list(iterate_vdevs(volume['topology']))
        guid = None
        for vdev in vdevs:
            if vdev['path'] == disk:
                guid = vdev['guid']
                break

        if guid is None:
            raise CommandException(_("Disk {0} is not part of the volume.".format(disk)))
        context.submit_task(
            'volume.vdev.online',
            self.parent.entity['id'],
            guid,
            callback=lambda s, t: post_save(self.parent, s, t)
        )
Exemplo n.º 40
0
    def run(self, context, args, kwargs, opargs):
        host = kwargs.get('host', None)
        name = q.get(self.parent.entity, 'names.0')

        if host:
            host = context.call_sync('docker.host.query', [('name', '=', host)], {'single': True, 'select': 'id'})
            if not host:
                raise CommandException(_('Docker host {0} not found'.format(kwargs.get('host'))))

            if host not in self.parent.entity['hosts']:
                raise CommandException(_('Image {0} does not exist on {1}'.format(
                    name,
                    kwargs.get('host')
                )))

        tid = context.submit_task(
            'docker.image.delete',
            name,
            host,
            callback=lambda s, t: post_save(self.parent, s, t)
        )

        return TaskPromise(context, tid)
Exemplo n.º 41
0
    def run(self, context, args, kwargs, opargs):
        if len(args) == 0:
            raise CommandException(_("Please specify a disk"))
        disk = args[0]
        volume = self.parent.entity

        disk = correct_disk_path(disk)

        vdevs = list(iterate_vdevs(volume['topology']))
        guid = None
        for vdev in vdevs:
            if vdev['path'] == disk:
                guid = vdev['guid']
                break

        if guid is None:
            raise CommandException(_("Disk {0} is not part of the volume.".format(disk)))
        context.submit_task(
            'volume.vdev.online',
            self.parent.entity['id'],
            guid,
            callback=lambda s, t: post_save(self.parent, s, t)
        )
Exemplo n.º 42
0
    def run(self, context, args, kwargs, opargs):
        name = self.parent.entity['name']
        compress = kwargs.pop('compress', None)
        encrypt = kwargs.pop('encrypt', None)
        throttle = kwargs.pop('throttle', None)
        transport_plugins = []

        if compress:
            if compress not in ['fast', 'default', 'best']:
                raise CommandException('Compression level must be selected as one of: fast, default, best')
            transport_plugins.append({
                'name': 'compress',
                'level': compress.upper()
            })

        if throttle:
            if not isinstance(throttle, int):
                raise CommandException('Throttle must be a number representing maximum transfer per second')
            transport_plugins.append({
                'name': 'throttle',
                'buffer_size': throttle
            })

        if encrypt:
            if encrypt not in ['AES128', 'AES192', 'AES256']:
                raise CommandException('Encryption type must be selected as one of: AES128, AES192, AES256')
            transport_plugins.append({
                'name': 'encrypt',
                'type': encrypt
            })

        context.submit_task(
            'replication.sync',
            name,
            transport_plugins,
            callback=lambda s, t: post_save(self.parent, s, t)
        )
Exemplo n.º 43
0
    def run(self, context, args, kwargs, opargs):
        if not args and not kwargs:
            raise CommandException(_(
                "create requires more arguments, see 'help create' for more information"
            ))
        if len(args) > 1:
            raise CommandException(_(
                "Wrong syntax for create, see 'help create' for more information"
            ))

        if len(args) == 1:
            if 'name' in kwargs:
                raise CommandException(_(
                    "Both implicit and explicit 'name' parameters are specified."
                ))
            else:
                kwargs[self.parent.primary_key.name] = args.pop(0)

        if 'name' not in kwargs:
            raise CommandException(_('Please specify a name for your snapshot'))
        else:
            name = kwargs.pop('name')

        descr = kwargs.pop('description', '')

        ns = get_item_stub(context, self.parent, name)

        tid = context.submit_task(
            self.parent.create_task,
            self.parent.parent.entity['id'],
            name,
            descr,
            callback=lambda s, t: post_save(ns, s, t)
        )

        return EntityPromise(context, tid, ns)
Exemplo n.º 44
0
 def save(self):
     return self.context.submit_task(
         self.update_task,
         self.get_diff(),
         callback=lambda s, t: post_save(self, s, t)
     )
Exemplo n.º 45
0
    def run(self, context, args, kwargs, opargs):
        if not kwargs.get('name') and not args:
            raise CommandException('name is a required property')

        if not kwargs.get('image'):
            raise CommandException('image is a required property')

        name = kwargs.get('name') or args[0]
        image = context.entity_subscribers['docker.image'].query(('names', 'in', kwargs['image']), single=True)
        if not image:
            image = q.query(DockerImageNamespace.default_images, ('name', '=', kwargs['image']), single=True)

        command = kwargs.get('command', [])
        command = command if isinstance(command, (list, tuple)) else [command]
        env = ['{0}={1}'.format(k, v) for k, v in kwargs.items() if k.isupper()]
        presets = image.get('presets') or {} if image else {}
        ports = presets.get('ports', [])
        volumes = presets.get('static_volumes', [])

        for k, v in kwargs.items():
            if k.startswith('volume:'):
                _, container_path = k.split(':', maxsplit=1)
                volumes.append({
                    'container_path': container_path,
                    'host_path': v,
                    'readonly': False
                })

            if k.startswith('port:'):
                _, portspec = k.split(':', maxsplit=1)
                port, protocol = portspec.split('/', maxsplit=1)
                protocol = protocol.upper()
                try:
                    port = int(port)
                except ValueError:
                    continue

                if protocol not in ('TCP', 'UDP'):
                    continue

                mapping = first_or_default(lambda m: m['container_port'] == port and m['protocol'] == protocol, ports)
                if mapping:
                    mapping['host_port'] = v
                    continue

                ports.append({
                    'container_port': port,
                    'host_port': v,
                    'protocol': protocol
                })

        if presets and len(presets.get('volumes', [])) != len(volumes):
            presets_volumes = set(i['container_path'] for i in presets['volumes'])
            entered_volumes = set(i['container_path'] for i in volumes)
            raise CommandException('Required volumes missing: {0}'.format(', '.join(presets_volumes - entered_volumes)))

        create_args = {
            'names': [name],
            'image': kwargs['image'],
            'host': kwargs.get('host'),
            'hostname': kwargs.get('hostname'),
            'command': command,
            'environment': env,
            'volumes': volumes,
            'ports': ports,
            'autostart': read_value(kwargs.get('autostart', 'no'), ValueType.BOOLEAN),
            'expose_ports': read_value(
                kwargs.get('expose_ports', q.get(presets, 'expose_ports', False)),
                ValueType.BOOLEAN
            ),
            'interactive': read_value(
                kwargs.get('interactive', q.get(presets, 'interactive', False)),
                ValueType.BOOLEAN
            )
        }

        ns = get_item_stub(context, self.parent, name)

        tid = context.submit_task(self.parent.create_task, create_args, callback=lambda s, t: post_save(ns, s, t))
        return EntityPromise(context, tid, ns)
Exemplo n.º 46
0
 def run(self, context, args, kwargs, opargs):
     if self.parent.entity.get('providers_presence', 'NONE') == 'NONE':
         raise CommandException('Volume is already fully locked')
     name = self.parent.entity['id']
     context.submit_task('volume.lock', name, callback=lambda s, t: post_save(self.parent, s, t))
Exemplo n.º 47
0
 def run(self, context, args, kwargs, opargs):
     if self.parent.entity.get('providers_presence', 'NONE') == 'NONE':
         raise CommandException('Volume is already fully locked')
     name = self.parent.entity['id']
     context.submit_task('volume.lock', name, callback=lambda s, t: post_save(self.parent, s, t))
Exemplo n.º 48
0
 def save(self):
     return self.context.submit_task(
         'service.configure',
         self.parent.entity['name'],
         self.get_diff(),
         callback=lambda s: post_save(self, s))
Exemplo n.º 49
0
 def save(self):
     return self.context.submit_task(
         'system_dataset.migrate',
         self.entity['pool'],
         callback=lambda s, t: post_save(self, s, t)
     )
Exemplo n.º 50
0
 def save(self):
     return self.context.submit_task(
         'system.general.update',
         self.entity,
         callback=lambda s, t: post_save(self, s, t)
     )
Exemplo n.º 51
0
 def save(self):
     return self.context.submit_task(
         'network.configure',
         self.get_diff(),
         callback=lambda s: post_save(self, s)
     )
Exemplo n.º 52
0
    def run(self, context, args, kwargs, opargs):
        if not args and not kwargs:
            raise CommandException(_("create requires more arguments, see 'help create' for more information"))
        if len(args) > 1:
            raise CommandException(_("Wrong syntax for create, see 'help create' for more information"))

        # This magic below make either `create foo` or `create name=foo` work
        if len(args) == 1:
            # However, do not allow user to specify name as both implicit and explicit parameter as this suggests a mistake
            if 'name' in kwargs:
                raise CommandException(_("Both implicit and explicit 'name' parameters are specified."))
            else:
                kwargs[self.parent.primary_key.name] = args.pop(0)

        if 'name' not in kwargs:
            raise CommandException(_('Please specify a name for your pool'))
        else:
            name = kwargs.pop('name')

        volume_type = kwargs.pop('type', 'auto')
        if volume_type not in VDEV_TYPES:
            raise CommandException(_(
                "Invalid volume type {0}.  Should be one of: {1}".format(volume_type, VDEV_TYPES)
            ))

        if 'disks' not in kwargs:
            raise CommandException(_("Please specify one or more disks using the disks property"))
        else:
            disks = kwargs.pop('disks')
            if isinstance(disks, six.string_types):
                disks = [disks]

        if read_value(kwargs.pop('encryption', False), ValueType.BOOLEAN) is True:
            encryption = True
            password = kwargs.get('password', None)
        else:
            encryption = False
            password = None

        cache_disks = kwargs.pop('cache', [])
        log_disks = kwargs.pop('log', [])
        if cache_disks is None:
            cache_disks = []
        if log_disks is None:
            log_disks = []
        if isinstance(cache_disks, six.string_types):
            cache_disks = [cache_disks]
        if isinstance(log_disks, six.string_types):
            log_disks = [log_disks]

        ns = SingleItemNamespace(None, self.parent)
        ns.orig_entity = query.wrap(copy.deepcopy(self.parent.skeleton_entity))
        ns.entity = query.wrap(copy.deepcopy(self.parent.skeleton_entity))

        disks, cache_disks, log_disks = check_disks(context, disks, cache_disks, log_disks)

        if len(disks) < DISKS_PER_TYPE[volume_type]:
            raise CommandException(_("Volume type {0} requires at least {1} disks".format(volume_type,
                                                                                          DISKS_PER_TYPE[volume_type])))
        if len(disks) > 1 and volume_type == 'disk':
            raise CommandException(_("Cannot create a volume of type disk with multiple disks"))

        if volume_type == 'auto':
            layout = kwargs.pop('layout', 'auto')
            if layout not in VOLUME_LAYOUTS:
                raise CommandException(_(
                    "Invalid layout {0}.  Should be one of: {1}".format(layout, list(VOLUME_LAYOUTS.keys()))
                ))
            else:
                if len(disks) < DISKS_PER_TYPE[VOLUME_LAYOUTS[layout]]:
                    raise CommandException(_("Volume layout {0} requires at least {1} disks".format(layout, DISKS_PER_TYPE[VOLUME_LAYOUTS[layout]])))

            context.submit_task('volume.create_auto', name, 'zfs', layout, disks, cache_disks, log_disks, encryption, password)
        else:
            ns.entity['id'] = name
            ns.entity['topology'] = {}
            ns.entity['topology']['data'] = []
            if volume_type == 'disk':
                ns.entity['topology']['data'].append(
                    {'type': 'disk', 'path': correct_disk_path(disks[0])})
            else:
                ns.entity['topology']['data'].append({
                    'type': volume_type,
                    'children': [{'type': 'disk', 'path': correct_disk_path(disk)} for disk in disks]
                })
            ns.entity['encrypted'] = encryption
            if len(cache_disks) > 0:
                if 'cache' not in ns.entity:
                    ns.entity['topology']['cache'] = []

                for disk in cache_disks:
                    ns.entity['topology']['cache'].append({
                        'type': 'disk',
                        'path': correct_disk_path(disk)
                    })

            if len(log_disks) > 0:
                if 'log' not in ns.entity:
                    ns.entity['topology']['log'] = []

                if len(log_disks) > 1:
                    ns.entity['topology']['log'].append({
                        'type': 'mirror',
                        'children': [{'type': 'disk', 'path': correct_disk_path(disk)} for disk in log_disks]
                    })
                else:
                    ns.entity['topology']['log'].append({
                        'type': 'disk',
                        'path': correct_disk_path(log_disks[0])
                    })

            context.submit_task(
                self.parent.create_task,
                ns.entity,
                password,
                callback=lambda s, t: post_save(ns, s, t))
Exemplo n.º 53
0
    def run(self, context, args, kwargs, opargs):
        if not args and not kwargs:
            raise CommandException(_("create requires more arguments, see 'help create' for more information"))
        if len(args) > 1:
            raise CommandException(_("Wrong syntax for create, see 'help create' for more information"))

        # This magic below make either `create foo` or `create name=foo` work
        if len(args) == 1:
            # However, do not allow user to specify name as both implicit and explicit parameter as this suggests a mistake
            if 'name' in kwargs:
                raise CommandException(_("Both implicit and explicit 'name' parameters are specified."))
            else:
                kwargs[self.parent.primary_key.name] = args.pop(0)

        if 'name' not in kwargs:
            raise CommandException(_('Please specify a name for your pool'))
        else:
            name = kwargs.pop('name')

        volume_type = kwargs.pop('type', 'auto')
        if volume_type not in VDEV_TYPES:
            raise CommandException(_(
                "Invalid volume type {0}.  Should be one of: {1}".format(volume_type, VDEV_TYPES)
            ))

        if 'disks' not in kwargs:
            raise CommandException(_("Please specify one or more disks using the disks property"))
        else:
            disks = kwargs.pop('disks')
            if isinstance(disks, six.string_types):
                disks = [disks]

        if read_value(kwargs.pop('encryption', False), ValueType.BOOLEAN) is True:
            encryption = True
            password = kwargs.get('password', None)
        else:
            encryption = False
            password = None

        cache_disks = kwargs.pop('cache', [])
        log_disks = kwargs.pop('log', [])
        if cache_disks is None:
            cache_disks = []
        if log_disks is None:
            log_disks = []
        if isinstance(cache_disks, six.string_types):
            cache_disks = [cache_disks]
        if isinstance(log_disks, six.string_types):
            log_disks = [log_disks]

        ns = SingleItemNamespace(None, self.parent)
        ns.orig_entity = query.wrap(copy.deepcopy(self.parent.skeleton_entity))
        ns.entity = query.wrap(copy.deepcopy(self.parent.skeleton_entity))

        disks, cache_disks, log_disks = check_disks(context, disks, cache_disks, log_disks)

        if disks != 'auto':
            if len(disks) < DISKS_PER_TYPE[volume_type]:
                raise CommandException(_("Volume type {0} requires at least {1} disks".format(
                    volume_type,
                    DISKS_PER_TYPE[volume_type]
                )))
            if len(disks) > 1 and volume_type == 'disk':
                raise CommandException(_("Cannot create a volume of type disk with multiple disks"))

        if volume_type == 'auto':
            layout = kwargs.pop('layout', 'auto')
            if layout not in VOLUME_LAYOUTS:
                raise CommandException(_(
                    "Invalid layout {0}.  Should be one of: {1}".format(layout, list(VOLUME_LAYOUTS.keys()))
                ))
            else:
                if disks != 'auto' and len(disks) < DISKS_PER_TYPE[VOLUME_LAYOUTS[layout]]:
                    raise CommandException(_("Volume layout {0} requires at least {1} disks".format(layout, DISKS_PER_TYPE[VOLUME_LAYOUTS[layout]])))

            context.submit_task('volume.create_auto', name, 'zfs', layout, disks, cache_disks, log_disks, encryption, password)
        else:
            ns.entity['id'] = name
            ns.entity['topology'] = {}
            ns.entity['topology']['data'] = []
            if volume_type == 'disk':
                ns.entity['topology']['data'].append(
                    {'type': 'disk', 'path': correct_disk_path(disks[0])})
            else:
                ns.entity['topology']['data'].append({
                    'type': volume_type,
                    'children': [{'type': 'disk', 'path': correct_disk_path(disk)} for disk in disks]
                })
            ns.entity['encrypted'] = encryption
            if len(cache_disks) > 0:
                if 'cache' not in ns.entity:
                    ns.entity['topology']['cache'] = []

                for disk in cache_disks:
                    ns.entity['topology']['cache'].append({
                        'type': 'disk',
                        'path': correct_disk_path(disk)
                    })

            if len(log_disks) > 0:
                if 'log' not in ns.entity:
                    ns.entity['topology']['log'] = []

                if len(log_disks) > 1:
                    ns.entity['topology']['log'].append({
                        'type': 'mirror',
                        'children': [{'type': 'disk', 'path': correct_disk_path(disk)} for disk in log_disks]
                    })
                else:
                    ns.entity['topology']['log'].append({
                        'type': 'disk',
                        'path': correct_disk_path(log_disks[0])
                    })

            context.submit_task(
                self.parent.create_task,
                ns.entity,
                password,
                callback=lambda s, t: post_save(ns, s, t))
Exemplo n.º 54
0
    def run(self, context, args, kwargs, opargs):
        if not args and not kwargs:
            raise CommandException(_("Pull requires more arguments, see 'help pull' for more information"))
        if len(args) > 1:
            raise CommandException(_("Wrong syntax for pull, see 'help create' for more information"))

        if len(args) == 1:
            if 'name' in kwargs:
                raise CommandException(_("Both implicit and explicit 'name' parameters are specified."))
            else:
                kwargs['name'] = args.pop(0)

        if 'name' not in kwargs:
            raise CommandException(_('Please specify image name'))
        else:
            name = kwargs.pop('name')

        host = kwargs.get('host')
        hostid = None
        if host:
            hostid = context.entity_subscribers['docker.host'].query(('name', '=', host), single=True, select='id')

        ns = get_item_stub(context, self.parent, name)

        tid = context.submit_task('docker.image.pull', name, hostid, callback=lambda s, t: post_save(ns, s, t))

        return EntityPromise(context, tid, ns)
Exemplo n.º 55
0
 def save(self):
     return self.context.submit_task(
         'system.general.update',
         self.entity,
         callback=lambda s, t: post_save(self, s, t)
     )
Exemplo n.º 56
0
 def save(self):
     return self.context.submit_task(
         self.update_task,
         self.get_diff(),
         callback=lambda s, t: post_save(self, s, t))
Exemplo n.º 57
0
 def save(self):
     self.context.submit_task(
         'system_dataset.migrate',
         self.entity['pool'],
         callback=lambda s, t: post_save(self, s, t)
     )
Exemplo n.º 58
0
 def run(self, context, args, kwargs, opargs):
     vol = kwargs.get('volume', None)
     if not vol:
         raise CommandException(_('Please specify a volume name'))
     context.submit_task('system_dataset.import', vol, callback=lambda s: post_save(self.parent, s))