Search in sources :

Example 1 with DirectImageStore

use of org.platformlayer.ops.images.direct.DirectImageStore in project platformlayer by platformlayer.

the class ImageStoreController method getImageStore.

@Override
public org.platformlayer.ops.images.ImageStore getImageStore() throws OpsException {
    String endpoint = model.getTags().findUnique("endpoint");
    if (endpoint == null) {
        log.warn("ImageStore not yet active: " + model);
        return null;
    }
    URI url;
    try {
        url = new URI(endpoint);
    } catch (URISyntaxException e) {
        throw new OpsException("Cannot parse endpoint: " + endpoint, e);
    }
    if (url.getScheme().equals("ssh")) {
        String myAddress = url.getHost();
        Machine machine = new OpaqueMachine(NetworkPoint.forPublicHostname(myAddress));
        // This is nasty; we're in the context of another service here...
        SshKey sshKey = sshKeys.findOtherServiceKey(new ServiceType("imagestore"));
        OpsTarget target = machine.getTarget("imagestore", sshKey.getKeyPair());
        DirectImageStore directImageStore = OpsContext.get().getInjector().getInstance(DirectImageStore.class);
        directImageStore.connect(target);
        return directImageStore;
    } else {
        throw new OpsException("Unknown protocol for endpoint: " + endpoint);
    }
}
Also used : SshKey(org.platformlayer.ops.helpers.SshKey) OpsException(org.platformlayer.ops.OpsException) OpsTarget(org.platformlayer.ops.OpsTarget) ServiceType(org.platformlayer.ids.ServiceType) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Machine(org.platformlayer.ops.Machine) OpaqueMachine(org.platformlayer.ops.OpaqueMachine) DirectImageStore(org.platformlayer.ops.images.direct.DirectImageStore)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ServiceType (org.platformlayer.ids.ServiceType)1 Machine (org.platformlayer.ops.Machine)1 OpaqueMachine (org.platformlayer.ops.OpaqueMachine)1 OpsException (org.platformlayer.ops.OpsException)1 OpsTarget (org.platformlayer.ops.OpsTarget)1 SshKey (org.platformlayer.ops.helpers.SshKey)1 DirectImageStore (org.platformlayer.ops.images.direct.DirectImageStore)1