@Override public NodeMetadata getNode(String id) { NodeMetadata node = nodes.get(id); return node == null ? null : NodeMetadataBuilder.fromNodeMetadata(node) .credentials(credentialStore.get("node#" + node.getId())) .build(); }
public void refreshSshIfNewAdminCredentialsConfigured(AdminAccess input) { if (input.getAdminCredentials() != null && input.shouldGrantSudoToAdminUser()) { ssh.disconnect(); logger.debug( ">> reconnecting as %s@%s", input.getAdminCredentials().identity, ssh.getHostAddress()); ssh = sshFactory.apply( node = NodeMetadataBuilder.fromNodeMetadata(node) .adminPassword(null) .credentials(input.getAdminCredentials()) .build()); ssh.connect(); setupLinkToInitFile(); } }
@Override public String associatePredefinedAddress(NodeMetadata node, String ip) { if (log.isDebugEnabled()) { log.debug( String.format( "Trying to associate predefined IP address: [node-id] %s [ip] %s", node.getId(), ip)); } ComputeServiceContext context = iaasProvider.getComputeService().getContext(); String region = ComputeServiceBuilderUtil.extractRegion(iaasProvider); FloatingIPApi floatingIPApi = context.unwrapApi(NovaApi.class).getFloatingIPExtensionForZone(region).get(); // get the list of all unassigned IP. ArrayList<FloatingIP> unassignedFloatingIPs = Lists.newArrayList( Iterables.filter( floatingIPApi.list(), new Predicate<FloatingIP>() { @Override public boolean apply(FloatingIP floatingIP) { return StringUtils.isEmpty(floatingIP.getFixedIp()); } })); boolean isAvailable = false; for (FloatingIP floatingIP : unassignedFloatingIPs) { if (log.isDebugEnabled()) { log.debug( "OpenstackNovaIaas:associatePredefinedAddress:iterating over available floatingip:" + floatingIP); } if (ip.equals(floatingIP.getIp())) { if (log.isDebugEnabled()) { log.debug( String.format( "OpenstackNovaIaas:associatePredefinedAddress:floating ip in use:%s /ip:%s", floatingIP, ip)); } isAvailable = true; break; } } if (isAvailable) { // assign ip if (log.isDebugEnabled()) { log.debug("OpenstackNovaIaas:associatePredefinedAddress:assign floating ip:" + ip); } // exercise same code as in associateAddress() // wait till the fixed IP address gets assigned - this is needed before // we associate a public IP while (node.getPrivateAddresses() == null) { CloudControllerUtil.sleep(1000); } int retries = 0; int retryCount = Integer.getInteger("stratos.public.ip.association.retry.count", 5); while (retries < retryCount && !associateIp(floatingIPApi, ip, node.getProviderId())) { // wait for 5s CloudControllerUtil.sleep(5000); retries++; } NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of(ip)).build(); log.info( String.format( "Successfully associated predefined IP address: [node-id] %s [ip] %s ", node.getId(), ip)); return ip; } else { log.warn( String.format( "Could not associate predefined IP address: [node-id] %s [ip] %s ", node.getId(), ip)); return null; } }