Skip to content

Commit

Permalink
Merge pull request #10 from msasad/dev
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
msasad committed Apr 27, 2016
2 parents c60be23 + 0304296 commit c4688ac
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 174 deletions.
22 changes: 7 additions & 15 deletions controllers/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ def __do(action, vmid):
vm.clone()
elif action == 'poweroff':
vm.shutdown(force=True)
elif action == 'get-vnc-console':
consoleurl = vm.get_console_url()
return jsonify(consoleurl=consoleurl, action=action)
elif action == 'get-spice-console':
consoleurl = vm.get_console_url(console_type='spice')
elif action == 'get-console-url':
console_type = config.get('misc', 'console_type')
consoleurl = vm.get_console_url(console_type=console_type)
return jsonify(consoleurl=consoleurl, action=action)
elif action == 'start-resume':
status = vm.get_status()
Expand Down Expand Up @@ -120,12 +118,8 @@ def __restore_snapshot(vmid):
return __do('restore-snapshot', vmid)


def __get_vnc_console(vmid):
return __do('get-vnc-console', vmid)


def __get_spice_console(vmid):
return __do('get-spice-console', vmid)
def __get_console_url(vmid):
return __do('get-console-url', vmid)


def __migrate(vmid):
Expand All @@ -152,10 +146,8 @@ def index():
return __start_resume(vmid)
elif action == 'snapshot':
return __snapshot(vmid)
elif action == 'get-vnc-console':
return __get_vnc_console(vmid)
elif action == 'get-spice-console':
return __get_spice_console(vmid)
elif action == 'get-console-url':
return __get_console_url(vmid)
elif action == 'clone':
return __clone_vm(vmid)
elif action == 'poweroff':
Expand Down
10 changes: 5 additions & 5 deletions controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ def all_vms():
response = list()
for vm in vms:
vm_properties = vm.properties()
snapshots = vm.properties()['snapshots']
STR = 'created'
for i in range(0, len(snapshots)):
snapshots[i][STR] = convert_timezone(snapshots[i][STR])
vm_properties['snapshots'] = snapshots
# snapshots = vm.properties()['snapshots']
# STR = 'created'
# for i in range(0, len(snapshots)):
# snapshots[i][STR] = convert_timezone(snapshots[i][STR])
# vm_properties['snapshots'] = snapshots
response.append(vm_properties)
return jsonify(data=response)
except Exception as e:
Expand Down
11 changes: 6 additions & 5 deletions controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ def my_vms():
response = list()
for vm in vms:
vm_properties = vm.properties()
snapshots = vm.properties()['snapshots']
for index in range(0, len(snapshots)):
snapshots[index]['created'] = convert_timezone(
snapshots[index]['created'])
vm_properties['snapshots'] = snapshots
response.append(vm_properties)
# snapshots = vm.properties()['snapshots']
# for index in range(0, len(snapshots)):
# snapshots[index]['created'] = convert_timezone(
# snapshots[index]['created'])
# vm_properties['snapshots'] = snapshots
return jsonify(data=response)
#return jsonify(data=vms)
except Exception as e:
logger.exception(e.message or str(e.__class__))
return jsonify(status='fail')
Expand Down
16 changes: 7 additions & 9 deletions models/6_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,24 @@ def validate_registration_form(vars):
fields.append('username')
if not email_is_valid(vars.email):
fields.append('email')
if not password_is_valid(vars.password, vars['password_repeat']):
if not password_is_valid(vars.password, vars['password-repeat']):
fields.append('password')
fields.append('password-repeat')
return fields


def userid_is_valid(userid):
valid = True
length = len(userid)
validator = validators.IS_IN_DB(db, db.account_requests.userid)
valid = valid and validator(userid)[1] is not None and len(userid) >= 4
valid = valid and validator(userid)[1] is not None and (4 <= length <= 12)
validator = validators.IS_ALPHANUMERIC()
valid = valid and validator(userid)[1] is None
return valid


def username_is_valid(username):
return validators.re.match(r'^[A-Za-z][A-Za-z ]{2,}[A-Za-z]$',
return validators.re.match(r'^[A-Za-z][A-Za-z ]{2,10}[A-Za-z]$',
username) is not None


Expand All @@ -46,11 +47,7 @@ def email_is_valid(email):


def password_is_valid(password, password_repeat):
valid = True
validator = validators.IS_STRONG(min=8, upper=2, lower=2)
valid = valid and validator(password)[1] is None
valid = valid and (password == password_repeat)
return valid
return len(password) > 6 and (password == password_repeat)


def validate_vm_request_form(vars):
Expand All @@ -77,7 +74,7 @@ def validate_vm_request_form(vars):


def vmname_is_valid(vm_name):
return validators.re.match(r'^[A-Za-z][A-Za-z_\-0-9]{2,}[A-Za-z0-9]$',
return validators.re.match(r'^[A-Za-z][A-Za-z_\-0-9]{2,10}[A-Za-z0-9]$',
vm_name) is not None


Expand Down Expand Up @@ -159,6 +156,7 @@ def validate_subnet_form(vars):
def subnet_name_is_valid(subnet_name):
return username_is_valid(subnet_name)


def cidr_is_valid(cidr):
re = r'^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|'\
'[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|'\
Expand Down
74 changes: 37 additions & 37 deletions modules/Baadal.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,41 +269,41 @@ def pause(self, ):

def properties(self):
server_properties = self.server.to_dict()
properties = dict()
properties['id'] = self.server.id
image = self.__conn.nova.images.find(id=self.server.image['id'])
properties['disk'] = image.metadata['disk_size']
properties['name'] = self.server.name
properties['status'] = self.get_status()
properties['ip-addresses'] = []
for (network, addresses) in server_properties['addresses'].iteritems():
for address in addresses:
properties['ip-addresses'].append({
'network': network,
'address': address['addr'],
'MAC': address['OS-EXT-IPS-MAC:mac_addr']})
pass
flavor = self.__conn.nova.flavors.find(id=self.server.flavor['id'])
# properties['flavor'] = flavor
properties['status'] = self.get_status()
properties['memory'] = flavor.__getattr__('ram')
properties['vcpus'] = flavor.__getattr__('vcpus')
properties['hostid'] = self.server.hostId
snapshots = self.get_snapshots()
l = []
for snapshot in snapshots:
l.append({'id': snapshot.id, 'created': snapshot.created,
'name': snapshot.name})
properties['snapshots'] = l

if self.__conn.user_is_project_admin:
properties['hostname'] = self.server.__getattr__(
'OS-EXT-SRV-ATTR:hypervisor_hostname')
userid = self.server.user_id
username = self.__conn.keystone.users.get(userid)
if username:
properties['owner'] = username.to_dict()
return properties
# properties = dict()
# properties['id'] = self.server.id
# image = self.__conn.nova.images.find(id=self.server.image['id'])
# properties['disk'] = image.metadata['disk_size']
# properties['name'] = self.server.name
# properties['status'] = self.get_status()
# properties['ip-addresses'] = []
# for (network, addresses) in server_properties['addresses'].iteritems():
# for address in addresses:
# properties['ip-addresses'].append({
# 'network': network,
# 'address': address['addr'],
# 'MAC': address['OS-EXT-IPS-MAC:mac_addr']})
# pass
# flavor = self.__conn.nova.flavors.find(id=self.server.flavor['id'])
# # properties['flavor'] = flavor
# properties['status'] = self.get_status()
# properties['memory'] = flavor.__getattr__('ram')
# properties['vcpus'] = flavor.__getattr__('vcpus')
# properties['hostid'] = self.server.hostId
# snapshots = self.get_snapshots()
# l = []
# for snapshot in snapshots:
# l.append({'id': snapshot.id, 'created': snapshot.created,
# 'name': snapshot.name})
# properties['snapshots'] = l

# if self.__conn.user_is_project_admin:
# properties['hostname'] = self.server.__getattr__(
# 'OS-EXT-SRV-ATTR:hypervisor_hostname')
# userid = self.server.user_id
# username = self.__conn.keystone.users.get(userid)
# if username:
# properties['owner'] = username.to_dict()
return server_properties
pass

def reboot(self, soft=True):
Expand Down Expand Up @@ -488,8 +488,8 @@ def baadal_vms(self, all_users=False):
for i in serverlist]
return serverlist or []
except Exception as e:
raise BaadalException(e.message or str(e.__class__))
pass
raise e
# raise BaadalException(e.message or str(e.__class__))

def find_baadal_vm(self, **kwargs):
"""
Expand Down
20 changes: 16 additions & 4 deletions openstack-setup.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@

# TODO: Rewrite this file in more readable and self-explainatory manner.

Install refering to the official openstack installation guide for ubuntu 14.04 Kilo (located at http://docs.openstack.org/kilo/install-guide/install/apt/content/index.html)
Install refering to the official openstack installation guide for ubuntu 14.04
Kilo (located at
http://docs.openstack.org/kilo/install-guide/install/apt/content/index.html)

While creating flavor give the id of the flavor as
xCPU-yM-zG, where x is the number of CPUs, y is the RAM in MB and D is disk in GB.
For example for a flavor with 2 CPUs, 1GB RAM and 160 disk flavor id would be:
2CPU-1024M-160G.
This is done to make the id of the flavor convey information about the flavor
as opposed to automatically generated UUID which conveys no information at all.

For networing, use neutron networking (not nova-networking)

Follow the guide for rest of the process, till network creation.

edit /etc/neutron/dhcp_agent.ini file in the neutron node to contain the following value
edit /etc/neutron/dhcp_agent.ini file in the neutron node to contain the
following value
dhcp_domain = iitd.ac.in

Create a router by following the guide. (Do not change the name of the external network, keep it 'ext-net')
Create a router by following the guide. (Do not change the name of the external
network, keep it 'ext-net')

Create internal network using the below command
$ neutron net-create --tenant-id $tenant NETWORK_NAME --provider:network_type gre --provider:segmentation_id SEGMENTATION_ID
$ neutron net-create --tenant-id $tenant NETWORK_NAME --provider:network_type \\
gre --provider:segmentation_id SEGMENTATION_ID

create subnet in each network using the below command
$ neutron subnet-create --tenant-id $tenant --name SUBNET_NAME NETWORK_NAME CIDR
Expand Down
1 change: 1 addition & 0 deletions private/baadal.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ external_network_name =
mysql_timestamp_format = %Y-%m-%d %H=%M:%S
gateway_server = GATEWAY_SERVER
default_keypair =
console_type =

[database]
dbhost =
Expand Down
1 change: 0 additions & 1 deletion static/css/baadal-custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ textarea {
#all-vms > tbody > tr> td:nth-child(4) {
white-space: nowrap;
text-overflow: ellipsis;
width: 35%;
max-width: 0;
overflow-x: hidden;
}
34 changes: 34 additions & 0 deletions static/js/baadal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ baadalApp.ipArrayToString = function(data, usebr) {
return arr.join(usebr ? '<br>' : '\n');
};

baadalApp.ipObjectToString = function(object) {
strings = [];
for (var i in object) {
ips = object[i];
for (var ip of ips) {
strings.push('MAC: ' + ip['OS-EXT-IPS-MAC:mac_addr'] + ' IP: ' + ip['addr']);
}
}
return strings.join('<br/>')
};

if (Handlebars) {
Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
switch (operator) {
Expand Down Expand Up @@ -64,3 +75,26 @@ baadalApp.filterArrayObject = function(object, array_name, field_name, value) {
object[array_name] = newarray;
return object;
};

baadalApp.getSettingsButtonsMarkup = function(status) {
var actions = {
'ACTIVE' : 'shutdown',
'SHUTOFF' : 'start',
'ERROR' : 'start'
};

var glyphicons = {
'ACTIVE' : 'stop',
'SHUTOFF' : 'play',
'ERROR' : 'play'
};
return '<div class="btn-group" role="group" aria-label="..."><button title="' +
actions[status] +
'" type="button" data-action="' +
actions[status] +
'" class="btn btn-success btn-action" aria-label="Start"><span class="fa fa-' +
glyphicons[status] +
'" aria-hidden="true"></span></button><button title="Settings" type="button"' +
'data-action="settings" class="btn btn-primary btn-settings" aria-label="Settings">' +
'<span class="fa fa-cog" aria-hidden="true"></span></button></div>';
}
23 changes: 16 additions & 7 deletions static/templates/vm-admin-settings-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ <h3 class="panel-title">{{name}}</h3>
<th>VM Name</th>
<th>State</th>
<th>IP Address(es)</th>
<th>VCPUs</th>
<th>Memory</th>
<th>Config</th>
<th>Users</th>
</tr>
</thead>
Expand All @@ -27,21 +26,29 @@ <h3 class="panel-title">{{name}}</h3>
<td>{{name}}</td>
<td>{{status}}</td>
<td>{{{ip-addresses}}}</td>
<td>{{vcpus}}</td>
<td>{{memory}}</td>
<td>{{owner.id}}</td>
<td>{{flavor.id}}</td>
<td>{{user_id}}</td>
</tr>
</tbody>
</table>
{{#if fault.message}}
<div class=" panel panel-danger">
<div class="panel-body">
<span class="text-danger">
{{fault.message}}
</span>
</div>
</div>
{{/if}}
<input type="hidden" id="vmid" value="{{id}}">
<div class="btn-group" data-vmid="{{id}}" role="group" aria-label="...">
<button type="button" data-action="snapshot" class="btn btn-lg btn-default btn-action" title="Take Snapshot">
<span class="fa fa-camera" aria-hidden="true"></span>
</button>
<button type="button" data-action="get-spice-console" class="btn btn-lg btn-default btn-action" title="Get VNC Console URL">
<button type="button" data-action="get-console-url" class="btn btn-lg btn-default btn-action" title="Get Console URL">
<span class="fa fa-terminal" aria-hidden="true"></span>
</button>
{{#ifCond status '==' 'Running'}}
{{#ifCond status '==' 'ACTIVE'}}
<button type="button" data-action="shutdown" class="btn btn-lg btn-default btn-action" title="Shutdown">
<span class="fa fa-stop" aria-hidden="true"></span>
</button>
Expand All @@ -59,6 +66,7 @@ <h3 class="panel-title">{{name}}</h3>
<button type="button" data-action="migrate" class="btn btn-lg btn-default btn-action" title="Migrate">
<span class="fa fa-plane" aria-hidden="true"></span>
</button>
{{#ifCond status '==' 'ACTIVE'}}
<button type="button" data-action="soft-reboot" class="btn btn-lg btn-default btn-action" title="Soft Reboot">
<span class="fa fa-refresh" aria-hidden="true"></span>
</button>
Expand All @@ -68,6 +76,7 @@ <h3 class="panel-title">{{name}}</h3>
<button type="button" data-action="force-reboot" class="btn btn-lg btn-warning btn-action" title="Force Reboot">
<span class="fa fa-refresh" aria-hidden="true"></span>
</button>
{{/ifCond}}
<button type="button" data-action="delete" class="btn btn-lg btn-danger btn-action" title="Delete VM">
<span class="fa fa-remove" aria-hidden="true"></span>
</button>
Expand Down
Loading

0 comments on commit c4688ac

Please sign in to comment.