Example #1
0
def populate_image_id_choices(self, request, context):

    images = self._get_available_images(request, context)

    if 'cloud' in request.GET:
        cloud = request.GET['cloud']

        if cloud.lower() not in settings.CLOUD_FUNCTIONS['launch_multiple']:
            self.fields['count'].widget.attrs['readonly'] = True

        if cloud.lower() not in settings.CLOUD_FUNCTIONS['namable_servers']:
            self.fields['name'].widget.attrs['readonly'] = True
            self.fields['name'].widget.attrs[
                'value'] = 'Feature not supported.'

        choices = [
            (image.id, image.name) for image in images
            if image.properties.get("image_type", '') != "snapshot" and (
                get_cloud(image) == cloud)
        ]
    else:
        choices = [(image.id, image.name) for image in images
                   if image.properties.get("image_type", '') != "snapshot"]
    if choices:
        choices.insert(0, ("", _("Select Image")))
    else:
        choices.insert(0, ("", _("No images available.")))
    return choices
Example #2
0
def populate_instance_snapshot_id_choices(self, request, context):
    images = self._get_available_images(request, context)

    if 'cloud' in request.GET:
        cloud = request.GET['cloud']

        if cloud.lower() not in settings.CLOUD_FUNCTIONS['launch_multiple']:
            self.fields['count'].widget.attrs['readonly'] = True

        if cloud.lower() not in settings.CLOUD_FUNCTIONS['namable_servers']:
            self.fields['name'].widget.attrs['readonly'] = True
            self.fields['name'].widget.attrs['value'] = 'Feature not supported.'

        choices = [(image.id, image.name) for image in images
            if image.properties.get("image_type", '') == "snapshot"
            and (get_cloud(image) == cloud)]
    else:
        choices = [(image.id, image.name)
               for image in images
               if image.properties.get("image_type", '') == "snapshot"]
    if choices:
        choices.insert(0, ("", _("Select Instance Snapshot")))
    else:
        choices.insert(0, ("", _("No snapshots available.")))
    return choices
Example #3
0
def tenant_quota_usages(request):

    cloud = None
    if 'cloud' in request.GET:
        cloud = request.GET['cloud']
    elif 'cloud' in request.POST:
        cloud = request.POST['cloud']

    # Get our quotas and construct our usage object.
    disabled_quotas = []
    if not is_service_enabled(request, 'volume'):
        disabled_quotas.extend(['volumes', 'gigabytes'])

    usages = QuotaUsage()
    for quota in get_tenant_quota_data(request, disabled_quotas):
        usages.add_quota(quota)

    # Get our usages.
    floating_ips = nova.tenant_floating_ip_list(request)
    #flavors = dict([(f.id, f) for f in nova.flavor_list(request) if limit_by_cloud(f) ])
    flavors = dict([(f.id, f) for f in nova.flavor_list(request)])

    instances = nova.server_list(request)
    if cloud is not None:
        instances = [
            instance for instance in instances if get_cloud(instance) == cloud
        ]

    # Fetch deleted flavors if necessary.
    missing_flavors = [
        instance.flavor['id'] for instance in instances
        if instance.flavor['id'] not in flavors
    ]
    for missing in missing_flavors:
        if missing not in flavors:
            try:
                flavors[missing] = nova.flavor_get(request, missing)
            except:
                flavors[missing] = {}
                exceptions.handle(request, ignore=True)

    usages.tally('instances', len(instances))
    usages.tally('floating_ips', len(floating_ips))

    if 'volumes' not in disabled_quotas:
        volumes = cinder.volume_list(request)
        usages.tally('gigabytes', sum([int(v.size) for v in volumes]))
        usages.tally('volumes', len(volumes))

    # Sum our usage based on the flavors of the instances.
    for flavor in [flavors[instance.flavor['id']] for instance in instances]:
        usages.tally('cores', getattr(flavor, 'vcpus', None))
        usages.tally('ram', getattr(flavor, 'ram', None))

    # Initialise the tally if no instances have been launched yet
    if len(instances) == 0:
        usages.tally('cores', 0)
        usages.tally('ram', 0)

    return usages
Example #4
0
 def get_link_url(self, datum):
     base_url = reverse(self.url)
     params = urlencode({
         "source_type": "instance_snapshot_id",
         "cloud": get_cloud(datum),
         "source_id": self.table.get_object_id(datum)
     })
     return "?".join([base_url, params])
Example #5
0
def tenant_quota_usages(request):

    cloud = None
    if 'cloud' in request.GET:
        cloud = request.GET['cloud']
    elif 'cloud' in request.POST:
        cloud = request.POST['cloud']

    # Get our quotas and construct our usage object.
    disabled_quotas = []
    if not is_service_enabled(request, 'volume'):
        disabled_quotas.extend(['volumes', 'gigabytes'])

    usages = QuotaUsage()
    for quota in get_tenant_quota_data(request, disabled_quotas):
        usages.add_quota(quota)

    # Get our usages.
    floating_ips = nova.tenant_floating_ip_list(request)
    #flavors = dict([(f.id, f) for f in nova.flavor_list(request) if limit_by_cloud(f) ])
    flavors = dict([(f.id, f) for f in nova.flavor_list(request) ])

    instances = nova.server_list(request)
    if cloud is not None:
        instances = [instance for instance in instances 
            if get_cloud(instance) == cloud]

    # Fetch deleted flavors if necessary.
    missing_flavors = [instance.flavor['id'] for instance in instances
                       if instance.flavor['id'] not in flavors]
    for missing in missing_flavors:
        if missing not in flavors:
            try:
                flavors[missing] = nova.flavor_get(request, missing)
            except:
                flavors[missing] = {}
                exceptions.handle(request, ignore=True)

    usages.tally('instances', len(instances))
    usages.tally('floating_ips', len(floating_ips))

    if 'volumes' not in disabled_quotas:
        volumes = cinder.volume_list(request)
        usages.tally('gigabytes', sum([int(v.size) for v in volumes]))
        usages.tally('volumes', len(volumes))

    # Sum our usage based on the flavors of the instances.
    for flavor in [flavors[instance.flavor['id']] for instance in instances]:
        usages.tally('cores', getattr(flavor, 'vcpus', None))
        usages.tally('ram', getattr(flavor, 'ram', None))

    # Initialise the tally if no instances have been launched yet
    if len(instances) == 0:
        usages.tally('cores', 0)
        usages.tally('ram', 0)

    return usages
Example #6
0
    def load_cells(self, datum=None):
        """
        Load the row's data (either provided at initialization or as an
        argument to this function), initiailize all the cells contained
        by this row, and set the appropriate row properties which require
        the row's data to be determined.

        This function is called automatically by
        :meth:`~horizon.tables.Row.__init__` if the ``datum`` argument is
        provided. However, by not providing the data during initialization
        this function allows for the possibility of a two-step loading
        pattern when you need a row instance but don't yet have the data
        available.
        """
        # Compile all the cells on instantiation.
        table = self.table
        if datum:
            self.datum = datum
        else:
            datum = self.datum
        cells = []
        for column in table.columns.values():
            if column.auto == "multi_select":
                widget = forms.CheckboxInput(check_test=False)
                # Convert value to string to avoid accidental type conversion
                data = widget.render('object_ids',
                                     unicode(table.get_object_id(datum)))
                table._data_cache[column][table.get_object_id(datum)] = data
            elif column.auto == "actions":
                data = table.render_row_actions(datum)
                table._data_cache[column][table.get_object_id(datum)] = data
            else:
                data = column.get_data(datum)
            cell = Cell(datum, data, column, self)
            cells.append((column.name or column.auto, cell))
        self.cells = SortedDict(cells)

        if self.ajax:
            interval = conf.HORIZON_CONFIG['ajax_poll_interval']
            self.attrs['data-update-interval'] = interval
            self.attrs['data-update-url'] = self.get_ajax_update_url()
            self.classes.append("ajax-update")

        # Add class of image's cloud name
        image_cloud = get_cloud(datum)
        self.classes.append(image_cloud.lower())

        # Add the row's status class and id to the attributes to be rendered.
        self.classes.append(self.status_class)
        id_vals = {"table": self.table.name,
                   "sep": STRING_SEPARATOR,
                   "id": table.get_object_id(datum)}
        self.id = "%(table)s%(sep)srow%(sep)s%(id)s" % id_vals
        self.attrs['id'] = self.id
Example #7
0
def cloud_filter(self, elements, field_name, function, request, context):
    if 'cloud' in request.GET:
        context['cloud'] = request.GET['cloud']
    if 'cloud' in context:
        if context['cloud'].lower() not in settings.CLOUD_FUNCTIONS[function]:
            self.fields[field_name].widget = forms.HiddenInput()
        else:
            self.fields[field_name].required = True
        cloud = context['cloud']
        element_list = [(kp.name, kp.name) for kp in elements
                if get_cloud(kp) == cloud]

    return element_list
Example #8
0
def cloud_filter(self, elements, field_name, function, request, context):
    if 'cloud' in request.GET:
        context['cloud'] = request.GET['cloud']
    if 'cloud' in context:
        if context['cloud'].lower() not in settings.CLOUD_FUNCTIONS[function]:
            self.fields[field_name].widget = forms.HiddenInput()
        else:
            self.fields[field_name].required = True
        cloud = context['cloud']
        element_list = [(kp.name, kp.name) for kp in elements
                        if get_cloud(kp) == cloud]

    return element_list
Example #9
0
def populate_flavor_choices(self, request, context):
    try:
        flavors = api.nova.flavor_list(request)

        if 'cloud' in request.GET:
            cloud = request.GET['cloud']
            flavor_list = [(flavor.id, "%s" % flavor.name)
                           for flavor in flavors if get_cloud(flavor) == cloud]
        else:
            flavor_list = [(flavor.id, "%s" % flavor.name)
                           for flavor in flavors]
    except:
        flavor_list = []
        exceptions.handle(request, _('Unable to retrieve instance flavors.'))
    return sorted(flavor_list)
Example #10
0
def populate_flavor_choices(self, request, context):
    try:
        flavors = api.nova.flavor_list(request)

        if 'cloud' in request.GET:
            cloud = request.GET['cloud']
            flavor_list = [(flavor.id, "%s" % flavor.name)
                       for flavor in flavors
           if get_cloud(flavor) == cloud]
        else:
            flavor_list = [(flavor.id, "%s" % flavor.name)
                       for flavor in flavors]
    except:
        flavor_list = []
        exceptions.handle(request,
                          _('Unable to retrieve instance flavors.'))
    return sorted(flavor_list)
Example #11
0
def get_help_text(self):
    extra = {}
    try:
        extra['usages'] = quotas.tenant_quota_usages(self.request)
        extra['usages_json'] = json.dumps(extra['usages'])
        if 'cloud' in self.request.GET:
            cloud = self.request.GET['cloud']
            flavors = json.dumps(
                [f._info for f in api.nova.flavor_list(self.request)
                 if get_cloud(f) == cloud])

        else:
            flavors = json.dumps([f._info for f in
                                   api.nova.flavor_list(self.request)])

        extra['flavors'] = flavors
    except:
        exceptions.handle(self.request,
                          _("Unable to retrieve quota information."))
    return super(SetInstanceDetailsAction, self).get_help_text(extra)
Example #12
0
def populate_keypair_choices(self, request, context):

    try:
        keypairs = api.nova.keypair_list(request)
        if 'cloud' in request.GET:
            context['cloud'] = request.GET['cloud']
        if 'cloud' in context:
            if context['cloud'].lower(
            ) not in settings.CLOUD_FUNCTIONS['instance_keys']:
                self.fields['keypair'].widget = forms.HiddenInput()
            cloud = context['cloud']
            keypair_list = [(kp.name, kp.name) for kp in keypairs
                            if get_cloud(kp) == cloud]
        else:
            keypair_list = [(kp.name, kp.name) for kp in keypairs]
    except:
        keypair_list = []
        exceptions.handle(request, _('Unable to retrieve keypairs.'))
    if keypair_list:
        keypair_list.insert(0, ("", _("Select a keypair")))
    else:
        keypair_list = (("", _("No keypairs available.")), )
    return keypair_list
Example #13
0
def populate_keypair_choices(self, request, context):


    try:
        keypairs = api.nova.keypair_list(request)
        if 'cloud' in request.GET:
            context['cloud'] = request.GET['cloud']
        if 'cloud' in context:
            if context['cloud'].lower() not in settings.CLOUD_FUNCTIONS['instance_keys']:
                self.fields['keypair'].widget = forms.HiddenInput()
            cloud = context['cloud']
            keypair_list = [(kp.name, kp.name) for kp in keypairs
            if get_cloud(kp) == cloud]
        else:
            keypair_list = [(kp.name, kp.name) for kp in keypairs]
    except:
        keypair_list = []
        exceptions.handle(request,
                          _('Unable to retrieve keypairs.'))
    if keypair_list:
        keypair_list.insert(0, ("", _("Select a keypair")))
    else:
        keypair_list = (("", _("No keypairs available.")),)
    return keypair_list
Example #14
0
 def allowed(self, request, image):
     return get_cloud(image).lower() in settings.CLOUD_FUNCTIONS[
         'launch_cluster'] and image.status in ("active", )
Example #15
0
 def get_link_url(self, datum):
     base_url = reverse(self.url)
     params = urlencode({"source_type": "image_id",
             "cloud": get_cloud(datum),
                         "source_id": self.table.get_object_id(datum)})
     return "?".join([base_url, params])
Example #16
0
 def allowed(self, request, image):
     return get_cloud(image).lower() in settings.CLOUD_FUNCTIONS['launch_cluster']
Example #17
0
 def action(self, request, obj_id):
     #need to different
     new_id = "cluster%s-%s" % (get_cloud(self.instance).lower(), obj_id)
     api.server_delete(request, new_id)
Example #18
0
def edit_instance_allowed(self, request, instance=None):

    return get_cloud(instance).lower() in settings.CLOUD_FUNCTIONS['edit_instance'] \
        and old_edit_instance_allowed(self, request, instance)
Example #19
0
 def allowed(self, request, image):
     return get_cloud(image).lower() in settings.CLOUD_FUNCTIONS['launch_cluster'] and image.status in ("active",)
Example #20
0
def simple_disassociate_ip_allowed(self, request, instance=None):

    return get_cloud(instance).lower() in settings.CLOUD_FUNCTIONS['associate_ip'] \
        and old_simple_disassociate_ip_allowed(self, request, instance)
Example #21
0
 def action(self, request, obj_id):
     #need to different
     new_id = "cluster%s-%s" % (get_cloud(self.instance).lower(), obj_id)
     api.server_delete(request, new_id)