Skip to content

Commit dab9795

Browse files
authored
Merge pull request #2089 from The-Loeki/vrouter-defer-configure
vRouters fixes & performance improvement
2 parents 52232b9 + 330a0c7 commit dab9795

4 files changed

Lines changed: 42 additions & 50 deletions

File tree

systemvm/patches/debian/config/opt/cloud/bin/cs/CsConfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CsConfig(object):
2626
A class to cache all the stuff that the other classes need
2727
"""
2828
__LOG_FILE = "/var/log/cloud.log"
29-
__LOG_LEVEL = "DEBUG"
29+
__LOG_LEVEL = "INFO"
3030
__LOG_FORMAT = "%(asctime)s %(levelname)-8s %(message)s"
3131
cl = None
3232

systemvm/patches/debian/config/opt/cloud/bin/merge.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,29 @@ def load(self):
4747
data = self.bdata
4848
if not os.path.exists(self.DPATH):
4949
os.makedirs(self.DPATH)
50-
self.fpath = self.DPATH + '/' + self.key + '.json'
50+
self.fpath = os.path.join(self.DPATH, self.key + '.json')
51+
5152
try:
52-
handle = open(self.fpath)
53+
with open(self.fpath, 'r') as _fh:
54+
logging.debug("Loading data bag type %s", self.key)
55+
data = json.load(_fh)
5356
except IOError:
5457
logging.debug("Creating data bag type %s", self.key)
5558
data.update({"id": self.key})
56-
else:
57-
logging.debug("Loading data bag type %s", self.key)
58-
data = json.load(handle)
59-
handle.close()
60-
self.dbag = data
59+
finally:
60+
self.dbag = data
6161

6262
def save(self, dbag):
6363
try:
64-
handle = open(self.fpath, 'w')
64+
with open(self.fpath, 'w') as _fh:
65+
logging.debug("Writing data bag type %s", self.key)
66+
json.dump(
67+
dbag, _fh,
68+
sort_keys=True,
69+
indent=2
70+
)
6571
except IOError:
6672
logging.error("Could not write data bag %s", self.key)
67-
else:
68-
logging.debug("Writing data bag type %s", self.key)
69-
logging.debug(dbag)
70-
jsono = json.dumps(dbag, indent=4, sort_keys=True)
71-
handle.write(jsono)
7273

7374
def getDataBag(self):
7475
return self.dbag

systemvm/patches/debian/config/opt/cloud/bin/update_config.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import json
2828
from cs.CsVmPassword import *
2929

30-
logging.basicConfig(filename='/var/log/cloud.log', level=logging.DEBUG, format='%(asctime)s %(filename)s %(funcName)s:%(lineno)d %(message)s')
30+
logging.basicConfig(filename='/var/log/cloud.log', level=logging.INFO, format='%(asctime)s %(filename)s %(funcName)s:%(lineno)d %(message)s')
3131

3232
# first commandline argument should be the file to process
3333
if (len(sys.argv) != 2):
@@ -52,15 +52,16 @@ def process(do_merge=True):
5252
qf.setFile(sys.argv[1])
5353
qf.do_merge = do_merge
5454
qf.load(None)
55-
5655
return qf
5756

5857

5958
def process_file():
6059
print "[INFO] process_file"
6160
qf = process()
62-
# Converge
63-
finish_config()
61+
# These can be safely deferred, dramatically speeding up loading times
62+
if not (os.environ.get('DEFER_CONFIG', False) and sys.argv[1] in ('vm_dhcp_entry.json', 'vm_metadata.json')):
63+
# Converge
64+
finish_config()
6465

6566

6667
def process_vmpasswd():

systemvm/patches/debian/config/opt/cloud/bin/vr_cfg.sh

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,29 @@ log_it() {
2727
echo "$(date) : $*" >> $log
2828
}
2929

30-
while getopts 'c:' OPTION
31-
do
32-
case $OPTION in
33-
c) cfg="$OPTARG"
34-
;;
35-
esac
36-
done
30+
while getopts 'c:' OPTION; do
31+
case $OPTION in
32+
c) cfg="$OPTARG" ;;
33+
esac; done
3734

38-
while read line
39-
do
35+
export DEFER_CONFIG=true
36+
while read line; do
4037
#comment
41-
if [[ $line == \#* ]]
42-
then
43-
continue
44-
fi
38+
if [[ $line == \#* ]]; then
39+
continue
4540

46-
if [ "$line" == "<version>" ]
47-
then
41+
elif [ "$line" == "<version>" ]; then
4842
read line
4943
version=$line
5044
log_it "VR config: configuation format version $version"
5145
#skip </version>
5246
read line
53-
continue
54-
fi
5547

56-
if [ "$line" == "<script>" ]
57-
then
48+
elif [ "$line" == "<script>" ]; then
5849
read line
5950
log_it "VR config: executing: $line"
6051
eval $line >> $log 2>&1
61-
if [ $? -ne 0 ]
62-
then
52+
if [ $? -ne 0 ]; then
6353
log_it "VR config: executing failed: $line"
6454
# expose error info to mgmt server
6555
echo "VR config: execution failed: \"$line\", check $log in VR for details " 1>&2
@@ -68,30 +58,30 @@ do
6858
#skip </script>
6959
read line
7060
log_it "VR config: execution success "
71-
continue
72-
fi
7361

74-
if [ "$line" == "<file>" ]
75-
then
62+
elif [ "$line" == "<file>" ]; then
7663
read line
7764
file=$line
7865
log_it "VR config: creating file: $file"
7966
rm -f $file
80-
while read -r line
81-
do
82-
if [ "$line" == "</file>" ]
83-
then
67+
while read -r line; do
68+
if [ "$line" == "</file>" ]; then
8469
break
8570
fi
8671
echo $line >> $file
8772
done
8873
log_it "VR config: create file success"
89-
continue
74+
9075
fi
76+
9177
done < $cfg
9278

93-
#remove the configuration file, log file should have all the records as well
94-
rm -f $cfg
79+
# archive the configuration file
80+
mv $cfg /var/cache/cloud/processed/
81+
82+
unset DEFER_CONFIG
83+
# trigger finish_config()
84+
/opt/cloud/bin/configure.py
9585

9686
# Flush kernel conntrack table
9787
log_it "VR config: Flushing conntrack table"

0 commit comments

Comments
 (0)