Skip to content
This repository was archived by the owner on Jul 21, 2026. It is now read-only.
Open
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
Binary file modified .DS_Store
Binary file not shown.
Binary file modified moc_ui/.DS_Store
Binary file not shown.
104 changes: 74 additions & 30 deletions moc_ui/auth.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
from os import environ as env

# Client package
import novaclient.v1_1.client as nvclient
import glanceclient.v2.client as glclient
import keystoneclient.v2_0.client as ksclient
#import novaclient.v1_1.client as nvclient

#from novaclient import client as nvclient

#import glanceclient.v2.client as glclient
#import keystoneclient.v2_0.client as ksclient

# from keystoneclient.auth.identity import v2
from keystoneclient import session
from novaclient import client

from keystoneauth1.identity import v3

from keystoneauth1 import session

from keystoneclient.v3 import client as ksclient
from novaclient import client as nvclient
from glanceclient import client as glclient

# Socks
import socks
import socket
#import socks
#import socket

# Set up SOCKS proxy usage:
s = socks.socksocket()
#s = socks.socksocket()

# Set up the Port number as the one used for connecting Harvard Cluster
socks.set_default_proxy(socks.SOCKS5, 'localhost', 5507)
socket.socket = socks.socksocket
#socks.set_default_proxy(socks.SOCKS5, 'localhost', 5507)
#socket.socket = socks.socksocket

# Log User to his/her associated Tenant
def loginTenant(request, tenant_name):
Expand All @@ -28,41 +37,76 @@ def loginTenant(request, tenant_name):

username = request.session['username']
password = request.session['password']

auth_url = 'https://engage1.massopencloud.org:5000/v3/'

print 'lucas-test-auth-loginTenant'
keystone = ksclient.Client(auth_url = 'http://140.247.152.207:5000/v2.0', username = username,
password = password, tenant_name = tenant_name)

unscoped_auth = v3.Password(auth_url = auth_url, username = username, password = password, user_domain_name="Default", unscoped=True)
unscoped_sess=session.Session(auth=unscoped_auth)
unscoped_token=unscoped_sess.get_token()
auth=v3.Token(auth_url = auth_url,token=unscoped_token)
sess=session.Session(auth=auth)
#scoped_token=sess.get_token()
keystone = ksclient.Client(session=sess)
# keystone = ksclient.Client(auth_url = 'https://engage1.massopencloud.org:5000/v2.0/', username = username,
# password = password, tenant_name = tenant_name)
print 'lucas-test-auth-loginTenant-succesfully'
nova = nvclient.Client(auth_url = 'http://140.247.152.207:5000/v2.0',
username = username,
api_key = password,
project_id = tenant_name)
glance_endpoint = keystone.service_catalog.url_for(service_type='image')
glance = glclient.Client(glance_endpoint, token = keystone.auth_token)
# nova = nvclient.Client('2', auth_url = 'https://engage1.massopencloud.org:5000/v2.0/',
# username = username,
# api_key = password,
# project_id = tenant_name)
nova = nvclient.Client('2', session=sess)
glance = glclient.Client('2', session=sess)
return {'keystone': keystone, 'nova': nova, 'glance': glance}

def get_keystone(request, tenant_name):
username = request.session['username']
password = request.session['password']
keystone = ksclient.Client(auth_url = 'http://140.247.152.207:5000/v2.0', username = username,
password = password, tenant_name = tenant_name)
auth_url = 'https://engage1.massopencloud.org:5000/v3/'
# keystone = ksclient.Client(auth_url = 'https://engage1.massopencloud.org:5000/v2.0/', username = username,
# password = password, tenant_name = tenant_name)
unscoped_auth = v3.Password(auth_url = auth_url, username = username, password = password, user_domain_name="Default", unscoped=True)
unscoped_sess=session.Session(auth=unscoped_auth)
unscoped_token=unscoped_sess.get_token()
auth=v3.Token(auth_url = auth_url,token=unscoped_token)
sess=session.Session(auth=auth)
#scoped_token=sess.get_token()
keystone = ksclient.Client(session=sess)
return keystone

def get_nova(request, tenant_name):
username = request.session['username']
password = request.session['password']
nova = nvclient.Client(auth_url = 'http://140.247.152.207:5000/v2.0',
username = username,
api_key = password,
project_id = tenant_name)
auth_url = 'https://engage1.massopencloud.org:5000/v3/'

unscoped_auth = v3.Password(auth_url = auth_url, username = username,
password = password, user_domain_name="Default", unscoped=True)
unscoped_sess=session.Session(auth=unscoped_auth)
unscoped_token=unscoped_sess.get_token()
auth=v3.Token(auth_url = auth_url,token=unscoped_token)
sess=session.Session(auth=auth)
nova = nvclient.Client('2', session=sess)
# nova = nvclient.Client('2', auth_url = 'https://engage1.massopencloud.org:5000/v2.0/',
# username = username,
# api_key = password,
# project_id = tenant_name)
return nova

def get_glance(request, tenant_name):
username = request.session['username']
password = request.session['password']
glance_endpoint = keystone.service_catalog.url_for(service_type='image')
glance = glclient.Client(glance_endpoint, token = keystone.auth_token)
return {'keystone': keystone, 'nova': nova, 'glance': glance}
auth_url = 'https://engage1.massopencloud.org:5000/v3/'

# keystone = get_keystone(request,tenant_name)
# nova = get_nova(request,tenant_name)
unscoped_auth = v3.Password(auth_url = auth_url, username = username,
password = password, user_domain_name="Default", unscoped=True)
unscoped_sess=session.Session(auth=unscoped_auth)
unscoped_token=unscoped_sess.get_token()
auth=v3.Token(auth_url = auth_url,token=unscoped_token)
sess=session.Session(auth=auth)
glance = glclient.Client('2', session=sess)
return glance



Expand All @@ -73,15 +117,15 @@ def get_glance(request, tenant_name):
# print 'lucas-test-auth-loginUser'

# keystone = ksclient.Client(
# auth_url = 'http://140.247.152.207:5000/v2.0',
# auth_url = 'https://engage1.massopencloud.org:5000/v2.0/',
# username = username,
# password = password)
# print 'lucas-test-auth-loginUser-succesfully'
# return keystone


# def _loginTenant (request, username, password, tenant_name):
# auth_url = 'http://140.247.152.207:5000/v2.0'
# auth_url = 'https://engage1.massopencloud.org:5000/v2.0/'
# auth = v2.Password(auth_url = auth_url, username = username, password = password, tenant_name = tenant_name)
# sess = session.Session(auth=auth)
# nova = client.Client('1.1', session=sess)
Expand Down
9 changes: 7 additions & 2 deletions moc_ui/dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
login_buttons = [{'name': 'Login', 'type': 'submit', 'action': '/login/', 'class': 'btn-primary'},
{'name': 'Register', 'type': 'modal', 'data_target': '#createUser', 'class': 'btn-success'}]


login_data = {'name': 'MassOpenCloud Login', 'action': '/login', 'method': 'post', 'button_list': login_buttons}

reg_modal = {'id': 'createUser', 'action': '/register', 'method': 'post', 'title': 'Register User'}
reg_modal = {'id': 'createUser', 'action': '/register', 'method': 'post', 'title': 'Register User'}

#CONTROL PAGE
vm_buttons = {'name': 'Create', 'type': 'modal', 'data_target': '#createVM', 'class': 'btn-success'}

vm_data = {'name': 'Create a VM', 'action': '/createVM', 'method': 'post', 'button_list': vm_buttons}

vm_modal = {'id': 'create VM', 'action': '/createVM', 'method': 'post', 'title': 'Create a New VM'}

# CLOUDS PAGE
test_vm_list_1 = [{'name': 'hadoop master', 'state': '=)', 'provider': 'HU-prod', 'image': 'centOS 7'},
Expand Down
4 changes: 2 additions & 2 deletions moc_ui/fixtures/projects.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"model": "moc_ui.ClusterProject",
"pk": 1,
"fields": {
"name": "ui",
"name": "atmosphere",
"token": ""
}
},
{
"model": "moc_ui.ClusterProject",
"pk": 2,
"fields": {
"name": "bit_coin_farm",
"name": "another_dummy_project",
"token": ""
}
}
Expand Down
49 changes: 45 additions & 4 deletions moc_ui/fixtures/service_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"pk": 11,
"fields": {
"name": "Hadoop",
"service_type": "Service",
"service_type": "Compute",
"description" : "Apache Hadoop",
"logo_url":"/static/hadoop.jpg",
"availability":"True"
Expand Down Expand Up @@ -143,18 +143,59 @@
"availability":"True"
}
},
{
{
"model": "moc_ui.service",
"pk": 14,
"fields": {
"name": "Ubuntu",
"service_type": "Service",
"description" : "Ubuntu vm image",
"logo_url":"/static/Ubuntu.jpg",
"availability":"True",
"image_name" : "Ubuntu 14.04.2 LTS (Trusty Tahr) x86_64"

}
},
{
"model": "moc_ui.service",
"pk": 15,
"fields": {
"name": "CentOS",
"service_type": "Service",
"description" : "CentOS vm image",
"logo_url":"/static/CentOS.png",
"availability":"True",
"image_name" : "CentOS-7-x86_64-GenericCloud-1503.qcow2"


}
},
{
"model": "moc_ui.service",
"pk": 16,
"fields": {
"name": "Fedora",
"service_type": "Service",
"description" : "Fedora VM image",
"logo_url":"/static/Fedora.jpg",
"availability":"True",
"image_name" : "Fedora-Cloud-Base-20141203-21.x86_64.qcow2"


}
},
{
"model": "moc_ui.uiproject",
"pk": 1,
"fields": {
"name": "big_data"
"name": "ui"
}
},
{
"model": "moc_ui.uiproject",
"pk": 2,
"fields": {
"name": "webservers"
"name": "another_one"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion moc_ui/fixtures/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"model":"moc_ui.user",
"fields": {
"user_name": "xuh",
"user_name": "xuh@bu.edu",
"password_hash": "$6$rounds=100000$wroWL0h4EVKrnMEa$UzEFNumbOj2mmDxlRfXM8DQ3FRuWxakNFL43NJxCRYQSfRDzj4wPuWiHAvyY6hPZu5YgL8qnAIfrgbRcD0U2C0"
}
}
Expand Down
70 changes: 48 additions & 22 deletions moc_ui/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from django.http import HttpResponseRedirect

import models
import novaclient.v1_1.client as nvclient
import glanceclient.v2.client as glclient
import keystoneclient.v2_0.client as ksclient
# import novaclient.v1_1.client as nvclient
# import glanceclient.v2.client as glclient
# import keystoneclient.v2_0.client as ksclient
import ui_api as api

class Login(forms.Form):
Expand Down Expand Up @@ -180,25 +180,51 @@ class Meta:

# vm actions
class Create_VM(forms.Form):
name = forms.CharField()
cluster_projects = []
for p in models.ClusterProject.objects.all().values('name').distinct(): #for all
cluster_projects.append((p['name'], p['name']))
cluster_project = forms.ChoiceField(widget=forms.Select, choices=cluster_projects)

#nova = api.get_nova(request, project) #get nova object

#image choices
#image_choices = []
#for option in nova.images.list():
# image_coices.append(str(option.name))
#imageName = forms.ChoiceField(widget=forms.Select, choices=image_choices)

#flavor choices
#flavor_choices = []
#for option in nova.flavors.list():
# flavor_choices.append(str(option.name))
#flavorName = forms.ChoiceField(widget=forms.Select, choices=flavor_choices)

# def __init__(self,request,*args,**kwargs):
# super (Create_VM, self).__init__(*args,**kwargs)

# self.fields['name'] = forms.CharField()
service_list = []
try:
services = models.ClusterProject_service.objects.all()
for service in services:
print service

print service_list
except Exception as e:
print 'err'
print e
name = forms.CharField()


# self.fields['image'] = forms.ChoiceField(widget =forms.Select, choices = ([(ubuntu,ubuntu),(centos,centos)]))
# image = forms.ChoiceField(widget =forms.Select, choices = ([(ubuntu,ubuntu),(centos,centos)]))
image = forms.ModelChoiceField(queryset = services, initial = 0)

# flavor_list = models.Service.objects.values('flavor')

# medium = flavor_list[13]['flavor']
# tiny = flavor_list[14]['flavor']

m = 'm1.medium'
t = 'm1.tiny'
l = 'm1.large'
s = 'm1.small'
x = 'm1.xlarge'
# self.fields['flavor'] = forms.ChoiceField(widget = forms.Select, choices = ([(m,m),(t,t),(l,l)]))
flavor = forms.ChoiceField(widget = forms.Select, choices = ([(m,m),(x,x),(l,l),(s,s),(t,t)]))


def save(self, request, force_insert=False, force_update=False, commit=True):

name = self.cleaned_data['name']
image = str(self.cleaned_data['image'])
flavor = self.cleaned_data['flavor']
nova = api.get_nova(request, 'ui')

api.createVM(nova, name, image, flavor)


class Delete_VM(forms.Form):
name = forms.CharField()
Expand Down
12 changes: 8 additions & 4 deletions moc_ui/html_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ def project_modals(request):
{'id':'add_Cluster_Project', 'action':'/create/ClusterProject',
'title':'Add Cluster Project', 'form':forms.ClusterProject()},
{'id':'delete_Cluster_Project', 'action':'/delete/ClusterProject',
'title':'Delete Cluster Project', 'form':forms.ClusterProject()},
#{'id':'createVM', 'title':'Create VM', 'form':forms.create_VM()},
{'id':'deleteVM', 'action':'/delete/Cluster',
'title':'Delete VM', 'form':forms.Delete_VM()},
'title':'Delete Cluster Project', 'form':forms.ClusterProject()}

]
def vm_modals(request):
return [{'id':'createVM', 'action' : '/createVM/ui',
'title':'Create VM', 'form':forms.Create_VM()},
{'id':'deleteVM', 'action':'/deleteVM',
'title':'Delete VM', 'form':forms.Delete_VM()}
]
Loading