

class UpdateInstances(object):

    @staticmethod
    def do():
        from dbaas_cloudstack.models import DatabaseInfraOffering
        from dbaas_cloudstack.models import PlanAttr

        infra_offerings = DatabaseInfraOffering.objects.all()

        for infra_offering in infra_offerings:
            plan_attr = PlanAttr.objects.get(plan=infra_offering.databaseinfra.plan)
            strong_offering = infra_offering.offering
            weaker_offering = plan_attr.get_weaker_offering()

            for instance in infra_offering.databaseinfra.instances.all():
                if instance.is_database:
                    instance.offering = weaker_offering
                else:
                    instance.oferring = strong_offering

                instance.save()



class UpdateInstances(object):

    @staticmethod
    def do():
        from dbaas_cloudstack.models import DatabaseInfraOffering
        from dbaas_cloudstack.models import PlanAttr

        infra_offerings = DatabaseInfraOffering.objects.all()

        for infra_offering in infra_offerings:
            plan_attr = PlanAttr.objects.get(plan=infra_offering.databaseinfra.plan)
            strong_offering = infra_offering.offering
            weaker_offering = plan_attr.get_weaker_offering()

            for instance in infra_offering.databaseinfra.instances.all():
                if instance.is_database:
                    instance.offering = strong_offering
                else:
                    instance.oferring = weaker_offering

                instance.save()

Fix script to update offering on instances
Fix script to update offering on instances

  
  
  class UpdateInstances(object):
  
      @staticmethod
      def do():
          from dbaas_cloudstack.models import DatabaseInfraOffering
          from dbaas_cloudstack.models import PlanAttr
  
          infra_offerings = DatabaseInfraOffering.objects.all()
  
          for infra_offering in infra_offerings:
              plan_attr = PlanAttr.objects.get(plan=infra_offering.databaseinfra.plan)
              strong_offering = infra_offering.offering
              weaker_offering = plan_attr.get_weaker_offering()
  
              for instance in infra_offering.databaseinfra.instances.all():
                  if instance.is_database:
-                     instance.offering = weaker_offering
+                     instance.offering = strong_offering
                  else:
-                     instance.oferring = strong_offering
+                     instance.oferring = weaker_offering
  
                  instance.save()
  
Fix script to update offering on instances
## Code Before:


class UpdateInstances(object):

    @staticmethod
    def do():
        from dbaas_cloudstack.models import DatabaseInfraOffering
        from dbaas_cloudstack.models import PlanAttr

        infra_offerings = DatabaseInfraOffering.objects.all()

        for infra_offering in infra_offerings:
            plan_attr = PlanAttr.objects.get(plan=infra_offering.databaseinfra.plan)
            strong_offering = infra_offering.offering
            weaker_offering = plan_attr.get_weaker_offering()

            for instance in infra_offering.databaseinfra.instances.all():
                if instance.is_database:
                    instance.offering = weaker_offering
                else:
                    instance.oferring = strong_offering

                instance.save()

## Instruction:
Fix script to update offering on instances
## Code After:


class UpdateInstances(object):

    @staticmethod
    def do():
        from dbaas_cloudstack.models import DatabaseInfraOffering
        from dbaas_cloudstack.models import PlanAttr

        infra_offerings = DatabaseInfraOffering.objects.all()

        for infra_offering in infra_offerings:
            plan_attr = PlanAttr.objects.get(plan=infra_offering.databaseinfra.plan)
            strong_offering = infra_offering.offering
            weaker_offering = plan_attr.get_weaker_offering()

            for instance in infra_offering.databaseinfra.instances.all():
                if instance.is_database:
                    instance.offering = strong_offering
                else:
                    instance.oferring = weaker_offering

                instance.save()
