Esempio n. 1
0
 def _push(self, job=None):
     with dissomniag.rootContext():
         if job != None:
             self.multiLog("Entering git._push", job)
         origin = self.adminRepo.remotes.origin
         dissomniag.getIdentity().refreshSSHEnvironment()
         try:
             origin.push()
         except Exception:
             dissomniag.getIdentity().refreshSSHEnvironment()
             if job != None:
                 self.multiLog("Entering git._push AGAIN", job)
             origin.push()
         return True
Esempio n. 2
0
 def _push(self, job = None):
     with dissomniag.rootContext():
         if job != None:
             self.multiLog("Entering git._push", job)
         origin = self.adminRepo.remotes.origin
         dissomniag.getIdentity().refreshSSHEnvironment()
         try:
             origin.push()
         except Exception:
             dissomniag.getIdentity().refreshSSHEnvironment()
             if job != None:
                 self.multiLog("Entering git._push AGAIN", job)
             origin.push()
         return True
Esempio n. 3
0
 def createCheckJob(self):
     context = dissomniag.taskManager.Context()
     user = dissomniag.getIdentity().getAdministrativeUser()
     job = dissomniag.taskManager.Job(context, "Makce initial check git environment", user = user)
     job.addTask(dissomniag.tasks.CheckGitEnvironment())
     dissomniag.taskManager.Dispatcher.addJobSyncronized(user, self, job)
     return True
Esempio n. 4
0
 def _pull(self, job=None):
     with dissomniag.rootContext():
         if job != None:
             self.multiLog("Entering git._pull", job)
         if self.adminRepo.is_dirty():
             self._commit(job, "Dirty repo commit")
         origin = self.adminRepo.remotes.origin
         dissomniag.getIdentity().refreshSSHEnvironment()
         try:
             origin.pull()
         except Exception:
             dissomniag.getIdentity().refreshSSHEnvironment()
             if job != None:
                 self.multiLog("Entering git._pull AGAIN", job)
             origin.pull()
         return True
Esempio n. 5
0
 def _pull(self, job = None):
     with dissomniag.rootContext():
         if job != None:
             self.multiLog("Entering git._pull", job)
         if self.adminRepo.is_dirty():
             self._commit(job, "Dirty repo commit")
         origin = self.adminRepo.remotes.origin
         dissomniag.getIdentity().refreshSSHEnvironment()
         try:
             origin.pull()
         except Exception:
             dissomniag.getIdentity().refreshSSHEnvironment()
             if job != None:
                 self.multiLog("Entering git._pull AGAIN", job)
             origin.pull()
         return True
Esempio n. 6
0
    def getInfoXML(self, user):
        self.authUser(user)
        liveInfo = etree.Element("liveInfo")
        commonName = etree.SubElement(liveInfo, "commonName")
        commonName.text = str(self.vm.commonName)
        password = etree.SubElement(liveInfo, "password")
        password.text = str(self.plainPassword)
        uuid = etree.SubElement(liveInfo, "uuid")
        uuid.text = str(self.vm.uuid)
        serverIp = etree.SubElement(liveInfo, "serverIp")
        ident = dissomniag.getIdentity()
        serverIp.text = str(ident.getMaintainanceIP().addr)
        for interface in self.vm.interfaces:
            inter = etree.SubElement(liveInfo, "interface")
            name = etree.SubElement(inter, "name")
            name.text = str(interface.name)
            mac = etree.SubElement(inter, "mac")
            mac.text = str(interface.macAddress)

        vmSSHKeys = etree.SubElement(liveInfo, "vmSSHKeys")
        publicKey = etree.SubElement(vmSSHKeys, "publicKey")
        publicKey.text = str(self.vm.sshKey.publicKey)
        privateKey = etree.SubElement(vmSSHKeys, "privateKey")
        privateKey.text = str(self.vm.sshKey.privateKey)

        if dissomniag.getIdentity().getAdministrativeUser(
        ).publicKeys[0] != None:
            adminKey = etree.SubElement(liveInfo, "sshKey")
            adminKey.text = str(dissomniag.getIdentity().getAdministrativeUser(
            ).publicKeys[0].publicKey)
        session = dissomniag.Session()
        try:
            users = session.query(dissomniag.auth.User).filter(
                dissomniag.auth.User.isAdmin == True).all()
        except NoResultFound:
            pass
        else:
            for user in users:
                for key in user.getKeys():
                    userKey = etree.SubElement(liveInfo, "sshKey")
                    userKey.text = str(key)

        ###
        # Add other user keys by topology
        ###

        return etree.tostring(liveInfo, pretty_print=True)
Esempio n. 7
0
 def createCheckJob(self):
     context = dissomniag.taskManager.Context()
     user = dissomniag.getIdentity().getAdministrativeUser()
     job = dissomniag.taskManager.Job(context,
                                      "Makce initial check git environment",
                                      user=user)
     job.addTask(dissomniag.tasks.CheckGitEnvironment())
     dissomniag.taskManager.Dispatcher.addJobSyncronized(user, self, job)
     return True
Esempio n. 8
0
 def getInfoXML(self, user):
     self.authUser(user)
     liveInfo = etree.Element("liveInfo")
     commonName = etree.SubElement(liveInfo, "commonName")
     commonName.text = str(self.vm.commonName)
     password = etree.SubElement(liveInfo, "password")
     password.text = str(self.plainPassword)
     uuid = etree.SubElement(liveInfo, "uuid")
     uuid.text = str(self.vm.uuid)
     serverIp = etree.SubElement(liveInfo, "serverIp")
     ident = dissomniag.getIdentity()
     serverIp.text = str(ident.getMaintainanceIP().addr)
     for interface in self.vm.interfaces:
         inter = etree.SubElement(liveInfo, "interface")
         name = etree.SubElement(inter, "name")
         name.text = str(interface.name)
         mac = etree.SubElement(inter, "mac")
         mac.text = str(interface.macAddress)
     
     vmSSHKeys = etree.SubElement(liveInfo, "vmSSHKeys")
     publicKey = etree.SubElement(vmSSHKeys, "publicKey")
     publicKey.text = str(self.vm.sshKey.publicKey)
     privateKey = etree.SubElement(vmSSHKeys, "privateKey")
     privateKey.text = str(self.vm.sshKey.privateKey)
     
     if dissomniag.getIdentity().getAdministrativeUser().publicKeys[0] != None:
         adminKey = etree.SubElement(liveInfo, "sshKey")
         adminKey.text = str(dissomniag.getIdentity().getAdministrativeUser().publicKeys[0].publicKey)
     session = dissomniag.Session()
     try:
         users = session.query(dissomniag.auth.User).filter(dissomniag.auth.User.isAdmin == True).all()
     except NoResultFound:
         pass
     else:
         for user in users:
             for key in user.getKeys():
                 userKey = etree.SubElement(liveInfo, "sshKey")
                 userKey.text = str(key) 
         
     ###
     # Add other user keys by topology
     ###
     
     return etree.tostring(liveInfo, pretty_print=True)
Esempio n. 9
0
def startSSHServer():
    Portal = portal.Portal(SSHDiSSOmniaGRealm(dissomniag.cliApi))
    
    Portal.registerChecker(SSHDiSSOmniaGPublicKeyDatabase())
    Portal.registerChecker(SSHDiSSOmniaGUserAuthDatabase())
    
    publicKeyString, rsaKey = dissomniag.getIdentity().getRsaKeys()
    DiSSOmniaGSSHFactory.portal = Portal
    DiSSOmniaGSSHFactory.publicKeys = {'ssh-rsa': publicKeyString}
    DiSSOmniaGSSHFactory.privateKeys = {'ssh-rsa': rsaKey}
    reactor.listenTCP(dissomniag.config.server.sshPort, DiSSOmniaGSSHFactory())
Esempio n. 10
0
def startSSHServer():
    Portal = portal.Portal(SSHDiSSOmniaGRealm(dissomniag.cliApi))

    Portal.registerChecker(SSHDiSSOmniaGPublicKeyDatabase())
    Portal.registerChecker(SSHDiSSOmniaGUserAuthDatabase())

    publicKeyString, rsaKey = dissomniag.getIdentity().getRsaKeys()
    DiSSOmniaGSSHFactory.portal = Portal
    DiSSOmniaGSSHFactory.publicKeys = {'ssh-rsa': publicKeyString}
    DiSSOmniaGSSHFactory.privateKeys = {'ssh-rsa': rsaKey}
    reactor.listenTCP(dissomniag.config.server.sshPort, DiSSOmniaGSSHFactory())
Esempio n. 11
0
 def _addCommonInfoToTree(self, user, tree):
     self.authUser(user)
     name = etree.SubElement(tree, "name")
     name.text = str(self.app.name)
     
     serverUser = etree.SubElement(tree, "serverUser")
     serverUser.text = str(dissomniag.config.git.gitUser)
     
     serverIpOrHost = etree.SubElement(tree, "serverIpOrHost")
     ident = dissomniag.getIdentity()
     serverIpOrHost.text = str(ident.getMaintainanceIP().addr)
     return tree
Esempio n. 12
0
    def process_IN_CREATE(self, event):
        log.error("GIT(EVENT) %s" % event.pathname)
        filename = event.pathname
        time.sleep(1)

        lines = None
        with dissomniag.rootContext():
            try:
                with open(filename, 'r') as f:
                    lines = f.readlines()
            except Exception as e:
                log.error("GitEventHandler: Cannot read file %s." % filename)
                return

        session = dissomniag.Session()

        if lines != None:
            for line in lines:
                try:
                    splitted = line.split("=")
                    appName = splitted[0].strip()
                    branchName = splitted[1].strip()

                    try:
                        app = session.query(dissomniag.model.App).filter(
                            dissomniag.model.App.name == appName).one()
                        vm = session.query(dissomniag.model.VM).filter(
                            dissomniag.model.VM.commonName ==
                            branchName).one()
                        liveCd = vm.liveCd
                        rel = session.query(
                            dissomniag.model.AppLiveCdRelation).filter(
                                dissomniag.model.AppLiveCdRelation.liveCd ==
                                liveCd).filter(
                                    dissomniag.model.AppLiveCdRelation.app ==
                                    app).one()
                        rel.createRefreshAndResetJob(
                            dissomniag.getIdentity().getAdministrativeUser())
                        log.info(
                            "App %s auto git update executed on branch %s." %
                            (appName, branchName))
                    except Exception as e:
                        log.error(
                            "SKIPPED App %s auto git update executed on branch %s. Exception: %s"
                            % (appName, branchName, str(e)))
                except Exception as e:
                    log.error("process_GIT_EVENT: No valid request.")
        with dissomniag.rootContext():
            try:
                os.remove(filename)
            except OSError as e:
                log.error("Could not delete file %s in git event handler." %
                          filename)
Esempio n. 13
0
    def _getNewConfig(self, job=None):
        if job != None:
            self.multiLog("Entering git._getNewConfig", job)
        session = dissomniag.Session()
        config = ConfigParser.SafeConfigParser()

        config.add_section("gitosis")
        config.add_section("group gitosis-admin")
        adminUser = dissomniag.getIdentity().getAdministrativeUser()
        keys = adminUser.publicKeys
        adminUserKeys = self._getMembersSet(keys)
        try:
            adminUsers = session.query(dissomniag.auth.User).filter(
                dissomniag.auth.User.isAdmin == True).all()
            for user in adminUsers:
                if user.publicKeys != None:
                    adminUserKeys = adminUserKeys.union(
                        self._getMembersSet(user.publicKeys))
        except NoResultFound:
            pass

        config.set("group gitosis-admin", "members", " ".join(adminUserKeys))
        config.set("group gitosis-admin", "writable", "gitosis-admin")

        try:
            apps = session.query(dissomniag.model.App).all()

            for app in apps:
                repoName = app.name
                sectionName = "group %s" % repoName
                config.add_section(sectionName)
                config.set(sectionName, "writable", repoName)
                keys = adminUserKeys
                #Add user keys
                for user in app.users:
                    if user.publicKeys != None:
                        keys = keys.union(self._getMembersSet(user.publicKeys))

                #Add Admin LiveCd Node Keys
                for relation in app.AppLiveCdRelations:
                    keys.add(str(
                        relation.liveCd.vm.sshKey.getUserHostString()))

                config.set(sectionName, "members", " ".join(keys))

        except NoResultFound as e:
            pass

        return config
Esempio n. 14
0
 def _getNewConfig(self, job = None):
     if job != None:
         self.multiLog("Entering git._getNewConfig", job)
     session = dissomniag.Session()
     config = ConfigParser.SafeConfigParser()
     
     config.add_section("gitosis")
     config.add_section("group gitosis-admin")
     adminUser = dissomniag.getIdentity().getAdministrativeUser()
     keys = adminUser.publicKeys
     adminUserKeys = self._getMembersSet(keys)
     try:
         adminUsers = session.query(dissomniag.auth.User).filter(dissomniag.auth.User.isAdmin == True).all()
         for user in adminUsers:
             if user.publicKeys != None:
                 adminUserKeys = adminUserKeys.union(self._getMembersSet(user.publicKeys))
     except NoResultFound:
         pass
     
     
     config.set("group gitosis-admin", "members", " ".join(adminUserKeys))
     config.set("group gitosis-admin", "writable", "gitosis-admin")
     
     try:
         apps = session.query(dissomniag.model.App).all()
         
         for app in apps:
             repoName = app.name
             sectionName = "group %s" % repoName
             config.add_section(sectionName)
             config.set(sectionName, "writable", repoName)
             keys = adminUserKeys
             #Add user keys
             for user in app.users:
                 if user.publicKeys != None:
                     keys = keys.union(self._getMembersSet(user.publicKeys))
                     
             #Add Admin LiveCd Node Keys
             for relation in app.AppLiveCdRelations:
                 keys.add(str(relation.liveCd.vm.sshKey.getUserHostString()))
             
             config.set(sectionName, "members", " ".join(keys))
                     
     except NoResultFound as e:
         pass
     
     return config
Esempio n. 15
0
 def implementation(self, *args):
     sys.stdout = self.terminal
     sys.stderr = self.terminal
     
     parser = argparse.ArgumentParser(description = 'Add a App', prog = args[0])
     
     parser.add_argument("appName", action = "store")
     
     options = parser.parse_args(args[1:])
     
     session = dissomniag.Session()
     
     name = str(options.appName)
     
     try:
         apps = session.query(dissomniag.model.App).filter(dissomniag.model.App.name == name).all()
     except NoResultFound:
         pass
     else:
         for app in apps:
             if app.name == name:
                 self.printError("App with name %s already exists." % name)
                 return
     try:
         dissomniag.model.App(self.user, name)
     except Exception as e:
         self.printError("App creation Error. %s" % str(e))
         return
     else:
         self.printSuccess("Successfully added App %s for user %s." % (name, self.user.username))
         try:
             gitUser = dissomniag.config.git.gitUser
             if dissomniag.config.git.gitosisHost == "localhost":
                 gitHost = dissomniag.getIdentity().getMaintainanceIP().addr
             else:
                 gitHost = dissomniag.config.git.gitosisHost
             self.printSuccess("The repository is accessible with following command: git clone %s@%s:%s.git" % (gitUser, gitHost, name))
         except Exception:
             pass            
         return
Esempio n. 16
0
 def process_IN_CREATE(self, event):
     log.error("GIT(EVENT) %s" % event.pathname)
     filename = event.pathname
     time.sleep(1)
     
     lines = None
     with dissomniag.rootContext():
         try:
             with open(filename, 'r') as f:
                 lines = f.readlines()
         except Exception as e:
             log.error("GitEventHandler: Cannot read file %s." % filename)
             return
     
     session = dissomniag.Session()
     
     if lines != None:
         for line in lines:
             try:
                 splitted = line.split("=")
                 appName = splitted[0].strip()
                 branchName = splitted[1].strip()
                 
                 try:
                     app = session.query(dissomniag.model.App).filter(dissomniag.model.App.name == appName).one()
                     vm = session.query(dissomniag.model.VM).filter(dissomniag.model.VM.commonName == branchName).one()
                     liveCd = vm.liveCd
                     rel = session.query(dissomniag.model.AppLiveCdRelation).filter(dissomniag.model.AppLiveCdRelation.liveCd == liveCd).filter(dissomniag.model.AppLiveCdRelation.app == app).one()
                     rel.createRefreshAndResetJob(dissomniag.getIdentity().getAdministrativeUser())
                     log.info("App %s auto git update executed on branch %s." % (appName, branchName))
                 except Exception as e:
                     log.error("SKIPPED App %s auto git update executed on branch %s. Exception: %s" % (appName, branchName, str(e)))
             except Exception as e:
                 log.error("process_GIT_EVENT: No valid request.")
     with dissomniag.rootContext():
         try:
             os.remove(filename)
         except OSError as e:
             log.error("Could not delete file %s in git event handler." % filename)
Esempio n. 17
0
 def createSampleTopology(self):
     session = dissomniag.Session()
     adminUser = session.query(dissomniag.auth.User).all()[0]
     try:
         topos = session.query(dissomniag.model.Topology).all()
     except NoResultFound:
         pass
     else:
         for topo in topos:
             if topo.name == "SampleTopology":
                 nets = topo.generatedNetworks
                 for net in nets:
                     net.start(adminUser)
                 vms = topo.vms
                 for vm in vms:
                     vm.createStartJob(adminUser)
                 
                 return
             
     #No sample Topo exists
     adminUser = session.query(dissomniag.auth.User).all()[1]
     ident = dissomniag.getIdentity() 
     #ip = str(ident.getMaintainanceIP().addr)
     ip = "10.0.10.21"
     host = dissomniag.model.Host(adminUser, "localhost", "10.0.10.21", "br0", administrativeUserName = "******")
     session.add(host)
     dissomniag.saveCommit(session)
     host.checkFull(adminUser)
     topo = dissomniag.model.Topology()
     topo.name = "SampleTopology" 
     session.add(topo)
     dissomniag.saveCommit(session)
     net1 = dissomniag.model.generatedNetwork(adminUser, "10.100.1.0/24", host, topo, "Connection1") 
     net1.xValue = str(83)
     net1.yValue = str(57)
     net1.zValue = str(0)
     session.add(net1)
     dissomniag.saveCommit(session)
     net2 = dissomniag.model.generatedNetwork(adminUser, "10.100.2.0/24", host, topo, "Connection2") 
     net2.xValue = str(285) 
     net2.yValue = str(58) 
     net2.zValue = str(0) 
     session.add(net1)
     dissomniag.saveCommit(session)
     
     vm1 = dissomniag.model.VM(adminUser, "Source", host)
     vm1.xValue = str(17) 
     vm1.yValue = str(9) 
     vm1.zValue = str(0)
     session.add(vm1) 
     dissomniag.saveCommit(session) 
     
     vm2 = dissomniag.model.VM(adminUser, "SimulatedNetwork", host)
     vm2.xValue = str(169) 
     vm2.yValue = str(10) 
     vm2.zValue = str(0.1)
     
     session.add(vm2) 
     dissomniag.saveCommit(session) 
     
     vm3 = dissomniag.model.VM(adminUser, "Sink", host) 
     vm3.xValue = str(406) 
     vm3.yValue = str(16) 
     vm3.zValue = str(0) 
     session.add(vm3) 
     dissomniag.saveCommit(session) 
     
     topo.vms.append(vm1) 
     topo.vms.append(vm2) 
     topo.vms.append(vm3) 
     
     dissomniag.saveCommit(session)
     
     vm1.addInterfaceToNet(adminUser, net1) 
     vm2.addInterfaceToNet(adminUser, net1) 
     vm2.addInterfaceToNet(adminUser, net2) 
     vm3.addInterfaceToNet(adminUser, net2) 
     
     dissomniag.saveCommit(session)
     
     net1.start(adminUser)
     net2.start(adminUser)
     
     vm1.createStartJob(adminUser)
     vm2.createStartJob(adminUser)
     vm3.createStartJob(adminUser)
Esempio n. 18
0
def run():
    
    dissomniag.checkProgrammUserAndGroup()
    os.chdir(dissomniag.config.dissomniag.execDir)
    dissomniag.init()
    dissomniag.getIdentity().run()
Esempio n. 19
0
 def refreshSSHEnvironment(self):
     self._prepareSSHEnvironment()
     sshKey = dissomniag.getIdentity().sshKey
     return self._checkRsaKeyAdded(sshKey.privateKeyFile, sshKey.publicKey)
Esempio n. 20
0
 def setUp(self):
     self.session = dissomniag.Session()
     self.user = dissomniag.getIdentity().getAdministrativeUser()
     self.host = self.session.query(dissomniag.model.Host).one()
Esempio n. 21
0
 def setUp(self):
     self.session = dissomniag.Session()
     self.user = dissomniag.getIdentity().getAdministrativeUser()
     self.host = self.session.query(dissomniag.model.Host).one()
Esempio n. 22
0
def run():

    dissomniag.checkProgrammUserAndGroup()
    os.chdir(dissomniag.config.dissomniag.execDir)
    dissomniag.init()
    dissomniag.getIdentity().run()
Esempio n. 23
0
 def refreshSSHEnvironment(self):
     self._prepareSSHEnvironment()
     sshKey = dissomniag.getIdentity().sshKey
     return self._checkRsaKeyAdded(sshKey.privateKeyFile, sshKey.publicKey)