From 7391fa71c7956cc89dc68c21f64c109bc3a2d2d4 Mon Sep 17 00:00:00 2001 From: Thirumal Ravula Date: Mon, 29 Sep 2014 12:13:06 +0530 Subject: [PATCH] Setting the environment in the container --- README.md | 18 ++++++++++ config/config.json | 4 +-- src/VMManager/VMManager.py | 7 ++-- src/VMManager/config.json | 67 ++++++++++++++++++++++++++++++++++++++ src/VMManager/envsetup.py | 64 ++++++++++++++++++++++++++++++++++++ src/adapters/settings.py | 2 +- src/settings.py | 2 +- 7 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 src/VMManager/config.json create mode 100644 src/VMManager/envsetup.py diff --git a/README.md b/README.md index d7a7dae..2643ba1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ ovpl ==== + +1) Edit the file ovpl/config/config.json to set the proxies + + "ENVIRONMENT": { + "HTTP_PROXY":"proxy.vlabs.ac.in:8080", + "HTTPS_PROXY":"proxy.vlabs.ac.in:8080" + }, + +2) Do the same with the file ovpl/src/VMManager/config.json + +3) Edit the file ovpl/src/settings.py to set the + SUBNET field to match with the subnet of your base machine + + If the ip address of your base machine is 10.2.58.XXX, + + SUBNET = ["10.2.58.12/28"] + +4) Do the same with the file ovpl/src/adapters/settings.py \ No newline at end of file diff --git a/config/config.json b/config/config.json index e1fc9ec..6eb8821 100644 --- a/config/config.json +++ b/config/config.json @@ -1,8 +1,8 @@ { "ENVIRONMENT": { - "HTTP_PROXY":"proxy.iiit.ac.in:8080", - "HTTPS_PROXY":"proxy.iiit.ac.in:8080" + "HTTP_PROXY":"proxy.vlabs.ac.in:8080", + "HTTPS_PROXY":"proxy.vlabs.ac.in:8080" }, "CONTROLLER_CONFIG": { diff --git a/src/VMManager/VMManager.py b/src/VMManager/VMManager.py index a76b823..36984a1 100644 --- a/src/VMManager/VMManager.py +++ b/src/VMManager/VMManager.py @@ -81,7 +81,10 @@ def test_lab(lab_src_url, version=None): # get the appropriate the actions from lab_spec.json # run LabAction Runner # instantiate the object - + from envsetup import EnvSetUp + e = EnvSetUp() + Logging.LOGGER.info("Environment http_proxy = %s" % os.environ["http_proxy"]) + Logging.LOGGER.info("Environment https_proxy = %s" % os.environ["https_proxy"]) def get_build_steps_spec(lab_spec): return {"build_steps": lab_spec['lab']['build_requirements']['platform']['build_steps']} @@ -174,6 +177,6 @@ def get_lab_spec(repo_name): if __name__ == "__main__": - test_lab("https://github.com/nrchandan/vlab-computer-programming") + test_lab("https://travula@bitbucket.org/virtual-labs/cse02-programming.git") print cpu_load() print mem_usage() diff --git a/src/VMManager/config.json b/src/VMManager/config.json new file mode 100644 index 0000000..6eb8821 --- /dev/null +++ b/src/VMManager/config.json @@ -0,0 +1,67 @@ +{ + + "ENVIRONMENT": { + "HTTP_PROXY":"proxy.vlabs.ac.in:8080", + "HTTPS_PROXY":"proxy.vlabs.ac.in:8080" + }, + + "CONTROLLER_CONFIG": { + "SERVER_PORT":8080, + "LOG_FILENAME":"/root/ovpl/log/ovpl.log" + }, + + "LABMANAGER_CONFIG": { + "GIT_CLONE_LOC":"/root/labs/lab-repo-cache/", + "LAB_SPEC_LOC":"/scripts/labspec.json" + }, + + "VMMANAGER_CONFIG": { + "DISK_USAGE_URI":"/api/1.0/disk-usage", + "MEMORY_USAGE_URI":"/api/1.0/mem-usage", + "RUNNING_TIME_URI":"/api/1.0/running-time", + "RUNNING_PROCESSES_URI":"/api/1.0/running-processes", + "CPU_LOAD_URI":"/api/1.0/cpu_load", + "EXECUTE_URI":"/api/1.0/execute/([\\w*\\d*\\%\\-]+)", + "TEST_LAB_URI":"/api/1.0/test-lab", + "SERVER_PORT":8089, + "GIT_CLONE_LOC":"/root/VMManager/lab-repo-cache/", + "LAB_SPEC_LOC":"/scripts/labspec.json", + "LOG_FILENAME":"/root/VMManager/log/vmmanager.log" + }, + + "API_ENDPOINTS": { + "__comment__":"used by vm pool manager", + "CREATE_URI_ADAPTER_ENDPOINT":"/api/1.0/vm/create", + "DESTROY_URI_ADAPTER_ENDPOINT":"/api/1.0/vm/destroy", + "RESTART_URI_ADAPTER_ENDPOINT":"/api/1.0/vm/restart" + }, + + "VMPOOL_CONFIGURATION": { + "VMPOOLS": [ + { + "POOLID":1, + "DESCRIPTION":"LINUX", + "ADAPTERIP":"http://localhost", + "PORT":"8000" + }, + { + "POOLID":2, + "DESCRIPTION":"WINDOWS", + "ADAPTERIP":"http://localhost", + "PORT":"8000" + }, + { + "POOLID":3, + "DESCRIPTION":"AMAZONS3", + "ADAPTERIP":"http://localhost", + "PORT":"8000" + }, + { + "POOLID":4, + "DESCRIPTION":"AMAZONEC2", + "ADAPTERIP":"http://localhost", + "PORT":"8000" + } + ] + } +} diff --git a/src/VMManager/envsetup.py b/src/VMManager/envsetup.py new file mode 100644 index 0000000..8d4c68e --- /dev/null +++ b/src/VMManager/envsetup.py @@ -0,0 +1,64 @@ +import os +import sys +import json + + +class EnvSetUp: + + + def __init__(self): + #do nothing + self.ovpl_directory_path = None + self.config_spec = None + self.http_proxy = None + self.https_proxy = None + self.no_proxy = "" + self.set_ovpl_directory_path() + self.setup_pythonpath() + self.create_no_proxy_string() + self.get_proxy_values() + self.set_environment() + + + def set_ovpl_directory_path(self): + # The assumption here is that this script is in the src directory + # which is one directory above ovpl + self.ovpl_directory_path = os.path.dirname(os.path.abspath(__file__)) + print self.ovpl_directory_path + + def setup_pythonpath(self): + sys.path.append(self.ovpl_directory_path) + + + def create_no_proxy_string(self): + + self.no_proxy += "localhost" + + + def get_proxy_values(self): + + self.config_spec = json.loads(open(self.ovpl_directory_path + "/config.json").read()) + self.http_proxy = self.config_spec["ENVIRONMENT"]["HTTP_PROXY"] + self.https_proxy = self.config_spec["ENVIRONMENT"]["HTTPS_PROXY"] + + def set_environment(self): + os.environ["http_proxy"] = self.http_proxy + os.environ["https_proxy"] = self.https_proxy + os.environ["no_proxy"] = self.no_proxy + if "PYTHONPATH" in os.environ: + os.environ["PYTHONPATH"] += ":" + os.environ["PYTHONPATH"] += self.ovpl_directory_path + else: + os.environ["PYTHONPATH"] = self.ovpl_directory_path + + +if __name__ == '__main__': + e = EnvSetUp() +# print e.ovpl_directory_path +# print e.no_proxy +# print e.http_proxy +# print e.https_proxy + print os.environ["http_proxy"] + print os.environ["https_proxy"] + print os.environ["no_proxy"] + print os.environ["PYTHONPATH"] diff --git a/src/adapters/settings.py b/src/adapters/settings.py index cde2faa..404468a 100644 --- a/src/adapters/settings.py +++ b/src/adapters/settings.py @@ -15,7 +15,7 @@ def get_subnet(): - SUBNET = ["10.2.56.12/28"] + SUBNET = ["10.2.58.12/28"] assert isinstance(SUBNET, list) return SUBNET diff --git a/src/settings.py b/src/settings.py index cde2faa..404468a 100644 --- a/src/settings.py +++ b/src/settings.py @@ -15,7 +15,7 @@ def get_subnet(): - SUBNET = ["10.2.56.12/28"] + SUBNET = ["10.2.58.12/28"] assert isinstance(SUBNET, list) return SUBNET