How To Programmatically import Azure Subnets in Azure Environment in CMP

Overview

In some cases, manually importing and configuring subnets for each azure environment is not desirable due to frequent changes of subnets in azure. This article discusses how to write a recurring job to programmatically import azure environment subnets in CMP.


Considerations

The Azure resource handler and is already configured in CMP.

Procedure

Step 1 Add a recurring job

  1. Go to Admin → Reccurings job

  2. Add a new recurring job from Action

  3. Fill the rest of the form

  4. Add this code

    from resourcehandlers.azure_arm.models import AzureArmHandler
    
    
    def run(job, logger=None):
        azure_handler = AzureArmHandler.objects.get(id=00) #replace 00 with ID of your Azure RH
        envs = azure_handler.environment_set.all()
        for env in envs:
            azure_handler.sync_subnets(env=env)    
        return "" "" ""

Step 2 Schedule the recurring job for a specific time to run

  1. From the Admin → Recurring jobs → Select the recurring job you added in Step #1

  2. Click on the pencil to edit the schedule

  3. Provide a cron schedule https://crontab.guru/

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.