def get_murano_images(request, region=None): images = [] try: # https://bugs.launchpad.net/murano/+bug/1339261 - glance # client version change alters the API. Other tuple values # are _more and _prev (in recent glance client) with helpers.current_region(request, region): images = glance.image_list_detailed(request)[0] except Exception: LOG.error("Error to request image list from glance ") exceptions.handle(request, _("Unable to retrieve public images.")) murano_images = [] # filter out the snapshot image type images = filter(lambda x: x.properties.get("image_type", '') != 'snapshot', images) for image in images: # Additional properties, whose value is always a string data type, are # only included in the response if they have a value. murano_property = getattr(image, 'murano_image_info', None) if murano_property: try: murano_metadata = json.loads(murano_property) except ValueError: LOG.warning("JSON in image metadata is not valid. " "Check it in glance.") messages.error(request, _("Invalid murano image metadata")) else: image.murano_property = murano_metadata murano_images.append(image) return murano_images
def update(self, request, form=None, **kwargs): self.choices = [('', _('No keypair'))] with helpers.current_region(request, getattr(form, 'region', None)): keypairs = nova.novaclient(request).keypairs.list() for keypair in sorted(keypairs, key=lambda e: e.name): self.choices.append((keypair.name, keypair.name))
def update(self, request, form=None, **kwargs): self.choices = [('', _('No keypair'))] with helpers.current_region(request, getattr(form, 'region', None)): keypairs = nova.novaclient(request).keypairs.list() for keypair in sorted(keypairs, key=lambda e: e.name): self.choices.append((keypair.name, keypair.name))
def get_murano_images(request, region=None): images = [] try: # https://bugs.launchpad.net/murano/+bug/1339261 - glance # client version change alters the API. Other tuple values # are _more and _prev (in recent glance client) with helpers.current_region(request, region): images = glance.image_list_detailed(request)[0] except Exception: LOG.error("Error to request image list from glance ") exceptions.handle(request, _("Unable to retrieve public images.")) murano_images = [] # filter out the snapshot image type images = filter( lambda x: x.properties.get("image_type", '') != 'snapshot', images) for image in images: # Additional properties, whose value is always a string data type, are # only included in the response if they have a value. murano_property = getattr(image, 'murano_image_info', None) if murano_property: try: murano_metadata = json.loads(murano_property) except ValueError: LOG.warning("JSON in image metadata is not valid. " "Check it in glance.") messages.error(request, _("Invalid murano image metadata")) else: image.murano_property = murano_metadata murano_images.append(image) return murano_images
def update(self, request, form=None, **kwargs): choices = [] with helpers.current_region(request, getattr(form, 'region', None)): flavors = nova.novaclient(request).flavors.list() # If no requirements are present, return all the flavors. if not hasattr(self, 'requirements'): choices = [(flavor.id, flavor.name) for flavor in flavors] else: for flavor in flavors: # If a flavor doesn't meet a minimum requirement, # do not add it to the options list and skip to the # next flavor. if flavor.vcpus < self.requirements.get('min_vcpus', 0): continue if flavor.disk < self.requirements.get('min_disk', 0): continue if flavor.ram < self.requirements.get('min_memory_mb', 0): continue if 'max_vcpus' in self.requirements: if flavor.vcpus > self.requirements['max_vcpus']: continue if 'max_disk' in self.requirements: if flavor.disk > self.requirements['max_disk']: continue if 'max_memory_mb' in self.requirements: if flavor.ram > self.requirements['max_memory_mb']: continue choices.append((flavor.id, flavor.name)) choices.sort(key=lambda e: e[1]) self.choices = choices if kwargs.get('form'): kwargs_form_flavor = kwargs["form"].fields.get('flavor') else: kwargs_form_flavor = None if kwargs_form_flavor: self.initial = kwargs["form"]["flavor"].value() else: # Search through selected flavors for flavor_id, flavor_name in self.choices: if 'medium' in flavor_name: self.initial = flavor_id break
def update(self, request, form=None, **kwargs): choices = [] with helpers.current_region(request, getattr(form, 'region', None)): flavors = nova.novaclient(request).flavors.list() # If no requirements are present, return all the flavors. if not hasattr(self, 'requirements'): choices = [(flavor.id, flavor.name) for flavor in flavors] else: for flavor in flavors: # If a flavor doesn't meet a minimum requirement, # do not add it to the options list and skip to the # next flavor. if flavor.vcpus < self.requirements.get('min_vcpus', 0): continue if flavor.disk < self.requirements.get('min_disk', 0): continue if flavor.ram < self.requirements.get('min_memory_mb', 0): continue if 'max_vcpus' in self.requirements: if flavor.vcpus > self.requirements['max_vcpus']: continue if 'max_disk' in self.requirements: if flavor.disk > self.requirements['max_disk']: continue if 'max_memory_mb' in self.requirements: if flavor.ram > self.requirements['max_memory_mb']: continue choices.append((flavor.id, flavor.name)) choices.sort(key=lambda e: e[1]) self.choices = choices if kwargs.get('form'): kwargs_form_flavor = kwargs["form"].fields.get('flavor') else: kwargs_form_flavor = None if kwargs_form_flavor: self.initial = kwargs["form"]["flavor"].value() else: # Search through selected flavors for flavor_id, flavor_name in self.choices: if 'medium' in flavor_name: self.initial = flavor_id break
def update(self, request, form=None, **kwargs): try: with helpers.current_region(request, getattr(form, 'region', None)): availability_zones = nova.novaclient( request).availability_zones.list(detailed=False) except Exception: availability_zones = [] exceptions.handle(request, _("Unable to retrieve availability zones.")) az_choices = [(az.zoneName, az.zoneName) for az in availability_zones if az.zoneState] if not az_choices: az_choices.insert(0, ("", _("No availability zones available"))) az_choices.sort(key=lambda e: e[1]) self.choices = az_choices
def update(self, request, form=None, **kwargs): try: with helpers.current_region(request, getattr(form, 'region', None)): availability_zones = nova.novaclient( request).availability_zones.list(detailed=False) except Exception: availability_zones = [] exceptions.handle(request, _("Unable to retrieve availability zones.")) az_choices = [(az.zoneName, az.zoneName) for az in availability_zones if az.zoneState] if not az_choices: az_choices.insert(0, ("", _("No availability zones available"))) az_choices.sort(key=lambda e: e[1]) self.choices = az_choices
def get_context_data(self, form, **kwargs): context = super(Wizard, self).get_context_data(form=form, **kwargs) mc = api.muranoclient(self.request) app_id = self.kwargs.get('app_id') app = self.storage.extra_data.get('app') # Save extra data to prevent extra API calls if not app: app = mc.packages.get(app_id) self.storage.extra_data['app'] = app wizard_id = self.request.POST.get('wizard_id') if wizard_id is None: wizard_id = uuid.uuid4() environment_id = self.kwargs.get('environment_id') environment_id = utils.ensure_python_obj(environment_id) if environment_id is not None: env_name = mc.environments.get(environment_id).name else: env_name = get_next_quick_environment_name(self.request) field_descr, extended_descr = services.get_app_field_descriptions( self.request, app_id, self.steps.index) context.update({ 'type': app.fully_qualified_name, 'service_name': app.name, 'app_id': app_id, 'environment_id': environment_id, 'environment_name': env_name, 'do_redirect': self.get_wizard_flag('do_redirect'), 'drop_wm_form': self.get_wizard_flag('drop_wm_form'), 'prefix': self.prefix, 'wizard_id': wizard_id, 'field_descriptions': field_descr, 'extended_descriptions': extended_descr, }) with helpers.current_region(self.request, form.region): context = self.update_usages(form, context) return context
def get_context_data(self, form, **kwargs): context = super(Wizard, self).get_context_data(form=form, **kwargs) mc = api.muranoclient(self.request) app_id = self.kwargs.get('app_id') app = self.storage.extra_data.get('app') # Save extra data to prevent extra API calls if not app: app = mc.packages.get(app_id) self.storage.extra_data['app'] = app wizard_id = self.request.POST.get('wizard_id') if wizard_id is None: wizard_id = uuid.uuid4() environment_id = self.kwargs.get('environment_id') environment_id = utils.ensure_python_obj(environment_id) if environment_id is not None: env_name = mc.environments.get(environment_id).name else: env_name = get_next_quick_environment_name(self.request) field_descr, extended_descr = services.get_app_field_descriptions( self.request, app_id, self.steps.index) context.update({'type': app.fully_qualified_name, 'service_name': app.name, 'app_id': app_id, 'environment_id': environment_id, 'environment_name': env_name, 'do_redirect': self.get_wizard_flag('do_redirect'), 'drop_wm_form': self.get_wizard_flag('drop_wm_form'), 'prefix': self.prefix, 'wizard_id': wizard_id, 'field_descriptions': field_descr, 'extended_descriptions': extended_descr, }) with helpers.current_region(self.request, form.region): context = self.update_usages(form, context) return context