Browse Source

checkvm: add --absent-ok argument

Élie Bouttier 7 years ago
parent
commit
236eb9213b
1 changed files with 4 additions and 3 deletions
  1. 4 3
      services/management/commands/checkvm.py

+ 4 - 3
services/management/commands/checkvm.py

@@ -22,6 +22,7 @@ class Command(BaseCommand):
 
     def add_arguments(self, parser):
         parser.add_argument('file', help='Fichier OpenStack')
+        parser.add_argument('--absent-ok', help='Ne pas afficher de message d’erreur si la VM est absente d’OpenStack', action='append')
     
     def handle(self, *args, **options):
         vm_st = ServiceType.objects.get(name='VM')
@@ -33,7 +34,7 @@ class Command(BaseCommand):
         else:
             with f:
                 openstack_list = self.get_openstack_list(f)
-        self.compare(djadhere_list, openstack_list)
+        self.compare(djadhere_list, openstack_list, absent_ok=options['absent_ok'])
 
     def get_openstack_list(self, f):
         openstack_list = []
@@ -46,7 +47,7 @@ class Command(BaseCommand):
                 openstack_list += [ (nom, ip, created) ]
         return openstack_list
 
-    def compare(self, djadhere_list, openstack_list):
+    def compare(self, djadhere_list, openstack_list, absent_ok=[]):
         for vm in djadhere_list.filter(label__exact=''):
             self.stdout.write(self.style.WARNING("> La VM n°%d n’a pas de label.\n"
                   "Celui-ci est obligatoire pour les VM afin de les retrouver dans OpenStack.\n"
@@ -73,7 +74,7 @@ class Command(BaseCommand):
                       "Il faut renseigner cette allocation dans Djadhere ou dés-allouer cette IP dans OpenStack." % (ip, vm)))
         for vm in djadhere_name_set - openstack_name_set: # Only in djadhere
             djadhere = djadhere_list.get(label=vm)
-            if djadhere.active:
+            if djadhere.active and vm not in absent_ok:
                 self.stdout.write(self.style.WARNING("> La VM '%s' présente dans Djadhere est absente d’OpenStack.\n"
                       "Soit il s’agit d’une VM à créer dans OpenStack, soit elle a été supprimée d’OpenStack et le service doit être marqué inactif dans Djadhere." % vm))
         for vm in openstack_name_set - djadhere_name_set: # Only in openstack