Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CsConfig(object):
A class to cache all the stuff that the other classes need
"""
__LOG_FILE = "/var/log/cloud.log"
__LOG_LEVEL = "DEBUG"
__LOG_LEVEL = "INFO"
__LOG_FORMAT = "%(asctime)s %(levelname)-8s %(message)s"
cl = None

Expand Down
27 changes: 14 additions & 13 deletions systemvm/patches/debian/config/opt/cloud/bin/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,29 @@ def load(self):
data = self.bdata
if not os.path.exists(self.DPATH):
os.makedirs(self.DPATH)
self.fpath = self.DPATH + '/' + self.key + '.json'
self.fpath = os.path.join(self.DPATH, self.key + '.json')

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:
logging.debug("Creating data bag type %s", self.key)
data.update({"id": self.key})
else:
logging.debug("Loading data bag type %s", self.key)
data = json.load(handle)
handle.close()
self.dbag = data
finally:
self.dbag = data

def save(self, dbag):
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:
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):
return self.dbag
Expand Down
9 changes: 5 additions & 4 deletions systemvm/patches/debian/config/opt/cloud/bin/update_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import json
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
if (len(sys.argv) != 2):
Expand All @@ -52,15 +52,16 @@ def process(do_merge=True):
qf.setFile(sys.argv[1])
qf.do_merge = do_merge
qf.load(None)

return qf


def process_file():
print "[INFO] process_file"
qf = process()
# Converge
finish_config()
# These can be safely deferred, dramatically speeding up loading times
if not (os.environ.get('DEFER_CONFIG', False) and sys.argv[1] in ('vm_dhcp_entry.json', 'vm_metadata.json')):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finish_config should be ignored when file name is vm_dhcp_entry.json or vm_metadata.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that exactly what it says or am I having a complete brainfart here???

(DEFER_CONFIG is set and vm_dhcp/vm_metadata) || finish_config()

Copy link
Contributor

@ustcweizhou ustcweizhou Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of dhcp or metadata from vr_cfg.sh, we will ignorethe finish_config and run the following at the end.
/opt/cloud/bin/configure.py vm_dhcp_entry.json
or
/opt/cloud/bin/configure.py vm_metadata.json

for others, finish_config should be executed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that exactly what it says or am I having a complete brainfart here???

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@The-Loeki looked at the code again, the code is correct.

At the first sight I thought it is
if not (os.environ.get('DEFER_CONFIG', False)) and sys.argv[1] in ('vm_dhcp_entry.json', 'vm_metadata.json'):

sorry for misunderstanding.

# Converge
finish_config()


def process_vmpasswd():
Expand Down
54 changes: 22 additions & 32 deletions systemvm/patches/debian/config/opt/cloud/bin/vr_cfg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,29 @@ log_it() {
echo "$(date) : $*" >> $log
}

while getopts 'c:' OPTION
do
case $OPTION in
c) cfg="$OPTARG"
;;
esac
done
while getopts 'c:' OPTION; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this condensed? it is not speeding up execution is it? only reducing readability afaict

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one, I am OK with.

case $OPTION in
c) cfg="$OPTARG" ;;
esac; done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

especially this line is concluding two levels of indentation at once. Please keep them for readability

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one, I agree with Daan. We are changing the indentation scope which is confusing.


while read line
do
export DEFER_CONFIG=true
while read line; do
#comment
if [[ $line == \#* ]]
then
continue
fi
if [[ $line == \#* ]]; then
continue

if [ "$line" == "<version>" ]
then
elif [ "$line" == "<version>" ]; then
read line
version=$line
log_it "VR config: configuation format version $version"
#skip </version>
read line
continue
fi

if [ "$line" == "<script>" ]
then
elif [ "$line" == "<script>" ]; then
read line
log_it "VR config: executing: $line"
eval $line >> $log 2>&1
if [ $? -ne 0 ]
then
if [ $? -ne 0 ]; then
log_it "VR config: executing failed: $line"
# expose error info to mgmt server
echo "VR config: execution failed: \"$line\", check $log in VR for details " 1>&2
Expand All @@ -68,30 +58,30 @@ do
#skip </script>
read line
log_it "VR config: execution success "
continue
fi

if [ "$line" == "<file>" ]
then
elif [ "$line" == "<file>" ]; then
read line
file=$line
log_it "VR config: creating file: $file"
rm -f $file
while read -r line
do
if [ "$line" == "</file>" ]
then
while read -r line; do
if [ "$line" == "</file>" ]; then
break
fi
echo $line >> $file
done
log_it "VR config: create file success"
continue

fi

done < $cfg

#remove the configuration file, log file should have all the records as well
rm -f $cfg
# archive the configuration file
mv $cfg /var/cache/cloud/processed/

unset DEFER_CONFIG
# trigger finish_config()
/opt/cloud/bin/configure.py

# Flush kernel conntrack table
log_it "VR config: Flushing conntrack table"
Expand Down