Sample Script for IP Range Management API

package com.hp.ucmdb.api.client.util;

import com.hp.ucmdb.api.UcmdbService;
import com.hp.ucmdb.api.UcmdbServiceFactory;
import com.hp.ucmdb.api.UcmdbServiceProvider;
import com.hp.ucmdb.api.client.types.IPRangeImpl;
import com.hp.ucmdb.api.client.types.IPRangeWithExcludingImpl;
import com.hp.ucmdb.api.discovery.types.IPRange;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by dingmen on 8/12/2015.
 */
public class UpdateIpRangeTest {

    private static final String HOST_NAME = "16.187.189.134";
    private static final int HTTP_PORT = 8080;
    private static final String HTTPS = "https";
    private static final String HTTP = "http";
    private static UcmdbService ucmdbService;

    public static void main(String[] args) {
        testSenario1();
    }

    private static  void  testSenario1(){
        try {
            UcmdbServiceProvider provider = UcmdbServiceFactory.getServiceProvider(HTTP, HOST_NAME, HTTP_PORT);
            ucmdbService = provider.connect(provider.createCredentials("admin", "admin"), provider.createClientContext("Test"));
            HashMap<String, ArrayList<String>> probeLBGroup = new HashMap<String, ArrayList<String>>();
            HashMap<String, ArrayList<IPRange>> IPRangeGroup = new HashMap<String, ArrayList<IPRange>>();
            HashMap<String, ArrayList<String>> domainGroup = new HashMap<String, ArrayList<String>>();

            //put domain name as key in domainGroup,  and its value is a list of groups.  'DefaultDomain' is a existing name in UCMDB .
            domainGroup.put("DefaultDomain", new ArrayList<String>());
            domainGroup.get("DefaultDomain").add("PG1");

            //define 'PG1' as the first group name(The group name can be any other values) in probeLBGroup ,
            //and its value is a list of probe name. 'Probe1' or 'Probe2' should be existing name in UCMDB .
            probeLBGroup.put("PG1", new ArrayList<String>());
            probeLBGroup.get("PG1").add("Probe1");
            probeLBGroup.get("PG1").add("Probe2");

            //Below all ranges are defined in IPRangeGroup for 'PG1' , and they will balanced distributed to probes in 'PG1'.
            IPRangeGroup.put("PG1", new ArrayList<IPRange>());
            //should specify ip type 'IPV4/IPV6' , and ip category 'DataCenter/Client' for each range.
            IPRangeGroup.get("PG1").add(new IPRangeWithExcludingImpl("1.1.1.1", "1.1.1.9", IPRange.IPType.IPV4, IPRange.RangeCategory.CLIENT, new ArrayList<IPRangeImpl>()));
            List<IPRangeImpl> excludedRange1=new ArrayList<IPRangeImpl>();
            IPRangeGroup.get("PG1").add(new IPRangeWithExcludingImpl("1.1.1.10", "1.1.1.19", IPRange.IPType.IPV4,IPRange.RangeCategory.DATA_CENTER, excludedRange1));
            excludedRange1.add(new IPRangeImpl("1.1.1.10","1.1.1.19",IPRange.IPType.IPV4,IPRange.RangeCategory.DATA_CENTER));
            excludedRange1.add(new IPRangeImpl("1.1.1.12","1.1.1.15",IPRange.IPType.IPV4,IPRange.RangeCategory.DATA_CENTER));
            IPRangeGroup.get("PG1").add(new IPRangeWithExcludingImpl("fe80:0:0:0:41f8:4318:2000:80", "fe80:0:0:0:41f8:4318:2000:83", IPRange.IPType.IPV6,IPRange.RangeCategory.CLIENT, new ArrayList<IPRangeImpl>()));

            //below is the second group 'PG2', and assign below 'GP2' range(1.1.1.20~1.1.1.30)  to below 'PG2' probe(Probe3) .
            domainGroup.get("DefaultDomain").add("PG2");
            probeLBGroup.put("PG2", new ArrayList<String>());
            probeLBGroup.get("PG2").add("Probe3");
            IPRangeGroup.put("PG2", new ArrayList<IPRange>());
            IPRangeGroup.get("PG2").add(new IPRangeWithExcludingImpl("1.1.1.20", "1.1.1.30", IPRange.IPType.IPV4,IPRange.RangeCategory.DATA_CENTER, new ArrayList<IPRangeImpl>()));

            //the domain group with probe and range group in set to importIPRanges API to update ip ranges.
            ucmdbService.getDDMConfigurationService().importIPRanges(probeLBGroup, IPRangeGroup, domainGroup);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

}