Merge pull request #390 from FirmlyReality/lxc_upgrade
remove env variable in lxc conf hook to support 2.0.11 lxc version.
This commit is contained in:
commit
401b249ab2
|
@ -25,8 +25,8 @@ lxc.network.type = veth
|
||||||
lxc.network.name = eth0
|
lxc.network.name = eth0
|
||||||
# veth.pair is limited in 16 bytes
|
# veth.pair is limited in 16 bytes
|
||||||
lxc.network.veth.pair = %VETHPAIR%
|
lxc.network.veth.pair = %VETHPAIR%
|
||||||
lxc.network.script.up = Bridge=%BRNAME% %LXCSCRIPT%/lxc-ifup
|
lxc.network.script.up = %LXCSCRIPT%/lxc-ifup
|
||||||
lxc.network.script.down = Bridge=%BRNAME% %LXCSCRIPT%/lxc-ifdown
|
lxc.network.script.down = %LXCSCRIPT%/lxc-ifdown
|
||||||
lxc.network.ipv4 = %IP%
|
lxc.network.ipv4 = %IP%
|
||||||
lxc.network.ipv4.gateway = %GATEWAY%
|
lxc.network.ipv4.gateway = %GATEWAY%
|
||||||
lxc.network.flags = up
|
lxc.network.flags = up
|
||||||
|
@ -50,7 +50,7 @@ lxc.mount.entry = %FS_PREFIX%/global/users/%USERNAME%/ssh %ROOTFS%/root/.ssh non
|
||||||
lxc.mount.entry = %FS_PREFIX%/local/temp/%LXCNAME%/ %ROOTFS%/tmp none bind,rw,create=dir 0 0
|
lxc.mount.entry = %FS_PREFIX%/local/temp/%LXCNAME%/ %ROOTFS%/tmp none bind,rw,create=dir 0 0
|
||||||
|
|
||||||
# setting hostname
|
# setting hostname
|
||||||
lxc.hook.pre-start = HNAME=%HOSTNAME% %LXCSCRIPT%/lxc-prestart
|
lxc.hook.pre-start = %LXCSCRIPT%/lxc-prestart
|
||||||
|
|
||||||
# setting nfs softlink
|
# setting nfs softlink
|
||||||
#lxc.hook.mount = %LXCSCRIPT%/lxc-mount
|
#lxc.hook.mount = %LXCSCRIPT%/lxc-mount
|
||||||
|
|
|
@ -25,8 +25,8 @@ lxc.network.type = veth
|
||||||
lxc.network.name = eth0
|
lxc.network.name = eth0
|
||||||
# veth.pair is limited in 16 bytes
|
# veth.pair is limited in 16 bytes
|
||||||
lxc.network.veth.pair = %VETHPAIR%
|
lxc.network.veth.pair = %VETHPAIR%
|
||||||
lxc.network.script.up = Bridge=docklet-br-%UserID% %LXCSCRIPT%/lxc-ifup
|
lxc.network.script.up = %LXCSCRIPT%/lxc-ifup
|
||||||
lxc.network.script.down = Bridge=docklet-br-%UserID% %LXCSCRIPT%/lxc-ifdown
|
lxc.network.script.down = %LXCSCRIPT%/lxc-ifdown
|
||||||
lxc.network.ipv4 = %IP%
|
lxc.network.ipv4 = %IP%
|
||||||
lxc.network.ipv4.gateway = %GATEWAY%
|
lxc.network.ipv4.gateway = %GATEWAY%
|
||||||
lxc.network.flags = up
|
lxc.network.flags = up
|
||||||
|
@ -50,7 +50,7 @@ lxc.mount.entry = %FS_PREFIX%/global/users/%USERNAME%/ssh %ROOTFS%/root/.ssh non
|
||||||
lxc.mount.entry = %FS_PREFIX%/local/temp/%LXCNAME%/ %ROOTFS%/tmp none bind,rw,create=dir 0 0
|
lxc.mount.entry = %FS_PREFIX%/local/temp/%LXCNAME%/ %ROOTFS%/tmp none bind,rw,create=dir 0 0
|
||||||
|
|
||||||
# setting hostname
|
# setting hostname
|
||||||
lxc.hook.pre-start = HNAME=%HOSTNAME% %LXCSCRIPT%/lxc-prestart
|
lxc.hook.pre-start = %LXCSCRIPT%/lxc-prestart
|
||||||
|
|
||||||
# setting nfs softlink
|
# setting nfs softlink
|
||||||
#lxc.hook.mount = %LXCSCRIPT%/lxc-mount
|
#lxc.hook.mount = %LXCSCRIPT%/lxc-mount
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
# $4 : network type, for example, veth
|
# $4 : network type, for example, veth
|
||||||
# $5 : value of lxc.network.veth.pair
|
# $5 : value of lxc.network.veth.pair
|
||||||
|
|
||||||
|
. $LXC_ROOTFS_PATH/../env.conf
|
||||||
|
|
||||||
ovs-vsctl --if-exists del-port $Bridge $5
|
ovs-vsctl --if-exists del-port $Bridge $5
|
||||||
cnt=$(ovs-vsctl list-ports ${Bridge} | wc -l)
|
cnt=$(ovs-vsctl list-ports ${Bridge} | wc -l)
|
||||||
if [ "$cnt" = "1" ]; then
|
if [ "$cnt" = "1" ]; then
|
||||||
|
|
|
@ -7,5 +7,7 @@
|
||||||
# $4 : network type, for example, veth
|
# $4 : network type, for example, veth
|
||||||
# $5 : value of lxc.network.veth.pair
|
# $5 : value of lxc.network.veth.pair
|
||||||
|
|
||||||
|
. $LXC_ROOTFS_PATH/../env.conf
|
||||||
|
|
||||||
ovs-vsctl --may-exist add-br $Bridge
|
ovs-vsctl --may-exist add-br $Bridge
|
||||||
ovs-vsctl --may-exist add-port $Bridge $5
|
ovs-vsctl --may-exist add-port $Bridge $5
|
||||||
|
|
|
@ -13,4 +13,6 @@
|
||||||
# $LXC_ROOTFS_PATH: this is the lxc.rootfs entry for the container.
|
# $LXC_ROOTFS_PATH: this is the lxc.rootfs entry for the container.
|
||||||
# Note this is likely not where the mounted rootfs is to be found, use LXC_ROOTFS_MOUNT for that.
|
# Note this is likely not where the mounted rootfs is to be found, use LXC_ROOTFS_MOUNT for that.
|
||||||
|
|
||||||
|
. $LXC_ROOTFS_PATH/../env.conf
|
||||||
|
|
||||||
echo $HNAME > $LXC_ROOTFS_PATH/etc/hostname
|
echo $HNAME > $LXC_ROOTFS_PATH/etc/hostname
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import subprocess, os, json
|
import subprocess, os, json, traceback
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
from utils import env, imagemgr
|
from utils import env, imagemgr
|
||||||
from utils.lvmtool import sys_run, check_volume
|
from utils.lvmtool import sys_run, check_volume
|
||||||
|
@ -24,6 +24,17 @@ class Container(object):
|
||||||
self.imgmgr = imagemgr.ImageMgr()
|
self.imgmgr = imagemgr.ImageMgr()
|
||||||
self.historymgr = History_Manager()
|
self.historymgr = History_Manager()
|
||||||
|
|
||||||
|
def prepare_hook_conf(self, conf_path, env_dict):
|
||||||
|
try:
|
||||||
|
confile = open(conf_path, "w")
|
||||||
|
for k,v in env_dict.items():
|
||||||
|
confile.write("%s=%s\n"%(k,v))
|
||||||
|
confile.close()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
return [False, e]
|
||||||
|
return [True, ""]
|
||||||
|
|
||||||
def create_container(self, lxc_name, proxy_server_ip, username, uid, setting, clustername, clusterid, containerid, hostname, ip, gateway, image):
|
def create_container(self, lxc_name, proxy_server_ip, username, uid, setting, clustername, clusterid, containerid, hostname, ip, gateway, image):
|
||||||
logger.info("create container %s of %s for %s" %(lxc_name, clustername, username))
|
logger.info("create container %s of %s for %s" %(lxc_name, clustername, username))
|
||||||
try:
|
try:
|
||||||
|
@ -85,6 +96,11 @@ class Container(object):
|
||||||
conffile.write(conftext)
|
conffile.write(conftext)
|
||||||
conffile.close()
|
conffile.close()
|
||||||
|
|
||||||
|
hook_env = {}
|
||||||
|
hook_env['Bridge'] = "docklet-br-%d" % uid
|
||||||
|
hook_env['HNAME'] = hostname
|
||||||
|
self.prepare_hook_conf(rootfs+"/../env.conf",hook_env)
|
||||||
|
|
||||||
#logger.debug(Ret.stdout.decode('utf-8'))
|
#logger.debug(Ret.stdout.decode('utf-8'))
|
||||||
logger.info("create container %s success" % lxc_name)
|
logger.info("create container %s success" % lxc_name)
|
||||||
|
|
||||||
|
|
|
@ -324,6 +324,16 @@ class TaskWorker(rpc_pb2_grpc.WorkerServicer):
|
||||||
|
|
||||||
return rpc_pb2.Reply(status=rpc_pb2.Reply.ACCEPTED,message="")
|
return rpc_pb2.Reply(status=rpc_pb2.Reply.ACCEPTED,message="")
|
||||||
|
|
||||||
|
def prepare_hook_conf(self, conf_path, env_dict):
|
||||||
|
try:
|
||||||
|
confile = open(conf_path, "w")
|
||||||
|
for k,v in env_dict.items():
|
||||||
|
confile.write("%s=%s\n"%(k,v))
|
||||||
|
confile.close()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
return [False, e]
|
||||||
|
return [True, ""]
|
||||||
|
|
||||||
#accquire ip and create a container
|
#accquire ip and create a container
|
||||||
def create_container(self,taskid,vnodeid,username,image,lxcname,quota,ipaddr,gateway,brname,hostname):
|
def create_container(self,taskid,vnodeid,username,image,lxcname,quota,ipaddr,gateway,brname,hostname):
|
||||||
|
@ -353,7 +363,6 @@ class TaskWorker(rpc_pb2_grpc.WorkerServicer):
|
||||||
content = content.replace("%LXCNAME%",lxcname)
|
content = content.replace("%LXCNAME%",lxcname)
|
||||||
content = content.replace("%VETHPAIR%",str(taskid)+"-"+str(vnodeid))
|
content = content.replace("%VETHPAIR%",str(taskid)+"-"+str(vnodeid))
|
||||||
content = content.replace("%IP%",ipaddr)
|
content = content.replace("%IP%",ipaddr)
|
||||||
content = content.replace("%BRNAME%",brname)
|
|
||||||
content = content.replace("%GATEWAY%",gateway)
|
content = content.replace("%GATEWAY%",gateway)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
@ -367,7 +376,11 @@ class TaskWorker(rpc_pb2_grpc.WorkerServicer):
|
||||||
conffile = open("/var/lib/lxc/%s/config" % lxcname, 'w')
|
conffile = open("/var/lib/lxc/%s/config" % lxcname, 'w')
|
||||||
conffile.write(conftext)
|
conffile.write(conftext)
|
||||||
conffile.close()
|
conffile.close()
|
||||||
return [True, ""]
|
|
||||||
|
hook_env = {}
|
||||||
|
hook_env['Bridge'] = brname
|
||||||
|
hook_env['HNAME'] = hostname
|
||||||
|
return self.prepare_hook_conf(rootfs+"/../env.conf",hook_env)
|
||||||
|
|
||||||
def write_output(self,lxcname,tmplogpath,filepath):
|
def write_output(self,lxcname,tmplogpath,filepath):
|
||||||
cmd = "lxc-attach -n " + lxcname + " -- mv %s %s"
|
cmd = "lxc-attach -n " + lxcname + " -- mv %s %s"
|
||||||
|
|
Loading…
Reference in New Issue