Java Code Examples for org.jclouds.compute.domain.NodeMetadata#getImageId()

The following examples show how to use org.jclouds.compute.domain.NodeMetadata#getImageId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JcloudsSshMachineLocation.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void setNode(NodeMetadata node) {
    this.node = null;
    config().removeKey("node");
    nodeId = node.getId();
    imageId = node.getImageId();
    publicAddresses = node.getPublicAddresses();
    _node = Optional.of(node);

    Boolean useMachinePublicAddressAsPrivateAddress = config().get(USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS);
    if(useMachinePublicAddressAsPrivateAddress) {
        LOG.debug("Overriding private address ["+node.getPrivateAddresses()+"] as public address ["+node.getPublicAddresses()+"] as config "+ USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS +" is set to true");
        privateAddresses = node.getPublicAddresses();
    } else {
        privateAddresses = node.getPrivateAddresses();
    }
}
 
Example 2
Source File: JcloudsWinRmMachineLocation.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void setNode(NodeMetadata node) {
    this.node = null;
    nodeId = node.getId();
    imageId = node.getImageId();
    privateAddresses = node.getPrivateAddresses();
    publicAddresses = node.getPublicAddresses();
    hostname = node.getHostname();
    _node = Optional.of(node);
}
 
Example 3
Source File: CloudDistributedTLCJob.java    From tlaplus with MIT License 4 votes vote down vote up
public WrapperNodeMetadata(final NodeMetadata m, final LoginCredentials credentials) {
	super(m.getProviderId(), m.getName(), m.getId(), m.getLocation(), m.getUri(), m.getUserMetadata(),
			m.getTags(), m.getGroup(), m.getHardware(), m.getImageId(), m.getOperatingSystem(), m.getStatus(),
			m.getBackendStatus(), m.getLoginPort(), m.getPublicAddresses(), m.getPrivateAddresses(),
			credentials, m.getHostname());
}
 
Example 4
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/**
 * Create the user immediately - executing ssh commands as required.
 */
protected LoginCredentials createUser(
        ComputeService computeService, NodeMetadata node, HostAndPort managementHostAndPort,
        LoginCredentials initialCredentials, ConfigBag config) {
    Image image = (node.getImageId() != null) ? computeService.getImage(node.getImageId()) : null;
    CreateUserStatements userCreation = createUserStatements(image, config);

    if (!userCreation.statements().isEmpty()) {
        // If unsure of OS family, default to unix for rendering statements.
        org.jclouds.scriptbuilder.domain.OsFamily scriptOsFamily;
        if (isWindows(node, config)) {
            scriptOsFamily = org.jclouds.scriptbuilder.domain.OsFamily.WINDOWS;
        } else {
            scriptOsFamily = org.jclouds.scriptbuilder.domain.OsFamily.UNIX;
        }

        boolean windows = isWindows(node, config);

        if (windows) {
            LOG.warn("Unable to execute statements on WinRM in JcloudsLocation; skipping for "+node+": "+userCreation.statements());
        } else {
            List<String> commands = Lists.newArrayList();
            for (Statement statement : userCreation.statements()) {
                InitAdminAccess initAdminAccess = new InitAdminAccess(new AdminAccessConfiguration.Default());
                initAdminAccess.visit(statement);
                commands.add(statement.render(scriptOsFamily));
            }

            String initialUser = initialCredentials.getUser();
            boolean authSudo = initialCredentials.shouldAuthenticateSudo();
            Optional<String> password = initialCredentials.getOptionalPassword();
            
            // TODO Retrying lots of times as workaround for vcloud-director. There the guest customizations
            // can cause the VM to reboot shortly after it was ssh'able.
            Map<String,Object> execProps = MutableMap.<String, Object>builder()
                    .put(ShellTool.PROP_RUN_AS_ROOT.getName(), true)
                    .put(SshTool.PROP_AUTH_SUDO.getName(), authSudo)
                    .put(SshTool.PROP_ALLOCATE_PTY.getName(), true)
                    .putIfNotNull(SshTool.PROP_PASSWORD.getName(), authSudo ? password.orNull() : null)
                    .put(SshTool.PROP_SSH_TRIES.getName(), 50)
            .put(SshTool.PROP_SSH_TRIES_TIMEOUT.getName(), 10*60*1000)
            .build();

            if (LOG.isDebugEnabled()) {
                LOG.debug("VM {}: executing user creation/setup via {}@{}; commands: {}", new Object[] {
                        getCreationString(config), initialUser, managementHostAndPort, commands});
            }

            SshMachineLocation sshLoc = createTemporarySshMachineLocation(managementHostAndPort, initialCredentials, config);
            try {
                // BROOKLYN-188: for SUSE, need to specify the path (for groupadd, useradd, etc)
                Map<String, ?> env = ImmutableMap.of("PATH", sbinPath());

                int exitcode = sshLoc.execScript(execProps, "create-user", commands, env);

                if (exitcode != 0) {
                    LOG.warn("exit code {} when creating user for {}; usage may subsequently fail", exitcode, node);
                }
            } finally {
                if (getManagementContext().getLocationManager().isManaged(sshLoc)) {
                    getManagementContext().getLocationManager().unmanage(sshLoc);
                }
                Streams.closeQuietly(sshLoc);
            }
        }
    }

    return userCreation.credentials();
}