For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

ANL_158394's avatar
ANL_158394
Icon for Nimbostratus rankNimbostratus
Jun 04, 2014

Adding and Deleting data group records and ZoneRunner records via PowerShell

What I would like to do is script the creation of Data Group Records and ZoneRunner records across our various F5s. What I would need is to list all the records within a specific data group and ZoneRunner to make sure the record does not already exist and then create it or delete it, and in turn do the opposite for deleting records... Is there an easy way to do this with PowerShell?

 

Thanks! Tony

 

15 Replies

  • So I am trying to just list the resource records get_rrs and get_rrs_detailed and I am getting the following error:

     

    An unhandled exception of type 'System.Net.WebException' occurred in System.dll

     

    Here's the code:

     

    Interfaces interfaces = new Interfaces();

     

    string[] view = { "external" };

     

    ManagementViewInfo[] views = interfaces.ManagementView.get_list();

     

    ManagementViewZone[] viewZones = interfaces.ManagementZone.get_zone_name(view);

     

    ManagementZoneInfo[] zoneInfo = interfaces.ManagementZone.get_zone(viewZones);

     

    ManagementResourceRecord rr = new ManagementResourceRecord();

     

    string[][] resourceRecords = rr.get_rrs(viewZones);

     

    ManagementRRList[] resourceRecordsDetailed = rr.get_rrs_detailed(viewZones);

     

    Thanks!

     

  • Brent_West_7733's avatar
    Brent_West_7733
    Historic F5 Account

    Unless I am mistakien, your arrays should be constructed like this...

     

    [[view_name][zone_name]],[[[domain_name][cname][ttl]]]

     

    And for your gets, which call is generating the error?

     

  • The get_rrs and get_rrs_detailed.

     

    Let me take a crack at constructing these arrays.

     

    Thanks!

     

  • I'm lost. Maybe I just don't know enough about the data structure nut this seems like overkill... I am getting a null reference exception at this line: recordseqseq[0][0] = recordseq[0]; This does appear to fix the issues with add_cname but the code doesn't get to that point so I am not sure if it really is fixed... At least Visual Studio is not underlining the add_cname line anymore because the overloads are to correct data structure it is looking for.

     

            Interfaces interfaces = new Interfaces();
            string[] view = { "external" };
            ManagementViewInfo[] views = interfaces.ManagementView.get_list();
            ManagementViewZone[] viewZones = interfaces.ManagementZone.get_zone_name(view);
            ManagementZoneInfo[] zoneInfo = interfaces.ManagementZone.get_zone(viewZones);
            ManagementCNAMERecord record = new ManagementCNAMERecord();
            record.cname = "test";
            record.domain_name = "st.int";
            record.ttl = 3600;
            ManagementCNAMERecord[] recordseq = new ManagementCNAMERecord[1];
            ManagementCNAMERecord[][] recordseqseq = new ManagementCNAMERecord[1][];
            recordseq[0] = record;
            recordseqseq[0][0] = recordseq[0];
            interfaces.ManagementResourceRecord.add_cname(viewZones, recordseqseq);

    Any ideas what the deal is?

     

  • I figured it out! Code below:

     

        Interfaces interfaces = new Interfaces();
        string[] view = { "external" };
        ManagementViewInfo[] views = interfaces.ManagementView.get_list();
        ManagementViewZone[] viewZones = interfaces.ManagementZone.get_zone_name(view);
        ManagementZoneInfo[] zoneInfo = interfaces.ManagementZone.get_zone(viewZones);
        ManagementCNAMERecord record = new ManagementCNAMERecord();
        record.cname = "test";
        record.domain_name = "st.int";
        record.ttl = 3600;
        ManagementCNAMERecord[][] recordseqseq = new ManagementCNAMERecord[][]
        {
            new ManagementCNAMERecord[] {record}
        };
        try
        {
            interfaces.ManagementResourceRecord.add_cname(viewZones, recordseqseq);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }

    Now in all reality, this code will NOT work as it is because you need to have FQDNs for both the cname and the domain_name field. Funny thing also is that the catch does not catch the error... It does catch exceptions on some configurations but if you have a domain name only and a cname only, it will not catch the exception.

     

    I am creating a custom REST API to automate some of the tasks that need to be done so I should be able to take care of error handling via Model Validation.

     

    Thanks for all the help!

     

    Tony