Skip to content

Commit

Permalink
Setting the environment in the container
Browse files Browse the repository at this point in the history
  • Loading branch information
Thirumal Ravula committed Sep 29, 2014
1 parent c76907b commit 7391fa7
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 6 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
7 changes: 5 additions & 2 deletions src/VMManager/VMManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']}

Expand Down Expand Up @@ -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()
67 changes: 67 additions & 0 deletions src/VMManager/config.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
}
64 changes: 64 additions & 0 deletions src/VMManager/envsetup.py
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 1 addition & 1 deletion src/adapters/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7391fa7

Please sign in to comment.