remove env variable in lxc conf hook to support 2.0.11 lxc version.

This commit is contained in:
zhuyj17 2019-05-27 01:06:09 +08:00
parent 863832b4b7
commit aad5ef5a17
7 changed files with 45 additions and 10 deletions

View File

@ -25,8 +25,8 @@ lxc.network.type = veth
lxc.network.name = eth0
# veth.pair is limited in 16 bytes
lxc.network.veth.pair = %VETHPAIR%
lxc.network.script.up = Bridge=%BRNAME% %LXCSCRIPT%/lxc-ifup
lxc.network.script.down = Bridge=%BRNAME% %LXCSCRIPT%/lxc-ifdown
lxc.network.script.up = %LXCSCRIPT%/lxc-ifup
lxc.network.script.down = %LXCSCRIPT%/lxc-ifdown
lxc.network.ipv4 = %IP%
lxc.network.ipv4.gateway = %GATEWAY%
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
# setting hostname
lxc.hook.pre-start = HNAME=%HOSTNAME% %LXCSCRIPT%/lxc-prestart
lxc.hook.pre-start = %LXCSCRIPT%/lxc-prestart
# setting nfs softlink
#lxc.hook.mount = %LXCSCRIPT%/lxc-mount

View File

@ -25,8 +25,8 @@ lxc.network.type = veth
lxc.network.name = eth0
# veth.pair is limited in 16 bytes
lxc.network.veth.pair = %VETHPAIR%
lxc.network.script.up = Bridge=docklet-br-%UserID% %LXCSCRIPT%/lxc-ifup
lxc.network.script.down = Bridge=docklet-br-%UserID% %LXCSCRIPT%/lxc-ifdown
lxc.network.script.up = %LXCSCRIPT%/lxc-ifup
lxc.network.script.down = %LXCSCRIPT%/lxc-ifdown
lxc.network.ipv4 = %IP%
lxc.network.ipv4.gateway = %GATEWAY%
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
# setting hostname
lxc.hook.pre-start = HNAME=%HOSTNAME% %LXCSCRIPT%/lxc-prestart
lxc.hook.pre-start = %LXCSCRIPT%/lxc-prestart
# setting nfs softlink
#lxc.hook.mount = %LXCSCRIPT%/lxc-mount

View File

@ -6,6 +6,8 @@
# $4 : network type, for example, veth
# $5 : value of lxc.network.veth.pair
. $LXC_ROOTFS_PATH/../env.conf
ovs-vsctl --if-exists del-port $Bridge $5
cnt=$(ovs-vsctl list-ports ${Bridge} | wc -l)
if [ "$cnt" = "1" ]; then

View File

@ -7,5 +7,7 @@
# $4 : network type, for example, veth
# $5 : value of lxc.network.veth.pair
. $LXC_ROOTFS_PATH/../env.conf
ovs-vsctl --may-exist add-br $Bridge
ovs-vsctl --may-exist add-port $Bridge $5

View File

@ -10,7 +10,9 @@
# $LXC_ROOTFS_MOUNT: the path to the mounted root filesystem.
# $LXC_CONFIG_FILE: the path to the container configuration file.
# $LXC_SRC_NAME: in the case of the clone hook, this is the original container's name.
# $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.
. $LXC_ROOTFS_PATH/../env.conf
echo $HNAME > $LXC_ROOTFS_PATH/etc/hostname

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3
import subprocess, os, json
import subprocess, os, json, traceback
from utils.log import logger
from utils import env, imagemgr
from utils.lvmtool import sys_run, check_volume
@ -24,6 +24,17 @@ class Container(object):
self.imgmgr = imagemgr.ImageMgr()
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):
logger.info("create container %s of %s for %s" %(lxc_name, clustername, username))
try:
@ -85,6 +96,11 @@ class Container(object):
conffile.write(conftext)
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.info("create container %s success" % lxc_name)

View File

@ -324,6 +324,16 @@ class TaskWorker(rpc_pb2_grpc.WorkerServicer):
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
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("%VETHPAIR%",str(taskid)+"-"+str(vnodeid))
content = content.replace("%IP%",ipaddr)
content = content.replace("%BRNAME%",brname)
content = content.replace("%GATEWAY%",gateway)
return content
@ -367,7 +376,11 @@ class TaskWorker(rpc_pb2_grpc.WorkerServicer):
conffile = open("/var/lib/lxc/%s/config" % lxcname, 'w')
conffile.write(conftext)
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):
cmd = "lxc-attach -n " + lxcname + " -- mv %s %s"