public AgentProperties findParametersForVmware ( Logger logger ) { logger . info ( "User data are being retrieved for VMWare..." ) ; AgentProperties result = null ; File propertiesFile = new File ( "/tmp/roboconf.properties" ) ; try { int retries = 30 ; while ( ( ! propertiesFile . exists ( ) || ! propertiesFile . canRead ( ) ) && retries -- > 0 ) { logger . fine ( "Agent tries to read properties file " + propertiesFile + ": trial #" + ( 30 - retries ) ) ; try { Thread . sleep ( 2000 ) ; } catch ( InterruptedException e ) { throw new IOException ( "Cannot read properties file: " + e ) ; } } result = AgentProperties . readIaasProperties ( Utils . readPropertiesFile ( propertiesFile ) ) ; /* * HACK for specific IaaS configurations (using properties file in a VMWare-like manner) * Try to pick IP address... in the case we are on OpenStack or any IaaS with amazon-compatible API * Some configurations (with floating IPs) do not provide network interfaces exposing public IPs ! */ InputStream in = null ; try { URL userDataUrl = new URL ( "http://169.254.169.254/latest/meta-data/public-ipv4" ) ; in = userDataUrl . openStream ( ) ; ByteArrayOutputStream os = new ByteArrayOutputStream ( ) ; Utils . copyStreamSafely ( in , os ) ; String ip = os . toString ( "UTF-8" ) ; if ( ! AgentUtils . isValidIP ( ip ) ) { // Failed retrieving public IP: try private one instead Utils . closeQuietly ( in ) ; userDataUrl = new URL ( "http://169.254.169.254/latest/meta-data/local-ipv4" ) ; in = userDataUrl . openStream ( ) ; os = new ByteArrayOutputStream ( ) ; Utils . copyStreamSafely ( in , os ) ; ip = os . toString ( "UTF-8" ) ; } if ( AgentUtils . isValidIP ( ip ) ) result . setIpAddress ( os . toString ( "UTF-8" ) ) ; } catch ( IOException e ) { Utils . logException ( logger , e ) ; } finally { Utils . closeQuietly ( in ) ; } /* HACK ends here (see comment above). Removing it is harmless on classical VMWare configurations. */ } catch ( IOException e ) { logger . fine ( "Agent failed to read properties file " + propertiesFile ) ; result = null ; } return result ; }
Configures the agent from VMWare .