Пример #1
0
 def create(cls, owner, group, version=None, date=None, provider=None, num_appliances=1,
         time_leased=60, preconfigured=True):
     from appliances.tasks import request_appliance_pool
     # Retrieve latest possible
     if not version:
         versions = Template.get_versions(
             template_group=group, ready=True, usable=True, preconfigured=preconfigured)
         if versions:
             version = versions[0]
     if not date:
         if version is not None:
             dates = Template.get_dates(template_group=group, version=version, ready=True,
                 usable=True, preconfigured=preconfigured)
         else:
             dates = Template.get_dates(
                 template_group=group, ready=True, usable=True, preconfigured=preconfigured)
         if dates:
             date = dates[0]
     if isinstance(group, basestring):
         group = Group.objects.get(id=group)
     if isinstance(provider, basestring):
         provider = Provider.objects.get(id=provider)
     if not (version or date):
         raise Exception("Could not find possible combination of group, date and version!")
     req = cls(
         group=group, version=version, date=date, total_count=num_appliances, owner=owner,
         provider=provider, preconfigured=preconfigured)
     if not req.possible_templates:
         raise Exception("No possible templates! (query: {}".format(str(req.__dict__)))
     req.save()
     logger().info("Appliance pool {} created".format(req.id))
     request_appliance_pool.delay(req.id, time_leased)
     return req
Пример #2
0
 def create(cls, owner, group, version=None, date=None, provider=None, num_appliances=1,
         time_leased=60, preconfigured=True, yum_update=False):
     if owner.has_quotas:
         user_pools_count = cls.objects.filter(owner=owner).count()
         user_vms_count = Appliance.objects.filter(appliance_pool__owner=owner).count()
         if owner.quotas.total_pool_quota is not None:
             if owner.quotas.total_pool_quota <= user_pools_count:
                 raise ValueError(
                     "User has too many pools ({} allowed, {} already existing)".format(
                         owner.quotas.total_pool_quota, user_pools_count))
         if owner.quotas.total_vm_quota is not None:
             if owner.quotas.total_vm_quota <= (user_vms_count + num_appliances):
                 raise ValueError(
                     "Requested {} appliances, limit is {} and currently user has {}".format(
                         num_appliances, owner.quotas.total_vm_quota, user_vms_count))
         if owner.quotas.per_pool_quota is not None:
             if num_appliances > owner.quotas.per_pool_quota:
                 raise ValueError("You are limited to {} VMs per pool, requested {}".format(
                     owner.quotas.per_pool_quota, num_appliances))
     from appliances.tasks import request_appliance_pool
     # Retrieve latest possible
     if not version:
         versions = Template.get_versions(
             template_group=group, ready=True, usable=True, exists=True,
             preconfigured=preconfigured, provider__working=True, provider__disabled=False)
         if versions:
             version = versions[0]
     if not date:
         if version is not None:
             dates = Template.get_dates(template_group=group, version=version, ready=True,
                 usable=True, exists=True, preconfigured=preconfigured, provider__working=True,
                 provider__disabled=False)
         else:
             dates = Template.get_dates(
                 template_group=group, ready=True, usable=True, exists=True,
                 preconfigured=preconfigured, provider__working=True, provider__disabled=False)
         if dates:
             date = dates[0]
     if isinstance(group, basestring):
         group = Group.objects.get(id=group)
     if isinstance(provider, basestring):
         provider = Provider.objects.get(id=provider, working=True, disabled=False)
     if not (version or date):
         raise Exception(
             "Could not find proper combination of group, date, version and a working provider!")
     req_params = dict(
         group=group, version=version, date=date, total_count=num_appliances, owner=owner,
         provider=provider, preconfigured=preconfigured, yum_update=yum_update)
     req = cls(**req_params)
     if not req.possible_templates:
         raise Exception("No possible templates! (pool params: {})".format(str(req_params)))
     req.save()
     cls.class_logger(req.pk).info("Created")
     request_appliance_pool.delay(req.id, time_leased)
     return req
Пример #3
0
 def create(cls,
            owner,
            group,
            version=None,
            date=None,
            provider=None,
            num_appliances=1,
            time_leased=60,
            preconfigured=True,
            yum_update=False):
     if owner.has_quotas:
         user_pools_count = cls.objects.filter(owner=owner).count()
         user_vms_count = Appliance.objects.filter(
             appliance_pool__owner=owner).count()
         if owner.quotas.total_pool_quota is not None:
             if owner.quotas.total_pool_quota <= user_pools_count:
                 raise ValueError(
                     "User has too many pools ({} allowed, {} already existing)"
                     .format(owner.quotas.total_pool_quota,
                             user_pools_count))
         if owner.quotas.total_vm_quota is not None:
             if owner.quotas.total_vm_quota <= (user_vms_count +
                                                num_appliances):
                 raise ValueError(
                     "Requested {} appliances, limit is {} and currently user has {}"
                     .format(num_appliances, owner.quotas.total_vm_quota,
                             user_vms_count))
         if owner.quotas.per_pool_quota is not None:
             if num_appliances > owner.quotas.per_pool_quota:
                 raise ValueError(
                     "You are limited to {} VMs per pool, requested {}".
                     format(owner.quotas.per_pool_quota, num_appliances))
     from appliances.tasks import request_appliance_pool
     # Retrieve latest possible
     if not version:
         versions = Template.get_versions(template_group=group,
                                          ready=True,
                                          usable=True,
                                          exists=True,
                                          preconfigured=preconfigured,
                                          provider__working=True,
                                          provider__disabled=False)
         if versions:
             version = versions[0]
     if not date:
         if version is not None:
             dates = Template.get_dates(template_group=group,
                                        version=version,
                                        ready=True,
                                        usable=True,
                                        exists=True,
                                        preconfigured=preconfigured,
                                        provider__working=True,
                                        provider__disabled=False)
         else:
             dates = Template.get_dates(template_group=group,
                                        ready=True,
                                        usable=True,
                                        exists=True,
                                        preconfigured=preconfigured,
                                        provider__working=True,
                                        provider__disabled=False)
         if dates:
             date = dates[0]
     if isinstance(group, basestring):
         group = Group.objects.get(id=group)
     if isinstance(provider, basestring):
         provider = Provider.objects.get(id=provider,
                                         working=True,
                                         disabled=False)
     if not (version or date):
         raise Exception(
             "Could not find proper combination of group, date, version and a working provider!"
         )
     req_params = dict(group=group,
                       version=version,
                       date=date,
                       total_count=num_appliances,
                       owner=owner,
                       provider=provider,
                       preconfigured=preconfigured,
                       yum_update=yum_update)
     req = cls(**req_params)
     if not req.possible_templates:
         raise Exception("No possible templates! (pool params: {})".format(
             str(req_params)))
     req.save()
     cls.class_logger(req.pk).info("Created")
     request_appliance_pool.delay(req.id, time_leased)
     return req