attached opennebula vm id to virtualmachine plan
This commit is contained in:
parent
abf6dbddce
commit
9a34518457
3 changed files with 10 additions and 21 deletions
|
@ -177,12 +177,15 @@ class VirtualMachinePlan(AssignPermissionsMixin, models.Model):
|
|||
|
||||
@classmethod
|
||||
def create_opennebula_vm(self, user, specs):
|
||||
|
||||
# Init opennebula manager using given user
|
||||
opennebula_client = OpenNebulaManager(
|
||||
user.email,
|
||||
user.password[0:20],
|
||||
create_user=True
|
||||
)
|
||||
|
||||
# Create a vm in opennebula using given specs
|
||||
vm = opennebula_client.create_vm(specs)
|
||||
return vm
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ class OpenNebulaManager:
|
|||
|
||||
def __init__(self, email=None, password=None, create_user=True):
|
||||
|
||||
# Get oneadmin client
|
||||
self.oneadmin_client = self._get_opennebula_client(
|
||||
settings.OPENNEBULA_USERNAME,
|
||||
settings.OPENNEBULA_PASSWORD
|
||||
|
@ -45,11 +46,13 @@ class OpenNebulaManager:
|
|||
if not create_user:
|
||||
return
|
||||
|
||||
# Get or create oppenebula user using given credentials
|
||||
self.opennebula_user = self._get_or_create_user(
|
||||
email,
|
||||
password
|
||||
)
|
||||
|
||||
# If opennebula user was created/obtained, get his client
|
||||
if self.opennebula_user:
|
||||
self.client = self._get_opennebula_client(
|
||||
email,
|
||||
|
@ -68,8 +71,6 @@ class OpenNebulaManager:
|
|||
))
|
||||
|
||||
def _get_or_create_user(self, email, password):
|
||||
# import pdb
|
||||
# pdb.set_trace()
|
||||
try:
|
||||
|
||||
user_pool = oca.UserPool(self.oneadmin_client)
|
||||
|
|
|
@ -340,29 +340,14 @@ class PaymentVMView(LoginRequiredMixin, FormView):
|
|||
# If the Stripe payment was successed, set order status approved
|
||||
order.set_approved()
|
||||
|
||||
# Create VM using oppenebula functions
|
||||
# _request = namedtuple('request', 'POST user')
|
||||
# _request.user = request.user
|
||||
# user = namedtuple('user', 'email')
|
||||
# email
|
||||
# _request.POST = {
|
||||
# 'vm_template': vm_template
|
||||
# }
|
||||
|
||||
open_vm = VirtualMachinePlan.create_opennebula_vm(
|
||||
# Create a vm using logged user
|
||||
oppennebula_vm_id = VirtualMachinePlan.create_opennebula_vm(
|
||||
self.request.user,
|
||||
specs
|
||||
)
|
||||
|
||||
print(open_vm)
|
||||
print(open_vm)
|
||||
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
|
||||
plan.oppenebula_id = oppennebula_vm_id
|
||||
plan.save()
|
||||
|
||||
# Send notification to ungleich as soon as VM has been booked
|
||||
context = {
|
||||
|
|
Loading…
Reference in a new issue