private @Nonnull List<MachineImage> listIsos(@Nullable ImageFilterOptions options) throws CloudException, InternalException {
        APITrace.begin(getProvider(), "Image.listIsos");
        try {
            final CSMethod method = new CSMethod(getProvider());
            final String accountNumber = (options == null ? null : options.getAccountNumber());
            final List<Param> params = new ArrayList<Param>();
            params.add(new Param("zoneId", getContext().getRegionId()));
            params.add(new Param("bootable", "true"));
            params.add(new Param("pagesize", "500"));
            final Param pageParam = new Param("page", "1");
            params.add(pageParam);

            if( accountNumber == null || getProvider().getServiceProvider().equals(CSServiceProvider.DATAPIPE) ) {
                params.add(new Param("isoFilter", "selfexecutable"));
            }
            else {
                params.add(new Param("isoFilter", "executable"));
            }

            Document doc = method.get(LIST_ISOS, params);

            final List<MachineImage> templates = new ArrayList<MachineImage>();

            int numPages = 1;
            NodeList nodes = doc.getElementsByTagName("count");
            Node n = nodes.item(0);
            if (n != null) {
                String value = n.getFirstChild().getNodeValue().trim();
                int count = Integer.parseInt(value);
                numPages = count/500;
                int remainder = count % 500;
                if (remainder > 0) {
                    numPages++;
                }
            }

            for (int page = 1; page <= numPages; page++) {
                if (page > 1) {
                    String nextPage = String.valueOf(page);
                    pageParam.setValue(nextPage);
                    doc = method.get(LIST_ISOS, params);
                }
                NodeList matches = doc.getElementsByTagName("iso");

                for( int i=0; i<matches.getLength(); i++ ) {
                    MachineImage image = toImage(matches.item(i), false, getProvider().getZoneHypervisors(getContext().getRegionId()));


                    if( image != null && (options == null || options.matches(image)) ) {
                        image.setTag("isISO", "true");
                        templates.add(image);
                    }
                }
            }

            return templates;
        }
        finally {
            APITrace.end();
        }
    }
private @ Nonnull List < MachineImage > listIsos ( @ Nullable ImageFilterOptions options ) throws CloudException , InternalException { APITrace . begin ( getProvider ( ) , "Image.listIsos" ) ; try { final CSMethod method = new CSMethod ( getProvider ( ) ) ; final String accountNumber = ( options == null ? null : options . getAccountNumber ( ) ) ; final List < Param > params = new ArrayList < Param > ( ) ; params . add ( new Param ( "zoneId" , getContext ( ) . getRegionId ( ) ) ) ; params . add ( new Param ( "bootable" , "true" ) ) ; params . add ( new Param ( "pagesize" , "500" ) ) ; final Param pageParam = new Param ( "page" , "1" ) ; params . add ( pageParam ) ; if ( accountNumber == null || getProvider ( ) . getServiceProvider ( ) . equals ( CSServiceProvider . DATAPIPE ) ) { params . add ( new Param ( "isoFilter" , "selfexecutable" ) ) ; } else { params . add ( new Param ( "isoFilter" , "executable" ) ) ; } Document doc = method . get ( LIST_ISOS , params ) ; final List < MachineImage > templates = new ArrayList < MachineImage > ( ) ; int numPages = 1 ; NodeList nodes = doc . getElementsByTagName ( "count" ) ; Node n = nodes . item ( 0 ) ; if ( n != null ) { String value = n . getFirstChild ( ) . getNodeValue ( ) . trim ( ) ; int count = Integer . parseInt ( value ) ; numPages = count / 500 ; int remainder = count % 500 ; if ( remainder > 0 ) { numPages ++ ; } } for ( int page = 1 ; page <= numPages ; page ++ ) { if ( page > 1 ) { String nextPage = String . valueOf ( page ) ; pageParam . setValue ( nextPage ) ; doc = method . get ( LIST_ISOS , params ) ; } NodeList matches = doc . getElementsByTagName ( "iso" ) ; for ( int i = 0 ; i < matches . getLength ( ) ; i ++ ) { MachineImage image = toImage ( matches . item ( i ) , false , getProvider ( ) . getZoneHypervisors ( getContext ( ) . getRegionId ( ) ) ) ; if ( image != null && ( options == null || options . matches ( image ) ) ) { image . setTag ( "isISO" , "true" ) ; templates . add ( image ) ; } } } return templates ; } finally { APITrace . end ( ) ; } }
TODO: refactor to use listImages, as the code is a copy-paste with minor changes.