Ejemplo n.º 1
0
def allocate_virtual_compute_from_hangar(model, event):
    if not IVirtualizationContainer.providedBy(model.__parent__):
        return

    if IDeployed.providedBy(model):
        return

    auto_allocate = get_config().getboolean('vms', 'auto_allocate', True)

    if not auto_allocate:
        return

    if IHangar.providedBy(model.__parent__.__parent__):
        action = AllocateAction
        msg = 'Allocated compute %s'
    elif ICompute.providedBy(model.__parent__.__parent__):
        action = DeployAction
        msg = 'Deployed compute %s'
    else:
        return

    try:
        path = canonical_path(model)
        owner = model.__owner__
        ul = UserLogger(subject=model, owner=owner)
        log.msg('Attempting %s for %s (%s, %s)' % (action.__name__, model, path, owner),
                system='create-event')
        d = task.deferLater(reactor, 2.0, virtual_compute_action, action, path, event)
        d.addCallback(lambda r: ul.log(msg % path))
        if not get_config().getboolean('stats', 'only_report_on_sync', True):
            d.addCallback(lambda r: defer.maybeDeferred(getUtility(IUserStatisticsProvider).update, owner))
        d.addErrback(log.err)
    except Exception:
        log.err(system='create-event')
Ejemplo n.º 2
0
 def allowed_classes_gen(item):
     from opennode.knot.model.machines import Machines
     from opennode.knot.model.virtualizationcontainer import IVirtualizationContainer
     yield isinstance(item, Machines)
     yield isinstance(item, Computes)
     yield ICompute.providedBy(item)
     yield IVirtualizationContainer.providedBy(item)
     yield IHangar.providedBy(item)
Ejemplo n.º 3
0
def allocate_virtual_compute_from_hangar(model, event):
    if not IVirtualizationContainer.providedBy(model.__parent__):
        return

    if IDeployed.providedBy(model):
        return

    auto_allocate = get_config().getboolean('vms', 'auto_allocate', True)

    if not auto_allocate:
        return

    if IHangar.providedBy(model.__parent__.__parent__):
        action = AllocateAction
        msg = 'Allocated compute %s'
    elif ICompute.providedBy(model.__parent__.__parent__):
        action = DeployAction
        msg = 'Deployed compute %s'
    else:
        return

    try:
        path = canonical_path(model)
        owner = model.__owner__
        ul = UserLogger(subject=model, owner=owner)
        log.msg('Attempting %s for %s (%s, %s)' %
                (action.__name__, model, path, owner),
                system='create-event')
        d = task.deferLater(reactor, 2.0, virtual_compute_action, action, path,
                            event)
        d.addCallback(lambda r: ul.log(msg % path))
        if not get_config().getboolean('stats', 'only_report_on_sync', True):
            d.addCallback(lambda r: defer.maybeDeferred(
                getUtility(IUserStatisticsProvider).update, owner))
        d.addErrback(log.err)
    except Exception:
        log.err(system='create-event')
Ejemplo n.º 4
0
def remove_compute_from_zabbix(model, event):
    if IHangar.providedBy(model.__parent__):
        return
    # FILL IT
    # exception thrown will prevent deletion
    log.msg("TODO: remove %s from zabbix" % (model,), system='zabbix')
Ejemplo n.º 5
0
def add_compute_to_zabbix(model, event):
    if IHangar.providedBy(model.__parent__):
        return
    # FILL IT
    log.msg("TODO: add %s to zabbix" % (model,), system='zabbix')
Ejemplo n.º 6
0
def remove_compute_from_zabbix(model, event):
    if IHangar.providedBy(model.__parent__):
        return
    # FILL IT
    # exception thrown will prevent deletion
    log.msg("TODO: remove %s from zabbix" % (model,), system="zabbix")
Ejemplo n.º 7
0
def add_compute_to_zabbix(model, event):
    if IHangar.providedBy(model.__parent__):
        return
    # FILL IT
    log.msg("TODO: add %s to zabbix" % (model,), system="zabbix")