コード例 #1
0
ファイル: Runner.py プロジェクト: StratusLab/client
    def _manageExtraContext(self):
        extraContext = {}
        contextElems = []

        if self.extraContextFile:
            contextFile = open(self.extraContextFile, "rb")
            contextFileData = contextFile.read()
            contextFile.close()
            contextElems.extend(contextFileData.split("\n"))

        if self.extraContextData:
            contextElems.extend(self.extraContextData.split(Util.cliLineSplitChar))

        if self.cloudInit or (
            hasattr(self, "defaultContextMethod")
            and self.defaultContextMethod
            and self.defaultContextMethod == "cloud-init"
        ):
            if self.cloudInit is None:
                self.cloudInit = ""

            cloudInitArgs = self.cloudInit.split(Util.cliLineSplitChar)
            cloudInitData = CloudInitUtil.context_file(cloudInitArgs, default_public_key_file=self.userPublicKeyFile)
            contextElems.extend(cloudInitData.split("\n"))

        for line in contextElems:
            if len(line) == 0:
                continue

            contextLine = line.split("=")

            if len(contextLine) < 2:
                printError("Error while parsing contextualization file.\n" "Syntax error in line `%s`" % line)

            extraContext[contextLine[0]] = "=".join(contextLine[1:])

        contextData = ['%s = "%s",' % (key, value) for key, value in extraContext.items()]

        self._appendContextData(contextData)
コード例 #2
0
    def doWork(self):
        contents = Util.context_file(self.args)

        with open('cloud-init.txt', 'wb') as f:
            f.write(contents)
            f.write("\n")