コード例 #1
0
ファイル: run.py プロジェクト: nl5887/upscale
def run(namespace, project):
    datadir = os.path.join(os.path.dirname(os.path.realpath(upscale.__file__)), "data")
    print datadir

    session = Session()
    namespace = session.query(Namespace).filter(Namespace.name == namespace).first()
    if not namespace:
        raise Exception("Unknown namespace")

    project = namespace.projects.filter(Project.name == project).first()
    if not project:
        raise Exception("Unknown project")

    from datetime import date

    bi = yaml.load(file(os.path.join(datadir, "runtime/{0}.yaml").format(project.template), "r"))

    container = "{0}_{1}_{2}".format(namespace.name, project.name, datetime.now().strftime("%y%m%d%H%M%S"))
    rootfs = "/var/lib/lxc/{0}/rootfs".format(container)
    mirror = "http://archive.ubuntu.com/ubuntu"
    security_mirror = "http://security.ubuntu.com/ubuntu"
    release = "raring"
    base = project.template + "_" + str(bi["version"])

    print ("Using runtime {0}".format(base))

    print (lxc.create(container))

    datadir = os.path.join(rootfs, "data")
    if not os.path.exists(datadir):
        os.mkdir(datadir)

    cmd("mount --bind /data/{0}/{1} {2}/data".format(namespace.name, project.name, rootfs))

    print lxc.start(container)
    print lxc.wait(container)

    import time

    hostname = None

    while not hostname:
        try:
            import socket

            (hostname, aliaslist, ipaddrlist) = socket.gethostbyname_ex(container)
        except socket.gaierror, exc:
            print "Container not reachable yet... Waiting 1 second..."
            time.sleep(1)
コード例 #2
0
def run (namespace, project):
	datadir = os.path.join(os.path.dirname(os.path.realpath(upscale.__file__)), 'data')
	print datadir

	session = Session()
	namespace = session.query(Namespace).filter(Namespace.name==namespace).first()
	if (not namespace):
		raise Exception("Unknown namespace")

	project = namespace.projects.filter(Project.name==project).first()
	if (not project):
		raise Exception("Unknown project")

	from datetime import date
	bi = yaml.load(file(os.path.join(datadir, 'runtime/{0}.yaml').format(project.template), 'r'))	
	
	container="{0}_{1}_{2}".format(namespace.name, project.name, datetime.now().strftime("%y%m%d%H%M%S"))
	rootfs="/var/lib/lxc/{0}/rootfs".format(container)
	mirror="http://archive.ubuntu.com/ubuntu"
	security_mirror="http://security.ubuntu.com/ubuntu"
	release="raring"
	base=project.template + '_' + str(bi['version'])

	print ("Using runtime {0}".format(base))

	print (lxc.create(container,))
	
	datadir  = os.path.join (rootfs, "data")
	if not os.path.exists(datadir):
		os.mkdir(datadir)

	cmd("mount --bind /data/{0}/{1} {2}/data".format(namespace.name, project.name, rootfs))

	print lxc.start(container)
	print lxc.wait(container)

	import time
	hostname = None

	while (not hostname):
		try:
			import socket
			(hostname, aliaslist, ipaddrlist) = socket.gethostbyname_ex (container)
		except socket.gaierror, exc:
			print 'Container not reachable yet... Waiting 1 second...'
			time.sleep(1)
コード例 #3
0
ファイル: worker.py プロジェクト: nl5887/upscale
	def wait(self, name, state='RUNNING'):
		lxc.wait(name, state)
		return (True)
コード例 #4
0
ファイル: worker.py プロジェクト: nl5887/upscale
 def wait(self, name, state='RUNNING'):
     lxc.wait(name, state)
     return (True)