Beispiel #1
0
    def clean(self):
        data = super(forms.Form, self).clean()
        tenant_id = data.get('tenant_id', None)
        name_launch = data.get('name_launch', None)
        if len(name_launch) < 2:
            raise ValidationError(_("Server Name value between 2 and 10."))
        elif len(name_launch) >10:
            raise ValidationError(_("Server Name value between 2 and 10."))


        check_data(data)

        if 'flavor' in data:
            try:
                flavor_id = None
                api.flavor_get(self.request, data['flavor'])
                flavors = api.flavor_list(self.request)
                for flavor in flavors:
                    if str(flavor.id) is str(data['flavor']):
                        flavor_id = flavor
                        break
                if flavor_id is not None and flavor_id.disk < int(
                    data['min_disk']):
                    msg = 'Instance flavor disk less-than Image min disk!'
                    raise ValidationError(_(msg))
                if flavor_id is not None and flavor_id.ram < int(
                    data['min_ram']):
                    msg = 'Instance flavor ram less-than Image min ram!'
                    raise ValidationError(_(msg))
            except Unauthorized:
                raise
            except Exception, e:
                LOG.error('can not get the usage info of tenant %s,%s' %
                          (tenant_id, e))
                return data
Beispiel #2
0
    def clean(self):
        data = super(forms.Form, self).clean()
        tenant_id = data.get('tenant_id', None)
        name_launch = data.get('name_launch', None)
        if len(name_launch) < 2:
            raise ValidationError(_("Server Name value between 2 and 10."))
        elif len(name_launch) > 10:
            raise ValidationError(_("Server Name value between 2 and 10."))

        check_data(data)

        if 'flavor' in data:
            try:
                flavor_id = None
                api.flavor_get(self.request, data['flavor'])
                flavors = api.flavor_list(self.request)
                for flavor in flavors:
                    if str(flavor.id) is str(data['flavor']):
                        flavor_id = flavor
                        break
                if flavor_id is not None and flavor_id.disk < int(
                        data['min_disk']):
                    msg = 'Instance flavor disk less-than Image min disk!'
                    raise ValidationError(_(msg))
                if flavor_id is not None and flavor_id.ram < int(
                        data['min_ram']):
                    msg = 'Instance flavor ram less-than Image min ram!'
                    raise ValidationError(_(msg))
            except Unauthorized:
                raise
            except Exception, e:
                LOG.error('can not get the usage info of tenant %s,%s' %
                          (tenant_id, e))
                return data
Beispiel #3
0
def search_flavor_status(request):
    """
    :param request: request object
    :return flavors list {flavor.id, flavor.disk}
    """
    try:
        flavors = api.flavor_list(request)
        flavor_list = [(flavor.id, {"fla_disk": flavor.disk, "fla_ram": flavor.ram})
                       for flavor in flavors]
    except Unauthorized:
        raise
    except Exception, e:
        flavor_list = []
        LOG.error('Unable to retrieve instance flavors.%s' % e)
Beispiel #4
0
    def clean(self):
        '''Check to make sure password fields match.'''
        data = super(forms.Form, self).clean()
#        flavor_name = data['name']
#        if not has_hz(flavor_name):
#            msg = 'Flavor Name has chinese.'
#            raise ValidationError(_(msg))

        try:
            flavors = api.flavor_list(self.request)
        except Unauthorized:
            raise
        except Exception, e:
            LOG.error('Unable to retrieve user list in handle_create.%s' % e)
            return data
Beispiel #5
0
def search_flavor_status(request):
    """
        :param request: request object
        :return flavors list {flavor.id, flavor.disk}
    """
    try:
        flavors = api.flavor_list(request)
        flavor_list = []
        for flavor in flavors:
            flavor_list.append((flavor.id + "disk", flavor.disk))
            flavor_list.append((flavor.id + 'ram', flavor.ram))
    except Unauthorized:
        raise
    except Exception, exc:
        flavor_list = []
        LOG.error('Unable to retrieve instance flavors.%s' % exc)
Beispiel #6
0
def delete_flavor(request,flavor_id):
    """
    :param request: request object
    :param flavor_id: the flavor id which will be deleted
    :return view<'get_flavor_list'>: view of flavor list
    """
    oldflavor = None
    try:
        flavors = api.flavor_list(request)
        for flav in flavors:
            if flav.id == flavor_id:
                oldflavor = flav
                break
    except Unauthorized:
        raise
    except Exception,e:
        LOG.debug(e)