public static String getVMIP ( String hostIpPort , String id ) throws TargetException { //TODO Expecting more interoperable implem... /compute/urn:uuid:ID for Scalair, /ID for CA ! if ( ! hostIpPort . endsWith ( "/compute" ) && id . startsWith ( "urn:uuid:" ) ) id = id . substring ( 9 ) ; String vmIp = null ; URL url = null ; try { CookieHandler . setDefault ( new CookieManager ( null , CookiePolicy . ACCEPT_ALL ) ) ; url = new URL ( "http://" + hostIpPort + "/" + id ) ; } catch ( MalformedURLException e ) { throw new TargetException ( e ) ; } HttpURLConnection httpURLConnection = null ; DataInputStream in = null ; try { httpURLConnection = ( HttpURLConnection ) url . openConnection ( ) ; httpURLConnection . setRequestMethod ( "GET" ) ; httpURLConnection . setRequestProperty ( "Accept" , "application/json" ) ; in = new DataInputStream ( httpURLConnection . getInputStream ( ) ) ; ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; Utils . copyStreamSafely ( in , out ) ; // Parse JSON response to extract VM IP ObjectMapper objectMapper = new ObjectMapper ( ) ; JsonResponse rsp = objectMapper . readValue ( out . toString ( "UTF-8" ) , JsonResponse . class ) ; vmIp = rsp . getHostsystemname ( ) ; if ( Utils . isEmptyOrWhitespaces ( vmIp ) ) vmIp = rsp . getHostname ( ) ; if ( Utils . isEmptyOrWhitespaces ( vmIp ) && rsp . getAttributes ( ) != null ) vmIp = rsp . getAttributes ( ) . getHostname ( ) ; } catch ( IOException e ) { throw new TargetException ( e ) ; } finally { Utils . closeQuietly ( in ) ; if ( httpURLConnection != null ) { httpURLConnection . disconnect ( ) ; } } return vmIp ; }
Retrieves VM IP .