Commit b5365f43 authored by Michael R's avatar Michael R
Browse files

Add ability to use multiple models with same profile to workflow-migrate command

parent e1e328bf
Pipeline #37259 passed with stages
in 15 minutes and 45 seconds
......@@ -28,7 +28,7 @@ class Command(BaseCommand):
"phone.PhoneRangeProfile": "phone.PhoneRange",
"vc.L2DomainProfile": "vc.L2Domain",
"vc.VLANProfile": "vc.VLAN",
"vc.VPNProfile": "vc.VPN",
"vc.VPNProfile": ["vc.VPN", "ip.VRF"],
"inv.SensorProfile": "inv.Sensor",
"pm.AgentProfile": "pm.Agent",
"sa.ServiceProfile": "sa.Service",
......@@ -76,7 +76,10 @@ class Command(BaseCommand):
if not wfm:
self.die("Invalid migration %s" % wfm.name)
pmodel = get_model(profile)
imodel = get_model(self.PROFILE_MAP[profile])
models = self.PROFILE_MAP[profile]
if isinstance(models, str):
models = [models]
imodels = [get_model(model) for model in models]
for pid in profiles:
p = pmodel.get_by_id(pid)
if not p:
......@@ -87,11 +90,14 @@ class Command(BaseCommand):
self.print("No translations")
continue
for ostate in tr:
c = imodel.objects.filter(state=ostate.id, profile=pid).count()
self.print(" %s -> %s: %d records" % (ostate, tr[ostate], c))
if c and not dry_run:
for o in imodel.objects.filter(state=ostate.id, profile=pid):
o.set_state(tr[ostate])
for imodel in imodels:
c = imodel.objects.filter(state=ostate.id, profile=pid).count()
self.print(
f" {ostate} -> {tr[ostate]}: {c} records in model '{imodel.__name__}'"
)
if c and not dry_run:
for o in imodel.objects.filter(state=ostate.id, profile=pid):
o.set_state(tr[ostate])
def handle_expire(self, dry_run=False, model=None, *args, **kwargs):
model = model or self.EXPIRE_MODELS
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment