Package org.platformlayer.ops

Source Code of org.platformlayer.ops.CloudContextRegistry

package org.platformlayer.ops;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.KeyPair;

import javax.inject.Inject;

import org.platformlayer.ops.machines.PlatformLayerCloudContext;
import org.platformlayer.ops.ssh.AcceptAllLearningServerKeyVerifier;
import org.platformlayer.ops.ssh.IServerKeyVerifier;
import org.platformlayer.ops.ssh.ISshContext;
import org.platformlayer.ops.ssh.SshConnection;

public class CloudContextRegistry {
  @Inject
  OpsSystem ops;

  public CloudContext getCloudContext() throws OpsException {
    // OpsConfig config = userInfo.getConfig();
    //
    // String type = config.getString("compute.type", "platformlayer");
    // // if (type.equals("openstack")) {
    // // // OpenstackCloudContext currently is stateless (probably shouldn't be!!)
    // // return ops.getInjector().getInstance(OpenstackCloudContext.class);
    // // }
    // if (type.equals("platformlayer")) {
    return ops.getInjector().getInstance(PlatformLayerCloudContext.class);
    // }
    // throw new OpsException("Unknown compute.type value: " + type);
  }

  private SshConnection getSshConnection(String host, String user, KeyPair sshKeyPair) throws OpsException {
    OpsSystem opsSystem = OpsContext.get().getOpsSystem();
    ISshContext sshContext = opsSystem.getSshContext();

    SshConnection sshConnection = sshContext.getSshConnection(user);
    try {
      sshConnection.setHost(InetAddress.getByName(host));
    } catch (UnknownHostException e) {
      throw new OpsException("Error resolving address: " + host, e);
    }

    sshConnection.setKeyPair(sshKeyPair);

    // TODO: Verify the server key once we've learned it
    IServerKeyVerifier serverKeyVerifier = new AcceptAllLearningServerKeyVerifier();
    sshConnection.setServerKeyVerifier(serverKeyVerifier);

    return sshConnection;
  }
}
TOP

Related Classes of org.platformlayer.ops.CloudContextRegistry

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.