mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge release branch 4.9 to master
* 4.9: vRouter defer configure: Resolve merge conflicts vRouter: vr_cfg: style consistency fixes vRouter: vr_cfg: Keep the original cfg vRouter: prevent fh leakage and use buffered writes in DataBags
This commit is contained in:
commit
b9a4cb8770
@ -26,7 +26,7 @@ class CsConfig(object):
|
|||||||
A class to cache all the stuff that the other classes need
|
A class to cache all the stuff that the other classes need
|
||||||
"""
|
"""
|
||||||
__LOG_FILE = "/var/log/cloud.log"
|
__LOG_FILE = "/var/log/cloud.log"
|
||||||
__LOG_LEVEL = "DEBUG"
|
__LOG_LEVEL = "INFO"
|
||||||
__LOG_FORMAT = "%(asctime)s %(levelname)-8s %(message)s"
|
__LOG_FORMAT = "%(asctime)s %(levelname)-8s %(message)s"
|
||||||
cl = None
|
cl = None
|
||||||
|
|
||||||
|
|||||||
@ -47,28 +47,29 @@ class DataBag:
|
|||||||
data = self.bdata
|
data = self.bdata
|
||||||
if not os.path.exists(self.DPATH):
|
if not os.path.exists(self.DPATH):
|
||||||
os.makedirs(self.DPATH)
|
os.makedirs(self.DPATH)
|
||||||
self.fpath = self.DPATH + '/' + self.key + '.json'
|
self.fpath = os.path.join(self.DPATH, self.key + '.json')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handle = open(self.fpath)
|
with open(self.fpath, 'r') as _fh:
|
||||||
|
logging.debug("Loading data bag type %s", self.key)
|
||||||
|
data = json.load(_fh)
|
||||||
except IOError:
|
except IOError:
|
||||||
logging.debug("Creating data bag type %s", self.key)
|
logging.debug("Creating data bag type %s", self.key)
|
||||||
data.update({"id": self.key})
|
data.update({"id": self.key})
|
||||||
else:
|
finally:
|
||||||
logging.debug("Loading data bag type %s", self.key)
|
self.dbag = data
|
||||||
data = json.load(handle)
|
|
||||||
handle.close()
|
|
||||||
self.dbag = data
|
|
||||||
|
|
||||||
def save(self, dbag):
|
def save(self, dbag):
|
||||||
try:
|
try:
|
||||||
handle = open(self.fpath, 'w')
|
with open(self.fpath, 'w') as _fh:
|
||||||
|
logging.debug("Writing data bag type %s", self.key)
|
||||||
|
json.dump(
|
||||||
|
dbag, _fh,
|
||||||
|
sort_keys=True,
|
||||||
|
indent=2
|
||||||
|
)
|
||||||
except IOError:
|
except IOError:
|
||||||
logging.error("Could not write data bag %s", self.key)
|
logging.error("Could not write data bag %s", self.key)
|
||||||
else:
|
|
||||||
logging.debug("Writing data bag type %s", self.key)
|
|
||||||
logging.debug(dbag)
|
|
||||||
jsono = json.dumps(dbag, indent=4, sort_keys=True)
|
|
||||||
handle.write(jsono)
|
|
||||||
|
|
||||||
def getDataBag(self):
|
def getDataBag(self):
|
||||||
return self.dbag
|
return self.dbag
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import configure
|
|||||||
import json
|
import json
|
||||||
from cs.CsVmPassword import *
|
from cs.CsVmPassword import *
|
||||||
|
|
||||||
logging.basicConfig(filename='/var/log/cloud.log', level=logging.DEBUG, format='%(asctime)s %(filename)s %(funcName)s:%(lineno)d %(message)s')
|
logging.basicConfig(filename='/var/log/cloud.log', level=logging.INFO, format='%(asctime)s %(filename)s %(funcName)s:%(lineno)d %(message)s')
|
||||||
|
|
||||||
# first commandline argument should be the file to process
|
# first commandline argument should be the file to process
|
||||||
if (len(sys.argv) != 2):
|
if (len(sys.argv) != 2):
|
||||||
@ -52,15 +52,16 @@ def process(do_merge=True):
|
|||||||
qf.setFile(sys.argv[1])
|
qf.setFile(sys.argv[1])
|
||||||
qf.do_merge = do_merge
|
qf.do_merge = do_merge
|
||||||
qf.load(None)
|
qf.load(None)
|
||||||
|
|
||||||
return qf
|
return qf
|
||||||
|
|
||||||
|
|
||||||
def process_file():
|
def process_file():
|
||||||
print "[INFO] process_file"
|
print "[INFO] process_file"
|
||||||
qf = process()
|
qf = process()
|
||||||
# Converge
|
# These can be safely deferred, dramatically speeding up loading times
|
||||||
finish_config()
|
if not (os.environ.get('DEFER_CONFIG', False) and sys.argv[1] in ('vm_dhcp_entry.json', 'vm_metadata.json')):
|
||||||
|
# Converge
|
||||||
|
finish_config()
|
||||||
|
|
||||||
|
|
||||||
def process_vmpasswd():
|
def process_vmpasswd():
|
||||||
|
|||||||
@ -27,39 +27,29 @@ log_it() {
|
|||||||
echo "$(date) : $*" >> $log
|
echo "$(date) : $*" >> $log
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts 'c:' OPTION
|
while getopts 'c:' OPTION; do
|
||||||
do
|
case $OPTION in
|
||||||
case $OPTION in
|
c) cfg="$OPTARG" ;;
|
||||||
c) cfg="$OPTARG"
|
esac; done
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
while read line
|
export DEFER_CONFIG=true
|
||||||
do
|
while read line; do
|
||||||
#comment
|
#comment
|
||||||
if [[ $line == \#* ]]
|
if [[ $line == \#* ]]; then
|
||||||
then
|
continue
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$line" == "<version>" ]
|
elif [ "$line" == "<version>" ]; then
|
||||||
then
|
|
||||||
read line
|
read line
|
||||||
version=$line
|
version=$line
|
||||||
log_it "VR config: configuation format version $version"
|
log_it "VR config: configuation format version $version"
|
||||||
#skip </version>
|
#skip </version>
|
||||||
read line
|
read line
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$line" == "<script>" ]
|
elif [ "$line" == "<script>" ]; then
|
||||||
then
|
|
||||||
read line
|
read line
|
||||||
log_it "VR config: executing: $line"
|
log_it "VR config: executing: $line"
|
||||||
eval $line >> $log 2>&1
|
eval $line >> $log 2>&1
|
||||||
if [ $? -ne 0 ]
|
if [ $? -ne 0 ]; then
|
||||||
then
|
|
||||||
log_it "VR config: executing failed: $line"
|
log_it "VR config: executing failed: $line"
|
||||||
# expose error info to mgmt server
|
# expose error info to mgmt server
|
||||||
echo "VR config: execution failed: \"$line\", check $log in VR for details " 1>&2
|
echo "VR config: execution failed: \"$line\", check $log in VR for details " 1>&2
|
||||||
@ -68,30 +58,30 @@ do
|
|||||||
#skip </script>
|
#skip </script>
|
||||||
read line
|
read line
|
||||||
log_it "VR config: execution success "
|
log_it "VR config: execution success "
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$line" == "<file>" ]
|
elif [ "$line" == "<file>" ]; then
|
||||||
then
|
|
||||||
read line
|
read line
|
||||||
file=$line
|
file=$line
|
||||||
log_it "VR config: creating file: $file"
|
log_it "VR config: creating file: $file"
|
||||||
rm -f $file
|
rm -f $file
|
||||||
while read -r line
|
while read -r line; do
|
||||||
do
|
if [ "$line" == "</file>" ]; then
|
||||||
if [ "$line" == "</file>" ]
|
|
||||||
then
|
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
echo $line >> $file
|
echo $line >> $file
|
||||||
done
|
done
|
||||||
log_it "VR config: create file success"
|
log_it "VR config: create file success"
|
||||||
continue
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done < $cfg
|
done < $cfg
|
||||||
|
|
||||||
#remove the configuration file, log file should have all the records as well
|
# archive the configuration file
|
||||||
rm -f $cfg
|
mv $cfg /var/cache/cloud/processed/
|
||||||
|
|
||||||
|
unset DEFER_CONFIG
|
||||||
|
# trigger finish_config()
|
||||||
|
/opt/cloud/bin/configure.py
|
||||||
|
|
||||||
# Flush kernel conntrack table
|
# Flush kernel conntrack table
|
||||||
log_it "VR config: Flushing conntrack table"
|
log_it "VR config: Flushing conntrack table"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user