Beispiel #1
0
    def PostInstall(self):
        try:
            tar = tarfile.open(self.tmp + self.TrayFile, "r:gz")
            tar.extractall(self.install + 'bin')
            tar.close()
        except:
            subutai.RaiseError("Failed to unpack Tray archive. Aborting")
            return 86

        self.__writeDesktopFile()
        postinst = subuco.PostInstall(self.tmp)
        postinst.append('mkdir -p /opt/subutai/bin')
        postinst.append('mkdir -p /opt/subutai/etc')
        postinst.append('mkdir -p /opt/subutai/resources')
        postinst.append('chown -R ' + os.environ['USER'] + ':' +
                        os.environ['USER'] + ' /opt/subutai')
        postinst.append('ln -s ' + self.install +
                        'bin/SubutaiTray /usr/local/bin/SubutaiTray')
        postinst.append('desktop-file-install ' + self.tmp +
                        'SubutaiTray.desktop')
        try:
            p = Popen([
                '/usr/bin/gksudo', '--message', 'Finalize Tray Installation',
                postinst.get()
            ],
                      stdin=PIPE,
                      stdout=PIPE,
                      stderr=PIPE,
                      universal_newlines=True)
            stdout, stderr = p.communicate('')
        except:
            subutai.RaiseError("Failed to launch Subutai Tray application")

        return 0
Beispiel #2
0
    def Download(self):
        rc = 0
        subutai.AddStatus("Installing")
        if not CheckOsascript() and not CheckCocoasudo(self.install):
            rc = InstallCocoasudo(self.tmp, self.install, self.progress)
            if rc != 0:
                return rc

        if not self.__checkTuntap():
            self.__installTuntap()    

        subutai.download(self.RemoteP2PFile)
        while subutai.isDownloadComplete() != 1:
            sleep(0.05)
            self.progress.setP2PProgress(subutai.GetBytesDownload())
            self.progress.updateProgress()

        self.progress.setP2PProgress(self.progress.getP2PSize())
        self.progress.updateProgress()
        try:
            copyfile(self.tmp+self.RemoteP2PFile, self.install+"bin/"+self.P2PFile)
        except:
            subutai.RaiseError("Failed to move p2p binary to " +
                            self.install + "bin/"+self.P2PFile)
            return 19

        try:
            st = os.stat(self.install+"/bin/"+self.P2PFile)
            os.chmod(self.install+"/bin/"+self.P2PFile, st.st_mode | stat.S_IEXEC)
        except:
            subutai.RaiseError("Failed to make p2p binary executable")
            return 31

        return rc
Beispiel #3
0
    def Download(self):
        rc = 0
        subutai.AddStatus("Installing")
        if not self.__checkNssm():
            subutai.download(self.NssmFile)
            while subutai.isDownloadComplete() != 1:
                sleep(0.05)
                self.progress.setNssmProgress(subutai.GetBytesDownload())
                self.progress.updateProgress()

            self.progress.setNssmProgress(self.progress.getNssmSize())
            self.progress.updateProgress()
            try:
                copyfile(self.tmp + self.NssmFile,
                         self.install + "bin/" + self.NssmFile)
            except:
                subutai.RaiseError(
                    "Failed to move NSSM file to it's destination")
                return 14
        else:
            subutai.UnregisterService("Subutai P2P")
            subutai.ProcessKill("nssm.exe")
            subutai.ProcessKill("p2p.exe")

        rc = self.__installTuntap()
        subutai.download(self.RemoteP2PFile)
        while subutai.isDownloadComplete() != 1:
            sleep(0.05)
            self.progress.setP2PProgress(subutai.GetBytesDownload())
            self.progress.updateProgress()

        self.progress.setP2PProgress(self.progress.getP2PSize())
        self.progress.updateProgress()
        try:
            copyfile(self.tmp + self.RemoteP2PFile,
                     self.install + "bin/" + self.P2PFile)
        except:
            subutai.RaiseError("Failed to move p2p binary to " + self.install +
                               "bin/" + self.P2PFile)
            return 19

        try:
            st = os.stat(self.install + "/bin/" + self.P2PFile)
            os.chmod(self.install + "/bin/" + self.P2PFile,
                     st.st_mode | stat.S_IEXEC)
        except:
            subutai.RaiseError("Failed to make p2p binary executable")
            return 31

        return rc
def installOpenjre(openjreFile, progress):
    td = "/var/snap/subutai-dev/common/lxc/tmpdir/"
    awk = " | awk '{print $5}'"

    rc = subutai.SSHStartSession("mng-setup2")
    if rc != 0:
        subutai.AddStatus("Downloading JVM")
        subutai.SSHRun("sudo subutai -d import openjre16 1>/tmp/openjre16-1.log 2>/tmp/openjre16-2.log")
        return 0

    subutai.AddStatus("Downloading JVM")
    rc = subutai.SSHExecute("mng-setup2", "sudo subutai import openjre16 &")
    if rc[0] != 0:
        subutai.RaiseError("Failed to install OpenJRE in background. Switching to static install")
        subutai.SSHRun("sudo subutai import openjre16 >/tmp/openjre16.log 2>&1")
    else:
        checks = 0
        while True:
            out = subutai.SSHRunOut("ps -ef | grep \"subutai import\" | grep -v grep | awk '{print $2}'")
            if out == '':
                break
            sleep(1)
            checks = checks + 1
            if checks >= 60:
                subutai.SSHExecute("mng-setup2", "ls / &")
                checks = 0
            out = subutai.SSHRunOut("ls -l "+td+openjreFile+awk)
            try:
                val = int(out)
                progress.setOpenjreProgress(val)
                progress.updateProgress()
            except:
                pass

    subutai.SSHStopSession("mng-setup2")
Beispiel #5
0
def subutaistart():

    tmpDir = subutai.GetTmpDir()

    chromeFilename = "GoogleChromeStandaloneEnterprise64.msi"

    chromeSize = subutai.GetFileSize(chromeFilename)
    totalSize = chromeSize
    chromeProgress = 0

    if subutai.IsChromeInstalled() != 0:
        subutai.AddStatus("Downloading Chrome")
        subutai.download(chromeFilename)
        while subutai.isDownloadComplete() != 1:
            sleep(0.05)
            chromeProgress = subutai.GetBytesDownload()
            updateProgress(chromeProgress, totalSize)

        chromeProgress = chromeSize

        subutai.AddStatus("Installing Chrome")
        try:
            call(['msiexec', '/qn', '/i', tmpDir + chromeFilename])
        except:
            subutai.RaiseError("Failed to install Google Chrome")
            sleep(5)

    subutai.AddStatus("Installing Browser Plugin")

    subutai.RegisterPlugin()

    subutai.Shutdown()

    return 0
Beispiel #6
0
def CleanSSHKeys(host, port):
    try:
        call(['ssh-keygen', '-R', '['+host+']:'+port])
    except:
        subutai.RaiseError("Failed to clean SSH keys")
        return 78
    return 0
Beispiel #7
0
    def SetupVirtualMachine(self):
        subutai.AddStatus("Setting up virtual machine")
        subutai.SetAction("INSTVM")
        rc = 0
        subutai.AddStatus("Installing VM")
        if subutai.CheckVMExists(self.name) != 0:
            subutai.download("core.ova")
            while subutai.isDownloadComplete() != 1:
                sleep(0.05)
                self.progress.setCoreProgress(subutai.GetBytesDownload())
                self.progress.updateProgress()

            subutai.AddStatus("VM Image downloaded")

        self.progress.setCoreProgress(self.progress.getCoreSize())
        self.progress.updateProgress()
        rc = subutai.VBoxS("import " +
                           subutai.GetTmpDir().replace(" ", "+++") +
                           "core.ova --vsys 0 --vmname " + self.name)
        if rc != 0:
            subutai.RaiseError("Failed to import Virtual Machine")
            return rc

        sleep(3)
        cpus = subutai.GetCoreNum()
        mem = subutai.GetMemSize() * 1024
        subutai.VBox("modifyvm " + self.name + " --cpus " + str(cpus))
        subutai.VBox("modifyvm " + self.name + " --memory " + str(mem))
        return rc
Beispiel #8
0
    def InstallUbuntu(self):
        subutai.SetAction("INSTUB")
        td = "/var/snap/subutai/common/lxc/tmpdir/"
        awk = " | awk '{print $5}'"

        subutai.AddStatus("Downloading Ubuntu Linux")
        rc = subutai.SSHStartSession("mng-setup")

        if rc != 0:
            subutai.RaiseError(
                "Failed to install Ubuntu interactively. Switching to static install"
            )
            subutai.SSHRun(
                "sudo subutai -d import ubuntu16 >/tmp/ubuntu16.log 2>&1")
            return 0

        rc = subutai.SSHExecute("mng-setup", "sudo subutai import ubuntu16 &")
        if rc[0] != 0:
            subutai.RaiseError(
                "Failed to install Ubuntu in background. Switching to static install"
            )
            subutai.SSHRun(
                "sudo subutai -d import ubuntu16 >/tmp/ubuntu16.log 2>&1")
        else:
            checks = 0
            while True:
                out = subutai.SSHRunOut(
                    "ps -ef | grep \"subutai import\" | grep -v grep | awk '{print $2}'"
                )
                if out == '':
                    subutai.AddStatus("Download completed")
                    break
                sleep(1)
                checks = checks + 1
                if checks >= 60:
                    subutai.SSHExecute("mng-setup", "ls / &")
                    checks = 0
                out = subutai.SSHRunOut("ls -l " + td + self.UbuntuFile + awk)
                try:
                    val = int(out)
                    self.progress.setUbuntuProgress(val)
                    self.progress.updateProgress()
                except:
                    pass

        subutai.SSHStopSession("mng-setup")
        return 0
Beispiel #9
0
 def Install(self):
     subutai.AddStatus("Installing Chrome")
     try:
         call(['msiexec', '/qn', '/i', self.tmp + self.GoogleChromeFile])
     except:
         subutai.RaiseError("Failed to install Google Chrome")
         return 28
     return 0
def GetPeerIP():
    ip = subutai.GetPeerIP()

    if ip == "":
        subutai.RaiseError("Failed to determine peer IP address")
        return "127.0.0.1"

    ip = "127.0.0.1"
    return ip
Beispiel #11
0
def CleanSSHKeys(host, port):
    try:
        call([
            subutai.GetInstallDir() + 'bin/ssh-keygen.exe', '-R',
            '[' + host + ']:' + port
        ])
    except:
        subutai.RaiseError("Failed to clean SSH keys")
        return 78
    return 0
Beispiel #12
0
    def StartVirtualMachine(self):
        subutai.SetAction("STARTVM")
        rc = 0
        if subutai.CheckVMRunning(self.name) != 0:
            rc = subutai.VBoxS("startvm --type headless " + self.name)

        if rc != 0:
            subutai.RaiseError("Failed to start Virtual Machine")

        return rc
Beispiel #13
0
    def WaitSSH(self):
        subutai.SetAction("WAITSSH")
        attempts = 0
        while subutai.TestSSH() != 0:
            sleep(5)
            attempts = attempts + 1
            if attempts == 30:
                subutai.RaiseError("SSH connection failed after 30 attempts")
                return 34

        attempts = 0
        out = ''
        while out == '':
            out = subutai.SSHRunOut("uptime")
            attempts = attempts + 1
            if attempts >= 30:
                subutai.RaiseError("SSH connection failed after 30 attempts")
                return 35

        return 0
Beispiel #14
0
    def RetrievePeerIP(self):
        subutai.SetAction("GETIP")
        self.PeerIP = subutai.GetPeerIP()
        self.LocalIP = '127.0.0.1'
        # Fixing peer ip
        self.PeerIP = self.LocalIP

        if self.PeerIP == "":
            subutai.RaiseError("Failed to determine peer IP address")
            return 1

        return 0
Beispiel #15
0
 def Install(self):
     subutai.SetAction('INST')
     if not os.path.exists(self.tmp+self.GoogleChromeFile):
         return 0
     try:
         script = 'do shell script "/usr/bin/tar -xf '+self.tmp+self.GoogleChromeFile+' -C /Applications" with administrator privileges'
         p = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
         stdout, stderr = p.communicate(script)
     except:
         subutai.RaiseError("Failed to install Google Chrome")
         return 64
     return 0
Beispiel #16
0
def InstallVirtualBox(tmp, install, progress):
    subutai.AddStatus("Downloading VirtualBox")
    subutai.download(GetVirtualBoxName())
    while subutai.isDownloadComplete() != 1:
        sleep(0.05)
        progress.setVboxProgress(subutai.GetBytesDownload())
        progress.updateProgress()

    progress.setVboxProgress(progress.getVboxSize())
    progress.updateProgress()
    try:
        subutai.AddStatus("Installing VirtualBox")
        postinst = subuco.PostInstall(tmp)
        postinst.append('dpkg -i ' + tmp + GetVirtualBoxName())
        postinst.append('modprobe vboxdrv >> /tmp/subutai/vbox.log 2>&1')
        postinst.append('modprobe vboxnetflt >> /tmp/subutai/vbox.log 2>&1')
        postinst.append('modprobe vboxnetadp >> /tmp/subutai/vbox.log 2>&1')
        postinst.append('modprobe vboxpci >> /tmp/subutai/vbox.log 2>&1')
        postinst.append("apt-get install -f -y")
        postinst.append('cat /tmp/subutai/vbox.log')
        p = run([
            '/usr/bin/gksudo', '--message', 'Install VirtualBox',
            postinst.get()
        ],
                stdout=PIPE,
                stderr=PIPE,
                encoding="utf-8")
        if p.stdout != '':
            subutai.Information(p.stdout)
        if p.stderr != '':
            subutai.Error(p.stderr)
    except:
        subutai.RaiseError("Failed to install VirtualBox. Aborting")
        return 45
    if not CheckVirtualBox():
        subutai.RaiseError("Failed to install VirtualBox. Aborting")
        return 24

    return 0
def waitForNetwork():
    subutai.AddStatus("Waiting for network")

    attempts = 0
    while True:
        out = subutai.SSHRunOut('if [ $(timeout 3 ping 8.8.8.8 -c1 2>/dev/null | grep -c "1 received") -ne 1 ]; then echo 1; else echo 0; fi')
        if out == '0':
            break
        if attempts >= 60:
            subutai.RaiseError("Failed to establish Internet connection on peer")
            return 82
        attempts = attempts + 1
        sleep(1)

    return 0
Beispiel #18
0
    def PostInstall(self):
        try:
            tar = tarfile.open(self.tmp+self.TrayFile, "r:gz")
            tar.extractall("/Applications/Subutai")
            tar.close()
        except:
            subutai.RaiseError("Failed to unpack Tray archive. Aborting")
            return 86
        postinst = subuco.PostInstall(self.tmp)
        postinst.append('installer -pkg '+self.tmp+self.LibsshFile+' -target /')
        ins = 'do shell script "/bin/sh '+postinst.get()+'" with administrator privileges'
        p = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
        stdout, stderr = p.communicate(ins)
        if p.returncode != 0:
            return 91

        try:
            launch = 'tell application "SubutaiTray.app" to activate'
            p = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
            stdout, stderr = p.communicate(launch)
        except:
            subutai.RaiseError("Failed to launch Subutai Tray application")

        return 0
Beispiel #19
0
    def InstallManagement(self):
        subutai.SetAction("INSTMNG")
        td = "/var/snap/subutai/common/lxc/tmpdir/"
        awk = " | awk '{print $5}'"

        rc = subutai.SSHStartSession("mng-setup3")
        if rc != 0:
            subutai.AddStatus("Installing Management Container")
            subutai.SSHRun(
                "sudo subutai -d import management 1>/tmp/management-1.log 2>/tmp/management-2.log"
            )
            return 0

        subutai.AddStatus("Installing Management Container")
        rc = subutai.SSHExecute("mng-setup3",
                                "sudo subutai import management &")
        if rc[0] != 0:
            subutai.RaiseError(
                "Failed to install Management in background. Switching to static install"
            )
            subutai.SSHRun(
                "sudo subutai import management >/tmp/management.log 2>&1")
        else:
            checks = 0
            while True:
                out = subutai.SSHRunOut(
                    "ps -ef | grep \"subutai import\" | grep -v grep | awk '{print $2}'"
                )
                if out == '':
                    break
                sleep(1)
                checks = checks + 1
                if checks >= 60:
                    subutai.SSHExecute("mng-setup3", "ls / &")
                    checks = 0
                out = subutai.SSHRunOut("ls -l " + td + "*" +
                                        self.ManagementFile + "*" + awk)
                try:
                    val = int(out)
                    self.progress.setManagementProgress(val)
                    self.progress.updateProgress()
                except:
                    pass

        subutai.SSHStopSession("mng-setup3")
        return 0
Beispiel #20
0
    def __installTuntap(self):
        subutai.SetStep("TAPINST")
        subutai.AddStatus("Downloading TUN/TAP driver")
        subutai.download(self.TapFile)
        while subutai.isDownloadComplete() != 1:
            sleep(0.05)
            self.progress.setTuntapProgress(subutai.GetBytesDownload())
            self.progress.updateProgress()

        self.progress.setTuntapProgress(self.progress.getTuntapSize())
        self.progress.updateProgress()
        subutai.Information("Running TAP installation")
        subutai.AddStatus("Installing TUN/TAP driver")
        r = call([self.tmp + self.TapFile, '/S'])
        if r != 0:
            subutai.RaiseError("Failed to install TUN/TAP Driver")
        return r
Beispiel #21
0
def InstallVirtualBox(tmp, install, progress):
    subutai.AddStatus("Downloading VirtualBox")
    subutai.download(GetVirtualBoxName())
    while subutai.isDownloadComplete() != 1:
        sleep(0.05)
        progress.setVboxProgress(subutai.GetBytesDownload())
        progress.updateProgress()

    progress.setVboxProgress(progress.getVboxSize())
    progress.updateProgress()
    subutai.AddStatus("Installing VirtualBox")
    try:
        call([tmp + GetVirtualBoxName(), '-silent'])
    except:
        subutai.RaiseError("Failed to install VirtualBox. Aborting")
        return 45

    return 0
Beispiel #22
0
def InstallCocoasudo(tmp, install, progress):
    subutai.AddStatus("Downloading cocoasudo application")
    subutai.download("cocoasudo")
    while subutai.isDownloadComplete() != 1:
        sleep(0.05)
        progress.setCocoasudoProgress(subutai.GetBytesDownload())
        progress.updateProgress()

    progress.setCocoasudoProgress(progress.getCocoasudoSize())
    progress.updateProgress()

    subutai.AddStatus("Installing cocoasudo")
    try:
        copyfile(tmp+"cocoasudo", install+"bin/cocoasudo")
        st = os.stat(install+"bin/cocoasudo")
        os.chmod(install+"bin/cocoasudo", st.st_mode | stat.S_IEXEC)
    except:
        subutai.RaiseError("Failed to install cocoasudo. Aborting")
        return -87
    return 0
Beispiel #23
0
def InstallVirtualBox(tmp, install, progress):
    subutai.AddStatus("Downloading VirtualBox")
    subutai.download("VirtualBox.pkg")
    while subutai.isDownloadComplete() != 1:
        sleep(0.05)
        progress.setVboxProgress(subutai.GetBytesDownload())
        progress.updateProgress()

    subutai.AddStatus("Installing VirtualBox")
    try:
        CheckAndKillVirtualBox()
        if not CheckOsascript():
            returnCode = call([install+"bin/cocoasudo",
                               '--prompt="Install VirtualBox"',
                               'installer',
                               '-pkg',
                               tmp+'VirtualBox.pkg',
                               '-target',
                               '/'])
            if returnCode != 0:
                return 21
        else:
            ins = 'do shell script "installer -pkg '+tmp+'VirtualBox.pkg -target /" with administrator privileges'
            p = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
            stdout, stderr = p.communicate(ins)
            if p.returncode != 0:
                return 23

    except:
        subutai.RaiseError("Failed to install VirtualBox. Aborting")
        sleep(10)
        return 45

    progress.setVboxProgress(progress.getVboxSize())
    progress.updateProgress()
    if not os.path.exists("/Applications/VirtualBox.app"):
        subutai.AddStatus("Failed to install VirtualBox. Aborting")
        return 24

    return 0
def waitSSH():
    subutai.log("info", "Waiting for machine to bring SSH")
    attempts = 0
    while subutai.TestSSH() != 0:
        sleep(1)
        attempts = attempts + 1
        if attempts == 30:
            subutai.log("error", "SSH timeout for 30 second")
            return 34

    attempts = 0
    out = ''
    while out == '':
        out = subutai.SSHRunOut("uptime")
        attempts = attempts + 1
        if attempts >= 30:
            subutai.RaiseError("SSH connection failed after 30 attempts")
            subutai.log("error", "SSH timeout for 30 second")
            return 35

    subutai.log("info", "SSH Connected")
    return 0
Beispiel #25
0
    def Download(self):
        rc = 0
        subutai.AddStatus("Downloading libssh2")
        subutai.download(self.LibsshFile)
        while subutai.isDownloadComplete() != 1:
            sleep(0.05)
            self.progress.setLibsshProgress(subutai.GetBytesDownload())
            self.progress.updateProgress()

        self.progress.setLibsshProgress(self.progress.getLibsshSize())
        self.progress.updateProgress()

        subutai.ProcessKill("SubutaiTray.exe")
        subutai.ProcessKill("ssh.exe")
        subutai.ProcessKill("ssh-keygen.exe")

        subutai.download(self.TrayFile)
        while subutai.isDownloadComplete() != 1:
            sleep(0.05)
            self.progress.setTrayProgress(subutai.GetBytesDownload())
            self.progress.updateProgress()

        self.progress.setTrayProgress(self.progress.getTraySize())
        self.progress.updateProgress()

        try:
            zf = zipfile.ZipFile(self.tmp + self.TrayFile, 'r')
            zf.extractall(self.install)
            zf.close()
            zfl = zipfile.ZipFile(self.tmp + self.LibsshFile, 'r')
            zfl.extractall(self.install + "/bin")
            zfl.close()
        except:
            subutai.RaiseError("Failed to replace tray")

        return rc
Beispiel #26
0
 def PostInstall(self):
     self.__writeJson()
     subutai.SetAction("POSINST")
     location = '/opt/google/chrome/extensions/'
     postinst = subuco.PostInstall(self.tmp)
     postinst.append('dpkg -i ' + self.tmp + self.GoogleChromeFile)
     postinst.append('apt-get install -f -y')
     if not os.path.exists(location):
         postinst.append('mkdir -p ' + location)
     postinst.append('cp ' + self.tmp + self.Plugin + ' ' + location)
     try:
         p = Popen([
             '/usr/bin/gksudo', '--message', 'Finalize E2E Installation',
             postinst.get()
         ],
                   stdin=PIPE,
                   stdout=PIPE,
                   stderr=PIPE,
                   universal_newlines=True)
         stdout, stderr = p.communicate('')
     except:
         subutai.RaiseError("Failed to install Google Chrome")
         return 64
     return 0
Beispiel #27
0
def subutaistart():
    tmpDir = subutai.GetTmpDir()
    subutai.AddStatus("Downloading Google Chrome")

    chromeFilename = "google-chrome-stable_current_amd64.deb"

    chromeSize = subutai.GetFileSize(chromeFilename)
    totalSize = chromeSize
    chromeProgress = 0

    subutai.download(chromeFilename)
    while subutai.isDownloadComplete() != 1:
        sleep(0.05)
        chromeProgress = subutai.GetBytesDownload()
        updateProgress(chromeProgress, totalSize)

    chromeProgress = chromeSize

    try:
        call([
            '/usr/bin/gksudo', '--message',
            'Install Google Chrome Dependencies',
            'apt-get install libappindicator1 -y'
        ])

        call([
            '/usr/bin/gksudo', '--message', 'Install Google Chrome',
            'dpkg -i ' + tmpDir + chromeFilename
        ])
        sleep(20)
    except:
        subutai.RaiseError("Failed to install Google Chrome")
        sleep(5)

    subutai.AddStatus("Installing Browser Plugin")

    #location = os.environ['HOME'] + '/.config/google-chrome/Default/External Extensions'
    location = '/opt/google/chrome/extensions/'
    if not os.path.exists(location):
        try:
            call([
                '/usr/bin/gksudo', '--message', 'Create extension directory',
                'mkdir -p ' + location
            ])
        except:
            subutai.RaiseError("Failed to create " + location + " directory")
            sleep(5)
            return -22

    ete = '{\n\t"external_update_url": "https://clients2.google.com/service/update2/crx"\n}\n'

    f = open(tmpDir + "kpmiofpmlciacjblommkcinncmneeoaa.json", 'w')
    f.write(ete)  # python will convert \n to os.linesep
    f.close()

    try:
        call([
            '/usr/bin/gksudo', '--message', 'Create extension directory',
            'cp ' + tmpDir + 'kpmiofpmlciacjblommkcinncmneeoaa.json ' +
            location
        ])
    except:
        subutai.RaiseError("Failed to move extension file")
        sleep(5)
        return -22

    subutai.Shutdown()

    return 0
def subutaistart():
    tmpDir = subutai.GetTmpDir()
    installDir = subutai.GetInstallDir()

    cocoasudoFile = "cocoasudo"
    p2pFile = "p2p_osx"
    tuntapFile = "tuntap_20150118_osx.pkg"

    cocoasudoSize = subutai.GetFileSize(cocoasudoFile)
    p2pSize = subutai.GetFileSize(p2pFile)
    tuntapSize = subutai.GetFileSize(tuntapFile)
    totalSize = cocoasudoSize + p2pSize + tuntapSize
    cocoasudoProgress = 0
    p2pProgress = 0
    tuntapProgress = 0

    if not os.path.exists(installDir+"bin/cocoasudo"):
        subutai.AddStatus("Downloading cocoasudo application")
        subutai.download(cocoasudoFile)
        while subutai.isDownloadComplete() != 1:
            sleep(0.05)
            cocoasudoProgress = subutai.GetBytesDownload()
            updateProgress(cocoasudoProgress, p2pProgress, tuntapProgress,
                           totalSize)

        try:
            copyfile(tmpDir+cocoasudoFile, installDir+"bin/cocoasudo")
            st = os.stat(installDir+"bin/cocoasudo")
            os.chmod(installDir+"bin/cocoasudo", st.st_mode | stat.S_IEXEC)
        except:
            subutai.RaiseError("Failed to install cocoasudo. Aborting")
            sleep(10)
            return -99

    cocoasudoProgress = cocoasudoSize
    subutai.AddStatus("Download TUNTAP driver")
    subutai.download(tuntapFile)
    while subutai.isDownloadComplete() != 1:
        sleep(0.05)
        tuntapProgress = subutai.GetBytesDownload()
        updateProgress(cocoasudoProgress, p2pProgress, tuntapProgress,
                       totalSize)

    tuntapProgress = tuntapSize
    subutai.AddStatus("Download p2p binary")

    subutai.download(p2pFile)
    while subutai.isDownloadComplete() != 1:
        sleep(0.05)
        p2pProgress = subutai.GetBytesDownload()
        updateProgress(cocoasudoProgress, p2pProgress, tuntapProgress,
                       totalSize)

    p2pProgress = p2pSize
    subutai.AddStatus("Download finished. Installing")

    try:
        copyfile(tmpDir+p2pFile, installDir+"bin/p2p")
    except:
        subutai.RaiseError("Failed to move p2p binary to " +
                           installDir + "bin/p2p")
        return 21

    subutai.SetProgress(0.99)

    subutai.AddStatus("Making p2p binary executable")
    try:
        st = os.stat(installDir+"/bin/p2p")
        os.chmod(installDir+"/bin/p2p", st.st_mode | stat.S_IEXEC)
    except:
        subutai.RaiseError("Failed to make p2p binary executable")
        return 31

    subutai.AddStatus("Creating p2p service")
    service = '''
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>io.subutai.p2p.daemon</string>

    <key>ProgramArguments</key>
    <array>
    <string>/usr/local/bin/p2p</string>
    <string>daemon</string>
    </array>

    <key>KeepAlive</key>
    <true/>

    <key>StandardOutPath</key>
    <string>/var/log/p2p.log</string>

    <key>StandardErrorPath</key>
    <string>/var/log/p2p.log</string>

    <key>Debug</key>
    <true/>
    </dict>
    </plist>
    '''.strip()

    daemonFile = 'io.subutai.p2p.daemon.plist'

    f = open(tmpDir+daemonFile, 'w')
    f.write(service)
    f.close()

    syslog = '''
    # logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]
    /var/log/p2p.log                       644  7     *    $D0   J
    '''.strip()
    sf = open(tmpDir+'p2p.conf', 'w')
    sf.write(syslog)
    sf.close()

    subutai.AddStatus("Configure P2P Daemon")
    installScript = "#!/bin/bash\n\n"
    installScript = installScript + "cp " + tmpDir + daemonFile + " /Library/LaunchDaemons/" + daemonFile + "\n"
    installScript = installScript + "cp " + tmpDir + "p2p.conf /etc/newsyslog.d/p2p.conf\n"
    installScript = installScript + "launchctl load /Library/LaunchDaemons/" + daemonFile + "\n"
    installScript = installScript + "installer -pkg " + tmpDir + "tuntap_20150118.pkg -target /\n"
    installScript = installScript + "ln -s "+installDir+"/bin/p2p /usr/local/bin/p2p\n"

    f = open(tmpDir+"p2p-setup.sh", 'w')
    f.write(installScript)
    f.close()

    try:
        st = os.stat(tmpDir+"p2p-setup.sh")
        os.chmod(tmpDir+"p2p-setup.sh", st.st_mode | stat.S_IEXEC)
    except:
        subutai.RaiseError("Failed to configure p2p daemon")
        sleep(10)
        return 31

    try:
        script = 'do shell script "'+tmpDir+'p2p-setup.sh" with administrator privileges'
        p = Popen(['osascript', '-'], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)
        stdout, stderr = p.communicate(script)
    except:
        subutai.RaiseError("Failed to install p2p daemon")
        sleep(10)
        return 22

    subutai.SetProgress(1.00)

    sleep(5)
    subutai.Shutdown()

    return 0
Beispiel #29
0
def subutaistart():
    subutai.AddStatus("Download Tray application")

    trayFile = "SubutaiTray_libs.zip"
    sshlibFile = "ssh.zip"

    traySize = subutai.GetFileSize(trayFile)
    libsshSize = subutai.GetFileSize(sshlibFile)
    totalSize = traySize + libsshSize
    trayProgress = 0
    libsshProgress = 0

    subutai.download(trayFile)
    while subutai.isDownloadComplete() != 1:
        sleep(0.05)
        trayProgress = subutai.GetBytesDownload()
        updateProgress(trayProgress, libsshProgress, totalSize)

    trayProgress = traySize

    subutai.download(sshlibFile)
    while subutai.isDownloadComplete() != 1:
        sleep(0.05)
        libsshProgress = subutai.GetBytesDownload()
        updateProgress(trayProgress, libsshProgress, totalSize)

    libsshProgress = libsshSize

    tmpDir = subutai.GetTmpDir()
    installDir = subutai.GetInstallDir()

    subutai.AddStatus("Installing Tray")

    subutai.ProcessKill("SubutaiTray.exe")
    subutai.ProcessKill("ssh.exe")
    subutai.ProcessKill("ssh-keygen.exe")

    try:
        zf = zipfile.ZipFile(tmpDir + "/" + trayFile, 'r')
        zf.extractall(installDir)
        zf.close()
        zfl = zipfile.ZipFile(tmpDir + "/" + sshlibFile, 'r')
        zfl.extractall(installDir + "/bin")
        zfl.close()
    except:
        subutai.RaiseError("Failed to replace tray")

    subutai.CreateDesktopShortcut(installDir + "/tray/SubutaiTray.exe",
                                  "Subutai Tray")

    subutai.AddStatus("Writing configuration")
    unPath = installDir.replace('\\', '/')
    unVBoxPath = subutai.GetVBoxPath().replace('\\', '/')
    f = open(unPath + "/tray/subutai_tray.ini", "w")
    f.write("P2P_Path=" + unPath + "/bin/p2p.exe\n")
    if unVBoxPath != "":
        f.write("VBoxManage_Path=" + unVBoxPath + "\n")
    f.write("Ssh_Path=" + unPath + "/bin/ssh.exe\n")
    f.write("Ssh_Keygen_Cmd=" + unPath + "/bin/ssh-keygen.exe\n")
    f.close()

    subutai.Shutdown()

    return 0
Beispiel #30
0
def subutaistart():
    coreFile = "core.ova"
    vboxFile = "VirtualBox.pkg"
    ubuntuFile = "ubuntu16-subutai-template_4.0.0_amd64.tar.gz"
    openjreFile = "openjre16-subutai-template_4.0.0_amd64.tar.gz"
    mngFile = "management"
    progress = subuco.Progress(coreFile,
                               vboxFile,
                               ubuntuFile,
                               openjreFile,
                               mngFile)

    tmpDir = subutai.GetTmpDir()
    installDir = subutai.GetInstallDir()
    rc = subup.InstallPeerPrerequisites(tmpDir, installDir, progress)
    if rc != 0:
        subutai.RaiseError("Failed to install prerequisites")
        sleep(10)
        return 29

    sleep(3)

    subup.CleanSSHKeys()
    subutai.SetSSHCredentials("subutai", "ubuntai", "127.0.0.1", 4567)

    peer = subuco.SubutaiPeer(subup.GetVirtualMachineName(),
                              progress,
                              ubuntuFile,
                              openjreFile,
                              mngFile)

    if peer.SetupVirtualMachine() != 0:
        sleep(10)
        subutai.Shutdown()
        return

    peer.ConfigureNetwork()

    rc = peer.StartVirtualMachine()

    subutai.AddStatus("Waiting for peer to start and initialize")
    sleep(40)
    if subutai.CheckVMRunning(peer.GetName()) != 0:
        peer.StartVirtualMachine()
        sleep(50)

    if subutai.CheckVMRunning(peer.GetName()) != 0:
        subutai.RaiseError("Aborting")
        sleep(15)
        subutai.Shutdown()
        return 21

    progress.spin()
    rc = peer.WaitSSH()
    if rc != 0:
        sleep(10)
        subutai.Shutdown()
        return rc

    peer.SetupSSH()
    rc = peer.waitForNetwork()
    if rc != 0:
        sleep(10)
        return rc
    rc = peer.InstallSnap()
    if rc != 0:
        subutai.RaiseError("Failed to install Subutai. Aborting")
        sleep(10)
        subutai.Shutdown()
        return rc
    peer.InitBTRFS()
    peer.SetupAlias()
    peer.RetrievePeerIP()
    progress.unspin()
    peer.InstallUbuntu()
    peer.installOpenJRE()
    peer.installManagement()
    peer.WaitPeerResponse()
    subutai.SetProgress(1.0)
    subutai.Shutdown()

    return 0