コード例 #1
0
ファイル: sync.py プロジェクト: AsherBond/opennode-knot
 def execute_sync_action(self, hostname, compute):
     log.msg("Syncing started: '%s' (%s)" % (hostname, str(compute)), system='sync')
     curtime = datetime.now().isoformat()
     syncaction = SyncAction(compute)
     deferred = syncaction.execute(DetachedProtocol(), object())
     self.outstanding_requests[str(compute)] = [deferred, curtime, 0, defer.Deferred()]
     deferred.addCallback(self.handle_success, 'synchronization', hostname, compute, 'suspicious')
     deferred.addErrback(self.handle_remote_error, hostname, compute, 'suspicious')
     deferred.addErrback(self.handle_error, 'Synchronization', hostname, compute, 'suspicious')
     return deferred
コード例 #2
0
ファイル: sync.py プロジェクト: opennode/opennode-knot
 def execute_sync_action(self, hostname, compute):
     log.msg("Syncing started: '%s' (%s)" % (hostname, str(compute)),
             system='sync')
     curtime = datetime.now().isoformat()
     syncaction = SyncAction(compute)
     deferred = syncaction.execute(DetachedProtocol(), object())
     self.outstanding_requests[str(compute)] = [
         deferred, curtime, 0, defer.Deferred()
     ]
     deferred.addCallback(self.handle_success, 'synchronization', hostname,
                          compute, 'suspicious')
     deferred.addErrback(self.handle_remote_error, hostname, compute,
                         'suspicious')
     deferred.addErrback(self.handle_error, 'Synchronization', hostname,
                         compute, 'suspicious')
     return deferred
コード例 #3
0
ファイル: compute.py プロジェクト: AsherBond/opennode-knot
 def execute(self, cmd, args):
     yield BaseHostRequestAction.execute(self, cmd, args)
     hostname = yield db.get(self.context, 'hostname')
     # Acceptance of a new HN should trigger its syncing
     uuid = yield register_machine(hostname, mgt_stack=ISaltInstalled)
     cmd.write('Host %s accepted. Syncing shortly...\n' % hostname)
     log.msg('Host %s accepted. Syncing in 5 seconds...' % hostname, system='action-accept')
     yield async_sleep(5)
     compute = yield get_machine_by_uuid(uuid)
     assert compute is not None, 'Machine not found after accept: %s' % uuid
     log.msg('Syncing NOW...', system='action-accept')
     syncaction = SyncAction(compute)
     syncaction._do_not_enqueue = False
     args = argparse.Namespace()
     args.full = True
     yield syncaction.execute(DetachedProtocol(), args)
コード例 #4
0
 def execute(self, cmd, args):
     yield BaseHostRequestAction.execute(self, cmd, args)
     hostname = yield db.get(self.context, 'hostname')
     # Acceptance of a new HN should trigger its syncing
     uuid = yield register_machine(hostname, mgt_stack=ISaltInstalled)
     cmd.write('Host %s accepted. Syncing shortly...\n' % hostname)
     log.msg('Host %s accepted. Syncing in 5 seconds...' % hostname,
             system='action-accept')
     yield async_sleep(5)
     compute = yield get_machine_by_uuid(uuid)
     assert compute is not None, 'Machine not found after accept: %s' % uuid
     log.msg('Syncing NOW...', system='action-accept')
     syncaction = SyncAction(compute)
     syncaction._do_not_enqueue = False
     args = argparse.Namespace()
     args.full = True
     yield syncaction.execute(DetachedProtocol(), args)
コード例 #5
0
    def _sync_vms_transact(self, remote_vms):
        local_vms = [i for i in self.context.listcontent() if IVirtualCompute.providedBy(i)]

        remote_uuids = set(i['uuid'] for i in remote_vms)
        local_uuids = set(i.__name__ for i in local_vms)

        root = db.get_root()['oms_root']
        machines = root['machines']

        for vm_uuid in remote_uuids.difference(local_uuids):
            remote_vm = [rvm for rvm in remote_vms if rvm['uuid'] == vm_uuid][0]

            existing_machine = follow_symlinks(machines['by-name'][remote_vm['name']])
            if existing_machine:
                # XXX: this VM is a nested VM, for now let's hack it this way
                new_compute = Symlink(existing_machine.__name__, existing_machine)
                self.context._add(new_compute)
            else:
                log.msg('Adding virtual compute %s...' % vm_uuid,
                        system='v12n-sync', logLevel=logging.WARNING)
                new_compute = Compute(unicode(remote_vm['name']), unicode(remote_vm['state']))
                new_compute.__name__ = vm_uuid
                new_compute.template = unicode(remote_vm['template'])
                alsoProvides(new_compute, IVirtualCompute)
                alsoProvides(new_compute, IDeployed)

                # for now let's force new synced computes to not have salt installed
                # XXX: not sure if removing a parent interface will remove the child also
                noLongerProvides(new_compute, IManageable)
                self.context.add(new_compute)

        for vm_uuid in remote_uuids.intersection(local_uuids):
            noLongerProvides(self.context[vm_uuid], IUndeployed)
            alsoProvides(self.context[vm_uuid], IDeployed)

        for vm_uuid in local_uuids.difference(remote_uuids):
            if IDeploying.providedBy(self.context[vm_uuid]):
                log.msg("Don't delete undeployed VM while in IDeploying state", system='v12n')
                continue

            noLongerProvides(self.context[vm_uuid], IDeployed)
            alsoProvides(self.context[vm_uuid], IUndeployed)
            self.context[vm_uuid].state = u'inactive'

            if get_config().getboolean('sync', 'delete_on_sync'):
                log.msg("Deleting compute %s" % vm_uuid, system='v12n-sync', logLevel=logging.WARNING)
                compute = self.context[vm_uuid]
                del self.context[vm_uuid]
                handle(compute, ModelDeletedEvent(self.context))

        # TODO: eliminate cross-import between compute and v12ncontainer
        from opennode.knot.backend.compute import ICompute
        from opennode.knot.backend.syncaction import SyncAction

        # sync each vm
        for compute in self.context.listcontent():
            if not IVirtualCompute.providedBy(compute):
                continue

            log.msg('Attempting to sync %s' % compute, system='sync-vms')
            if not ICompute.providedBy(compute.__parent__.__parent__):
                log.msg('Inconsistent data: %s, Compute is expected. Attempting to fix %s'
                        % (compute.__parent__.__parent__, compute),
                        system='sync-vms', logLevel=logging.WARNING)

                compute.__parent__ = self.context

                log.msg('Fixing %s %s' % (compute,
                                          'successful!'
                                          if ICompute.providedBy(compute.__parent__.__parent__)
                                          else 'failed!'),
                        system='sync-vms', logLevel=logging.WARNING)

                if not ICompute.providedBy(compute.__parent__.__parent__):
                    return

            action = SyncAction(compute)

            matching = [rvm for rvm in remote_vms if rvm['uuid'] == compute.__name__]

            if not matching:
                continue

            remote_vm = matching[0]

            # todo delegate all this into the action itself
            default_console = action._default_console()
            action._sync_consoles()
            action.sync_owner_transact(remote_vm)
            action.sync_vm(remote_vm)
            action.create_default_console(default_console)