def setUpStaticPortForwardingForSSH(publicInterface): deviceName = _findPublicInterface(publicInterface) for index in xrange(LAST_INDEX + 1): subprocess.call([ "iptables", '-D', 'PREROUTING', '-t', 'nat', '-i', deviceName, '-p', 'tcp', '--dport', str(sshPortFromHostIndex(index)), '-j', 'DNAT' ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) for index in xrange(LAST_INDEX + 1): sh.run([ "iptables", "-A", "PREROUTING", "-t", "nat", "-i", deviceName, "-p", "tcp", "--dport", str(sshPortFromHostIndex(index)), "-j", "DNAT", "--to", "%s:22" % ipAddressFromHostIndex(index) ]) subprocess.call([ "iptables", "-t", "nat", "-D", "POSTROUTING", "-o", deviceName, "-j", 'MASQUERADE' ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) sh.run([ "iptables", "-t", "nat", "-A", "POSTROUTING", "-o", deviceName, "-j", 'MASQUERADE' ])
def _work(self): self._busy = False label, sizeGB, callback = self._queue.get() self._busy = True with globallock.lock: callback(None, "Localizing label %s" % label) logging.info("Localizing label '%(label)s'", dict(label=label)) try: sh.run(["solvent", "localize", "--label", label]) except Exception as e: logging.exception("Unable to localize label '%(label)s'", dict(label=label)) with globallock.lock: callback(False, "Unable to localize label '%s': '%s'" % (label, str(e))) return with globallock.lock: callback(None, "Done localizing label %s, Building image using inaugurator" % label) logging.info("Done localizing label '%(label)s', building image using inaugurator", dict( label=label)) vmInstance, stateMachine = self._startInauguratorVM(label, sizeGB) self._event.wait() self._event.clear() with globallock.lock: assert stateMachine.state() in [ hoststatemachine.STATE_INAUGURATION_DONE, hoststatemachine.STATE_DESTROYED] if stateMachine.state() == hoststatemachine.STATE_DESTROYED: logging.error("Unable to build image using inaugurator") callback(False, "Unable to build image using inaugurator. Review rackattack provider logs") return self._imageStore.put(filename=vmInstance.disk1Image(), imageLabel=label, sizeGB=sizeGB) stateMachine.unassign() stateMachine.destroy() callback(True, "Done building image using inaugurator (label %s)" % label) logging.info("Done building image using inaugurator (label %(label)s)", dict(label=label))
def _work(self): self._busy = False label, sizeGB, callback = self._queue.get() self._busy = True with globallock.lock: callback(None, "Localizing label %s" % label) logging.info("Localizing label '%(label)s'", dict(label=label)) try: sh.run(["solvent", "localize", "--label", label]) except Exception as e: logging.exception("Unable to localize label '%(label)s'", dict(label=label)) with globallock.lock: callback( False, "Unable to localize label '%s': '%s'" % (label, str(e))) return with globallock.lock: callback( None, "Done localizing label %s, Building image using inaugurator" % label) logging.info( "Done localizing label '%(label)s', building image using inaugurator", dict(label=label)) vmInstance, stateMachine = self._startInauguratorVM(label, sizeGB) self._event.wait() self._event.clear() with globallock.lock: assert stateMachine.state() in [ hoststatemachine.STATE_INAUGURATION_DONE, hoststatemachine.STATE_DESTROYED ] if stateMachine.state() == hoststatemachine.STATE_DESTROYED: logging.error("Unable to build image using inaugurator") callback( False, "Unable to build image using inaugurator. Review rackattack provider logs" ) return self._imageStore.put(filename=vmInstance.disk1Image(), imageLabel=label, sizeGB=sizeGB) stateMachine.unassign() stateMachine.destroy() callback( True, "Done building image using inaugurator (label %s)" % label) logging.info("Done building image using inaugurator (label %(label)s)", dict(label=label))
def _verifyLabelsExistsInOsmosis(self, labels): labels = set(labels) for label in labels: existingLabels = sh.run([ "osmosis", "listlabels", label, "--objectStores", self._osmosisServer + ":1010"]).strip() existingLabels = existingLabels.splitlines() if label not in existingLabels: raise Exception("Label '%s' does not exist on object store" % label)
def setUpStaticPortForwardingForSSH(publicInterface): deviceName = _findPublicInterface(publicInterface) for index in xrange(LAST_INDEX + 1): subprocess.call([ "iptables", '-D', 'PREROUTING', '-t', 'nat', '-i', deviceName, '-p', 'tcp', '--dport', str(sshPortFromHostIndex(index)), '-j', 'DNAT'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) for index in xrange(LAST_INDEX + 1): sh.run([ "iptables", "-A", "PREROUTING", "-t", "nat", "-i", deviceName, "-p", "tcp", "--dport", str(sshPortFromHostIndex(index)), "-j", "DNAT", "--to", "%s:22" % ipAddressFromHostIndex(index)]) subprocess.call([ "iptables", "-t", "nat", "-D", "POSTROUTING", "-o", deviceName, "-j", 'MASQUERADE'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) sh.run([ "iptables", "-t", "nat", "-A", "POSTROUTING", "-o", deviceName, "-j", 'MASQUERADE'])
def _verifyLabelsExistsInOsmosis(self, labels): for label in labels: exists = sh.run([ "osmosis", "listlabels", label, "--objectStores", self._osmosisServer + ":1010" ]).strip() if not exists: raise Exception("Label '%s' does not exist on object store" % label)
def _verifyLabelsExistsInOsmosis(self, labels): labels = set(labels) for label in labels: existingLabels = sh.run([ "osmosis", "listlabels", label, "--objectStores", self._osmosisServer + ":1010"]).strip() existingLabels = existingLabels.splitlines() if label not in existingLabels: self._broadcaster.allocationRejected(reason="labelDoesNotExist") raise Exception("Label '%s' does not exist on object store" % label)
def _verifyLabelsExistsInOsmosis(self, labels): for label in labels: exists = sh.run([ "osmosis", "listlabels", label, "--objectStores", self._osmosisServer + ":1010"]).strip() if not exists: raise Exception("Label '%s' does not exist on object store" % label)
def create(image, sizeGB): dirname = os.path.dirname(image) if not os.path.isdir(dirname): os.makedirs(dirname, 0777) sh.run(['qemu-img', 'create', '-f', 'qcow2', image, '%dG' % sizeGB]) os.chmod(image, 0666)
def deriveCopyOnWrite(original, newImage, originalFormat='qcow2'): sh.run(['qemu-img', 'create', '-F', originalFormat, '-f', 'qcow2', '-b', original, newImage]) os.chmod(newImage, 0666)