def get(self, request, *args, **kwargs): if not UserHostingKey.objects.filter(user=self.request.user).exists(): messages.success( request, 'In order to create a VM, you need to create/upload your SSH KEY first.' ) return HttpResponseRedirect(reverse('hosting:ssh_keys')) try: manager = OpenNebulaManager() templates = manager.get_templates() configuration_options = HostingPlan.get_serialized_configs() context = { 'templates': VirtualMachineTemplateSerializer(templates, many=True).data, 'configuration_options': configuration_options, } except: messages.error( request, 'We could not load the VM templates due to a backend connection \ error. Please try again in a few minutes') context = {'error': 'connection'} return render(request, self.template_name, context)
def get(self, request, *args, **kwargs): if not UserHostingKey.objects.filter( user=self.request.user).exists(): messages.success( request, 'In order to create a VM, you need to create/upload your SSH KEY first.' ) return HttpResponseRedirect(reverse('hosting:ssh_keys')) try: manager = OpenNebulaManager() templates = manager.get_templates() configuration_options = HostingPlan.get_serialized_configs() context = { 'templates': VirtualMachineTemplateSerializer(templates, many=True).data, 'configuration_options': configuration_options, } except: messages.error( request, 'We could not load the VM templates due to a backend connection \ error. Please try again in a few minutes' ) context = { 'error': 'connection' } return render(request, self.template_name, context)
def get(self, request, *args, **kwargs): try: manager = OpenNebulaManager() templates = manager.get_templates() context = { 'templates': VirtualMachineTemplateSerializer(templates, many=True).data, } except: messages.error( request, 'We have a temporary problem to connect to our backend. \ Please try again in a few minutes') context = {'error': 'connection'} return render(request, self.template_name, context)
def get(self, request, *args, **kwargs): try: manager = OpenNebulaManager() templates = manager.get_templates() context = { 'templates': VirtualMachineTemplateSerializer(templates, many=True).data, } except: messages.error( request, 'We have a temporary problem to connect to our backend. \ Please try again in a few minutes' ) context = { 'error' : 'connection' } return render(request, self.template_name, context)
def get(self, request, *args, **kwargs): for session_var in ['specs', 'user', 'billing_address_data']: if session_var in request.session: del request.session[session_var] try: manager = OpenNebulaManager() templates = manager.get_templates() context = { 'templates': VirtualMachineTemplateSerializer(templates, many=True).data } except: messages.error( request, 'We have a temporary problem to connect to our backend. \ Please try again in a few minutes') context = {'error': 'connection'} return render(request, self.template_name, context)
def get(self, request, *args, **kwargs): try: manager = OpenNebulaManager() templates = manager.get_templates() context = { 'templates': VirtualMachineTemplateSerializer(templates, many=True).data, } except: messages.error( request, 'We could not load the VM templates due to a backend connection \ error. Please try again in a few minutes' ) context = { 'error' : 'connection' } return render(request, self.template_name, context)
def handle(self, *args, **options): try: manager = OpenNebulaManager() templates = manager.get_templates() dcl_vm_templates = [] for template in templates: template_name = template.name.strip('public-') template_id = template.id dcl_vm_template = VMTemplate.create(template_name, template_id) dcl_vm_templates.append(dcl_vm_template) old_vm_templates = VMTemplate.objects.all() old_vm_templates.delete() for dcl_vm_template in dcl_vm_templates: dcl_vm_template.save() except Exception as e: logger.error( 'Error connecting to OpenNebula. Error Details: {err}'.format( err=str(e)))