Skip to content
Snippets Groups Projects
Commit da650415 authored by Jupiter Hu's avatar Jupiter Hu
Browse files

add initialization

parent e2041073
No related branches found
No related tags found
No related merge requests found
......@@ -102,6 +102,17 @@
- name: install karaage3-wsgi.conf
template: src=kg-idps.j2 dest=/usr/bin/kg-idps mode=755
sudo: true
- name: install shibboleth cache file
template: src=metadata.aaf.xml.j2 dest=/tmp/metadata.aaf.xml
- name: install karaage projects init setting file
template: src=kg_init.txt.j2 dest=/tmp/kg_init.txt
- name: install karaage init script
template: src=kg_init.j2 dest=/usr/bin/kg_init mode=755
sudo: true
-
name: "enabling Karaage configuration"
shell: a2enconf karaage3-wsgi
......@@ -138,10 +149,11 @@
sudo: true
when: karaage_db_init.stdout.find("0") == 0
#-
# name: "Create IDP institutes (disable it as cache is not available)"
# shell: kg-idps
# sudo: true
-
name: "Create IDP institutes (disable it as cache is not available)"
shell: kg-idps /tmp/metadata.aaf.xml
sudo: true
when: karaage_db_init.stdout.find("0") == 0
- name: install postfix
apt: name=postfix state=present
......
#!/usr/bin/python
import os
import os, sys
import django
os.environ['DJANGO_SETTINGS_MODULE'] = "karaage.conf.settings"
def get_idps_from_metadata():
DEFAULT_CACHE_FILE = "/var/cache/shibboleth/metadata.aaf.xml"
def get_idps_from_metadata(cache_path):
import xml.etree.ElementTree as ET
tree = ET.parse('/var/cache/shibboleth/metadata.aaf.xml')
tree = ET.parse(cache_path)
root=tree.getroot()
idps=[]
for entity in root.findall("{urn:oasis:names:tc:SAML:2.0:metadata}EntityDescriptor"):
......@@ -66,11 +68,19 @@ def get_or_create_idp(entityID,name):
# print dir(form)
# #print "not actually saving my form"
django.setup()
idps = get_idps_from_metadata()
for idp in idps:
try:
get_or_create_idp(entityID=idp['entityID'],name=idp['name'])
except:
pass
def main(argv):
if len(sys.argv) > 1:
cache_path = argv[0]
else:
cache_path = DEFAULT_CACHE_FILE
django.setup()
idps = get_idps_from_metadata(cache_path)
for idp in idps:
try:
get_or_create_idp(entityID=idp['entityID'],name=idp['name'])
except:
pass
if __name__ == '__main__':
main(sys.argv[1:])
#!/usr/bin/python
import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = "karaage.conf.settings"
from django.conf import settings
from karaage.projects.models import Project
from karaage.institutes.models import Institute
DEFAULT_PROJECTS = [
{"project_name": "MCC2", "pid": "pMcc2", "institute_name": "Monash University"},
{"project_name": "MCC3", "pid": "pMcc3", "institute_name": "Monash University"},
{"project_name": "MASSIVE", "pid": "pMassive", "institute_name": "Monash University"},
{"project_name": "CVL", "pid": "pCvl", "institute_name": "Monash University"}
]
class InitDefaultProject():
import django
django.setup()
def __init__(self, configfile):
import json
self.path = configfile
if self.path:
with open(self.path) as data:
self.config = json.load(data)
else:
self.config = DEFAULT_PROJECTS
def log(self, message):
print message
def getGroup(self, name):
group = None
try:
group =Group.objects.get(name = name)
if group:
self.log("Find group %s" %(name))
except:
self.log("Group %s not found" %(name))
finally:
return group
def getProject(self, name):
self.log("Get Project 1 %s" %(name))
project = None
try:
project = Project.objects.get(name = name)
if project:
self.log("Find project %s" %(project.name))
group = project.group
if group:
self.log("Group name = %s" %(group.name))
else:
self.log("Project %s not found" %(project.name))
except Project.DoesNotExist:
self.log("project %s does not exists" %(name))
except:
self.log("Exception: ", traceback.format_exc())
finally:
return project
def createProject(self, pid, name, institute_name):
project = None
try:
institute = self.getInstitute(institute_name)
if institute:
self.log("Find insititute %s" %(institute.name))
project = Project.objects.create(pid = pid, name = name, institute = institute, group = institute.group, is_active = True)
if project:
self.log("Create project OK")
else:
self.log("Create project failed")
else:
self.log("Insititute %s does not exist" %(institute_name))
except:
self.log("Exception: ", traceback.format_exc())
finally:
return project
def getInstitute(self, name):
institute = None
try:
institute = Institute.objects.get(name = name)
if institute:
self.log("Institute %s exist" %(institute.name))
group = institute.group
if group:
self.log("Group name = %s" %(group.name))
else:
self.log("Institute %s not found" %(name))
except Institute.DoesNotExist:
self.log("Institute %s not found" %(name))
finally:
return institute
def defaultProjects(self):
for p in self.config:
project = self.getProject(p["project_name"])
if project:
self.log("Find project %s" %(project.name))
else:
self.log("Create project name = %s, pid = %s, institute name = %s" %(p["project_name"], p["pid"], p["institute_name"]))
project = self.createProject(p["pid"], p["project_name"], p["institute_name"])
if project:
self.log("Create project %s OK." %(project.name))
else:
self.log("Create project %s failed." %(p["project_name"]))
break
def main(argv):
config_path = None
if len(sys.argv) > 1:
config_path = argv[0]
init = InitDefaultProject(config_path)
init.defaultProjects()
if __name__ == '__main__':
main(sys.argv[1:])
[
{"project_name": "MCC2", "pid": "pMcc2", "institute_name": "Monash University"},
{"project_name": "MCC3", "pid": "pMcc3", "institute_name": "Monash University"},
{"project_name": "MASSIVE", "pid": "pMassive", "institute_name": "Monash University"},
{"project_name": "CVL", "pid": "pCvl", "institute_name": "Monash University"}
]
This diff is collapsed.
......@@ -78,18 +78,6 @@ ADMINS = (
# link notifications when BrokenLinkEmailsMiddleware is enabled.
MANAGERS = ADMINS
{% if defaultProject is defined and defaultMachineCategory is defined %}
DEFAULT_PROJECT_PID = "{{ defaultProject }}"
DEFAULT_MACHINE_CATEGORY_NAME = "{{ defaultMachineCategory }}"
{% endif %}
DEFAULT_INSTITUTE_NAME = "Monash University"
DEFAULT_PROJECTS = [
{"project_name": "MCC2", "pid": "pMcc2", "institute_name": "Monash University"},
{"project_name": "MCC3", "pid": "pMcc3", "institute_name": "Monash University"},
{"project_name": "MASSIVE", "pid": "pMassive", "institute_name": "Monash University"},
{"project_name": "CVL", "pid": "pCvl", "institute_name": "Monash University"}
]
# A dictionary containing the settings for all databases to be used with
# Django. It is a nested dictionary whose contents maps database aliases to a
# dictionary containing the options for an individual database.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment