attached opennebula vm id to virtualmachine plan

This commit is contained in:
Levi 2017-05-08 21:54:12 -05:00
parent abf6dbddce
commit 9a34518457
3 changed files with 10 additions and 21 deletions

View file

@ -177,12 +177,15 @@ class VirtualMachinePlan(AssignPermissionsMixin, models.Model):
@classmethod @classmethod
def create_opennebula_vm(self, user, specs): def create_opennebula_vm(self, user, specs):
# Init opennebula manager using given user
opennebula_client = OpenNebulaManager( opennebula_client = OpenNebulaManager(
user.email, user.email,
user.password[0:20], user.password[0:20],
create_user=True create_user=True
) )
# Create a vm in opennebula using given specs
vm = opennebula_client.create_vm(specs) vm = opennebula_client.create_vm(specs)
return vm return vm

View file

@ -37,6 +37,7 @@ class OpenNebulaManager:
def __init__(self, email=None, password=None, create_user=True): def __init__(self, email=None, password=None, create_user=True):
# Get oneadmin client
self.oneadmin_client = self._get_opennebula_client( self.oneadmin_client = self._get_opennebula_client(
settings.OPENNEBULA_USERNAME, settings.OPENNEBULA_USERNAME,
settings.OPENNEBULA_PASSWORD settings.OPENNEBULA_PASSWORD
@ -45,11 +46,13 @@ class OpenNebulaManager:
if not create_user: if not create_user:
return return
# Get or create oppenebula user using given credentials
self.opennebula_user = self._get_or_create_user( self.opennebula_user = self._get_or_create_user(
email, email,
password password
) )
# If opennebula user was created/obtained, get his client
if self.opennebula_user: if self.opennebula_user:
self.client = self._get_opennebula_client( self.client = self._get_opennebula_client(
email, email,
@ -68,8 +71,6 @@ class OpenNebulaManager:
)) ))
def _get_or_create_user(self, email, password): def _get_or_create_user(self, email, password):
# import pdb
# pdb.set_trace()
try: try:
user_pool = oca.UserPool(self.oneadmin_client) user_pool = oca.UserPool(self.oneadmin_client)

View file

@ -340,29 +340,14 @@ class PaymentVMView(LoginRequiredMixin, FormView):
# If the Stripe payment was successed, set order status approved # If the Stripe payment was successed, set order status approved
order.set_approved() order.set_approved()
# Create VM using oppenebula functions # Create a vm using logged user
# _request = namedtuple('request', 'POST user') oppennebula_vm_id = VirtualMachinePlan.create_opennebula_vm(
# _request.user = request.user
# user = namedtuple('user', 'email')
# email
# _request.POST = {
# 'vm_template': vm_template
# }
open_vm = VirtualMachinePlan.create_opennebula_vm(
self.request.user, self.request.user,
specs specs
) )
print(open_vm) plan.oppenebula_id = oppennebula_vm_id
print(open_vm) plan.save()
print(open_vm)
# hosting_admin = HostingManageVMAdmin.__new__(HostingManageVMAdmin)
# hosting_admin.init_opennebula_client(request)
# oppennebula_vm_id = hosting_admin.create_vm_view(vm_type.get_specs())
# plan.oppenebula_id = oppennebula_vm_id
# Send notification to ungleich as soon as VM has been booked # Send notification to ungleich as soon as VM has been booked
context = { context = {