Listing of VMs and Creation of VMs done.

This commit is contained in:
M.Ravi 2017-03-17 00:42:27 +05:30
parent b363bf5f6a
commit 24cfe707cd
2 changed files with 26 additions and 11 deletions

View file

@ -111,6 +111,7 @@ class VirtualMachinePlanAdmin(admin.ModelAdmin):
class HostingManageVMsAdmin(admin.ModelAdmin):
client = None
def get_urls(self):
self.client = oca.Client(settings.OPENNEBULA_USERNAME + ':' + settings.OPENNEBULA_PASSWORD, settings.OPENNEBULA_PROTOCOL + '://' + settings.OPENNEBULA_DOMAIN + ':' + settings.OPENNEBULA_PORT + settings.OPENNEBULA_ENDPOINT)
urls = super().get_urls()
socket.setdefaulttimeout(5)
my_urls = [
@ -124,13 +125,8 @@ class HostingManageVMsAdmin(admin.ModelAdmin):
s_message = ''
e_message = ''
try :
client = oca.Client(settings.OPENNEBULA_USERNAME + ':' + settings.OPENNEBULA_PASSWORD, settings.OPENNEBULA_PROTOCOL + '://' + settings.OPENNEBULA_DOMAIN + ':' + settings.OPENNEBULA_PORT + settings.OPENNEBULA_ENDPOINT)
vm_pool = oca.VirtualMachinePool(client)
vm_pool = oca.VirtualMachinePool(self.client)
vm_pool.info()
for vm in vm_pool:
vm.info()
print("%s (memory: %s MB)" % ( vm.name, vm.template.memory))
except socket.timeout:
e_message = "Socket timeout error."
except OpenNebulaException:
@ -150,10 +146,10 @@ class HostingManageVMsAdmin(admin.ModelAdmin):
s_message = ''
e_message = ''
try :
client = oca.Client(settings.OPENNEBULA_USERNAME + ':' + settings.OPENNEBULA_PASSWORD, settings.OPENNEBULA_PROTOCOL + '://' + settings.OPENNEBULA_DOMAIN + ':' + settings.OPENNEBULA_PORT + settings.OPENNEBULA_ENDPOINT)
# Lets create a test VM with 128MB of ram and 1 CPU
vm_id = oca.VirtualMachine.allocate(client, '<VM><MEMORY>128</MEMORY><CPU>1</CPU></VM>')
vm_id = oca.VirtualMachine.allocate(self.client, '<VM><MEMORY>128</MEMORY><CPU>1</CPU></VM>')
s_message = "Created with id = " + str(vm_id)
vm_pool = self.get_vms
# Lets print the VMs available in the pool
# print("Printing the available VMs in the pool.")
# vm_pool = oca.VirtualMachinePool(client)
@ -168,6 +164,7 @@ class HostingManageVMsAdmin(admin.ModelAdmin):
self.admin_site.each_context(request),
error_msg=e_message,
success_msg=s_message,
vms = vm_pool,
# Anything else you want in the context...
# key=value,
)

View file

@ -1,4 +1,5 @@
{% extends "admin/base_site.html" %}
{% load staticfiles bootstrap3 i18n %}
{% block content %}
{% if error_msg %}
<p class="alert alert-danger">{{error_msg}}</p>
@ -10,11 +11,28 @@
{% if vms %}
<section>
<ul class="list-group">
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Memory</th>
<th>Status</th>
<th>User Name</th>
</tr>
</thead>
<tbody>
{% for vm in vms %}
<li class="list-group-item">{{vm.name}} --- {{vm.template.memory}} --- {{vm.state}} --- {{vm.uname}}</li>
<tr>
<td>{{vm.id}}</td>
<td>{{vm.name}}</td>
<td>{{vm.template.memory}}</td>
<td>{{vm.str_state}}</td>
<td>{{vm.uname}}</td>
</tr>
{% endfor %}
</ul>
</tbody>
</table>
</section>
{% endif %}