Beispiel #1
0
 def exposePort(self, local_port, public_port, scheme):
     keyfile = self.core.getInsecureKeyFile()
     keyfile = Shell.normalizePath(keyfile)
     forward_descr = "0.0.0.0:%s:127.0.0.1:%s" % (public_port, local_port)
     engineIP = self.getSSHIP()
     enginePort = str(self.getSSHPort())
     cmdPath = "ssh"
     cmdArgs = [
         "ssh", "-N", "-L", forward_descr, engineIP, "-l", "substance",
         "-p", enginePort, "-o", "StrictHostKeyChecking=no", "-o",
         "UserKnownHostsFile=/dev/null", "-i", keyfile
     ]
     sudo = False
     if public_port < 1024 and not Shell.isCygwin():
         sudo = True
     self.logAdapter.info(
         "Exposing port %s as %s; kill the process (CTRL-C) to un-expose.",
         local_port, public_port)
     with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as s:
         s.connect(("8.8.8.8", 80))
         ip = s.getsockname()[0]
         if scheme:
             self.logAdapter.info("%s://%s:%s is now available.", scheme,
                                  ip, public_port)
         else:
             self.logAdapter.info(
                 "Others can now connect to port %s via IP %s.",
                 public_port, ip)
     Shell.execvp(cmdPath, cmdArgs, {}, sudo=sudo)
Beispiel #2
0
def importOVF(importParams, name, ovfFile):
    '''
    Import the OVF file as a virtual box vm.
    '''
    ovfFile = Shell.normalizePath(ovfFile)
    importParams.insert(0, '"' + ovfFile + '"')
    return vboxManager("import", " ".join(importParams)) \
        .then(defer(readMachineID, name))
Beispiel #3
0
    def getUnisonArgs(self, direction, path=''):
        folder = self.engine.getEngineFolders()[0]
        localRoot = Shell.normalizePath(os.path.join(folder.hostPath, path))
        remoteRoot = 'ssh://substance@%s/%s/%s' % (
            self.engine.getSSHIP(), folder.guestPath.rstrip('/'),
            path.lstrip('/'))

        # Direction arguments
        if direction == Syncher.UP:
            directionArgs = [
                '-nocreation', localRoot, '-nodeletion', localRoot,
                '-noupdate', localRoot
            ]
        elif direction == Syncher.DOWN:
            directionArgs = [
                '-nocreation', remoteRoot, '-nodeletion', remoteRoot,
                '-noupdate', remoteRoot
            ]
        else:
            directionArgs = ['-prefer', 'newer', '-copyonconflict']

        # User args
        userArgs = folder.syncArgs

        # Other arguments
        rootArgs = [localRoot, remoteRoot]
        ignoreArgs = [
            item for sublist in [['-ignore', 'Name ' + excl]
                                 for excl in folder.excludes]
            for item in sublist
        ]

        # SSH config
        transport = "-p %s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" % self.engine.getSSHPort(
        )
        if self.keyfile is not None:
            transport += " -i %s" % Shell.normalizePath(self.keyfile)

        # Assemble everything
        args = ['-batch', '-repeat', 'watch', '-sshargs', transport] + \
            userArgs + directionArgs + ignoreArgs + rootArgs
        if self.ignoreArchives and '-ignorearchives' not in args:
            args.insert(0, '-ignorearchives')
        return args
Beispiel #4
0
 def getUnisonEnv(self):
     # Add the unison-fsmonitor binary to PATH
     path = self.getUnisonSupportDirectory() + os.pathsep + os.environ.get(
         'PATH', '')
     # Tell unison to save all replica state to ~/.substance/unison
     unisonDir = Shell.normalizePath(
         os.path.join(self.engine.core.getBasePath(), 'unison'))
     homeDir = os.environ.get('HOME', os.path.expanduser('~'))
     return {
         'UNISON': unisonDir,
         'PATH': path,
         'HOME': homeDir,
         'SSH_AUTH_SOCK': os.environ.get('SSH_AUTH_SOCK', '')
     }
Beispiel #5
0
def inspectOVF(ovfFile):
    '''
    Inspect an OVF file to extract it's examined output
    '''
    return vboxManager("import", '-n "%s"' % Shell.normalizePath(ovfFile))