Exemplo n.º 1
0
def handlePackage_Activate(*args,**kwargs):
    event = kwargs["sender"]
    session = kwargs["session"]
    accountId = event.accountId
    try:
        account = session.query(Tenant).filter(Tenant.id == accountId).one()
        logger.error("<%s> account is in db , need to clean.")
    except NoResultFound:
        logger.info("<%s> is new accountid , create tenant id in db" % accountId)
        tenant = Tenant()
        tenant.id = accountId
        tenant.name = "TBD"
        tenant.state = Tenant_Sate.INIT
        session.add(tenant)
        packageName = event.packageName
        manager = ModelManager()
        svcs = manager.listsvcbypath(packageName)
        if svcs is None:
          logger.error("package(%s) has no corresponding service definition..." % pkg_path)
          return
        else:
          for model_svc in svcs:
              servcie = createRuntimeService(model_svc,tenant.id)
              session.add(servcie)
          tenant.getSM().trigger("package_activate",tenant = tenant,payload = event)
Exemplo n.º 2
0
def handleTenant_SAEnable(*args,**kwargs):
    event = kwargs["sender"]
    session = kwargs["session"]
    accountId = event.accountId
    if accountId == None:
        logger.error("accountId is None, ignore the invalid request")
        return
    try:
        account = session.query(Tenant).filter(Tenant.id == accountId).one()
        logger.error("<%s> account is in db , need to clean.")
        return
    except NoResultFound:
        tenant = Tenant()
        tenant.id = accountId
        tenant.name = "TBD"
        tenant.state = Tenant_Sate.PACKAGE_ACTIVATE
        session.add(tenant)
        session.flush()
        inventory = DMSInventoryManager()
        try:
            inventory.start()
            services = inventory.getservice(accountId)
        except:
            logger.error("get account <%s> service from zookeeper failed" % accountId)
            return
        mgr = ModelManager()
        for svc in services:
            model_svc = mgr.getsvfdefbyname(svc)
            servcie = createRuntimeService(model_svc,tenant.id)
            session.add(servcie)
            session.flush()
        for svc in services:
            nodes = inventory.getinstancebyservice(accountId,svc)
            for node in nodes:
                node["topic"] = "dms.event.rundeck"
                msg_event = EventFactory.getEvent("CREATE_VM",node)
                tenant.getSM().trigger("create_vm",tenant = tenant,payload=msg_event)
        session.commit()
        inventory.stop()