Beispiel #1
0
 def handle(self, **options):
     queuename = options.get('queuename')
     if not queuename:
         raise CommandError("Specify `--queuename` to use this command.")
     changed = False
     with advisory_lock('instance_group_registration_%s' % queuename):
         ig = InstanceGroup.objects.filter(name=queuename)
         control_ig = None
         if options.get('controller'):
             control_ig = InstanceGroup.objects.filter(
                 name=options.get('controller')).first()
         if ig.exists():
             print("Instance Group already registered {}".format(
                 ig[0].name))
             ig = ig[0]
             if control_ig and ig.controller_id != control_ig.pk:
                 ig.controller = control_ig
                 ig.save()
                 print("Set controller group {} on {}.".format(
                     control_ig.name, ig.name))
                 changed = True
         else:
             print("Creating instance group {}".format(queuename))
             ig = InstanceGroup(
                 name=queuename,
                 policy_instance_percentage=options.get('instance_percent'),
                 policy_instance_minimum=options.get('instance_minimum'))
             if control_ig:
                 ig.controller = control_ig
             ig.save()
             changed = True
         hostname_list = []
         if options.get('hostnames'):
             hostname_list = options.get('hostnames').split(",")
         instance_list = [x.strip() for x in hostname_list if x]
         for inst_name in instance_list:
             instance = Instance.objects.filter(hostname=inst_name)
             if instance.exists() and instance[0] not in ig.instances.all():
                 ig.instances.add(instance[0])
                 print("Added instance {} to {}".format(
                     instance[0].hostname, ig.name))
                 changed = True
             elif not instance.exists():
                 print("Instance does not exist: {}".format(inst_name))
                 if changed:
                     print('(changed: True)')
                 sys.exit(1)
             else:
                 print("Instance already registered {}".format(
                     instance[0].hostname))
         ig.policy_instance_list = instance_list
         ig.save()
         if changed:
             print('(changed: True)')
def test_containerized_group_default_fields(instance_group, kube_credential):
    ig = InstanceGroup(name="test_policy_field_defaults")
    ig.policy_instance_list = [1]
    ig.policy_instance_minimum = 5
    ig.policy_instance_percentage = 5
    ig.save()
    assert ig.policy_instance_list == [1]
    assert ig.policy_instance_minimum == 5
    assert ig.policy_instance_percentage == 5
    ig.credential = kube_credential
    ig.save()
    assert ig.policy_instance_list == []
    assert ig.policy_instance_minimum == 0
    assert ig.policy_instance_percentage == 0
Beispiel #3
0
def isolated_instance_group(instance_group, instance):
    ig = InstanceGroup(name="iso", controller=instance_group)
    ig.save()
    ig.instances.set([instance])
    ig.save()
    return ig
Beispiel #4
0
def instance_group(job_factory):
    ig = InstanceGroup(name="east")
    ig.save()
    return ig
Beispiel #5
0
def tower_instance_group():
    ig = InstanceGroup(name='tower')
    ig.save()
    return ig
Beispiel #6
0
def containerized_instance_group(instance_group, kube_credential):
    ig = InstanceGroup(name="container")
    ig.credential = kube_credential
    ig.is_container_group = True
    ig.save()
    return ig
def isolated_instance_group(instance_group):
    ig = InstanceGroup(name="iso", controller=instance_group)
    ig.save()
    return ig