Search in sources :

Example 1 with SshjSshClientModule

use of org.jclouds.sshj.config.SshjSshClientModule in project legacy-jclouds-examples by jclouds.

the class MainApp method initComputeService.

private static ComputeService initComputeService(String provider, String identity, String credential) {
    // example of specific properties, in this case optimizing image list to
    // only amazon supplied
    Properties properties = new Properties();
    properties.setProperty(PROPERTY_EC2_AMI_QUERY, "owner-id=137112412989;state=available;image-type=machine");
    properties.setProperty(PROPERTY_EC2_CC_AMI_QUERY, "");
    long scriptTimeout = TimeUnit.MILLISECONDS.convert(20, TimeUnit.MINUTES);
    properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");
    // example of injecting a ssh implementation
    Iterable<Module> modules = ImmutableSet.<Module>of(new SshjSshClientModule(), new SLF4JLoggingModule(), new EnterpriseConfigurationModule());
    ContextBuilder builder = ContextBuilder.newBuilder(provider).credentials(identity, credential).modules(modules).overrides(properties);
    System.out.printf(">> initializing %s%n", builder.getApiMetadata());
    return builder.buildView(ComputeServiceContext.class).getComputeService();
}
Also used : EnterpriseConfigurationModule(org.jclouds.enterprise.config.EnterpriseConfigurationModule) SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) SshjSshClientModule(org.jclouds.sshj.config.SshjSshClientModule) ContextBuilder(org.jclouds.ContextBuilder) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) Properties(java.util.Properties) SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) Module(com.google.inject.Module) SshjSshClientModule(org.jclouds.sshj.config.SshjSshClientModule) EnterpriseConfigurationModule(org.jclouds.enterprise.config.EnterpriseConfigurationModule)

Example 2 with SshjSshClientModule

use of org.jclouds.sshj.config.SshjSshClientModule in project legacy-jclouds-examples by jclouds.

the class CreateVolumeAndAttach method init.

private void init(String[] args) {
    // The provider configures jclouds To use the Rackspace Cloud (US)
    // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudservers-uk"
    String provider = "rackspace-cloudservers-us";
    String username = args[0];
    String apiKey = args[1];
    // These properties control how often jclouds polls for a status udpate
    Properties overrides = new Properties();
    overrides.setProperty(ComputeServiceProperties.POLL_INITIAL_PERIOD, Constants.POLL_PERIOD_TWENTY_SECONDS);
    overrides.setProperty(ComputeServiceProperties.POLL_MAX_PERIOD, Constants.POLL_PERIOD_TWENTY_SECONDS);
    Iterable<Module> modules = ImmutableSet.<Module>of(new SshjSshClientModule());
    ComputeServiceContext context = ContextBuilder.newBuilder(provider).credentials(username, apiKey).modules(modules).overrides(overrides).buildView(ComputeServiceContext.class);
    compute = context.getComputeService();
    nova = context.unwrap();
    volumeAttachmentApi = nova.getApi().getVolumeAttachmentExtensionForZone(Constants.ZONE).get();
    provider = "rackspace-cloudblockstorage-us";
    cinder = ContextBuilder.newBuilder(provider).credentials(username, apiKey).modules(modules).build(CinderApiMetadata.CONTEXT_TOKEN);
    volumeApi = cinder.getApi().getVolumeApiForZone(Constants.ZONE);
}
Also used : SshjSshClientModule(org.jclouds.sshj.config.SshjSshClientModule) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) Properties(java.util.Properties) ComputeServiceProperties(org.jclouds.compute.config.ComputeServiceProperties) Module(com.google.inject.Module) SshjSshClientModule(org.jclouds.sshj.config.SshjSshClientModule)

Example 3 with SshjSshClientModule

use of org.jclouds.sshj.config.SshjSshClientModule in project legacy-jclouds-examples by jclouds.

the class DetachVolume method init.

private void init(String[] args) {
    // The provider configures jclouds To use the Rackspace Cloud (US)
    // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudservers-uk"
    String provider = "rackspace-cloudservers-us";
    String username = args[0];
    String apiKey = args[1];
    Iterable<Module> modules = ImmutableSet.<Module>of(new SshjSshClientModule());
    ComputeServiceContext context = ContextBuilder.newBuilder(provider).credentials(username, apiKey).modules(modules).buildView(ComputeServiceContext.class);
    compute = context.getComputeService();
    nova = context.unwrap();
    volumeAttachmentApi = nova.getApi().getVolumeAttachmentExtensionForZone(Constants.ZONE).get();
    serverApi = nova.getApi().getServerApiForZone(Constants.ZONE);
    provider = "rackspace-cloudblockstorage-us";
    cinder = ContextBuilder.newBuilder(provider).credentials(username, apiKey).build(CinderApiMetadata.CONTEXT_TOKEN);
    volumeApi = cinder.getApi().getVolumeApiForZone(Constants.ZONE);
}
Also used : SshjSshClientModule(org.jclouds.sshj.config.SshjSshClientModule) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) Module(com.google.inject.Module) SshjSshClientModule(org.jclouds.sshj.config.SshjSshClientModule)

Example 4 with SshjSshClientModule

use of org.jclouds.sshj.config.SshjSshClientModule in project gora by apache.

the class ChefSoftwareProvisioning method performChefComputeServiceBootstrapping.

private static void performChefComputeServiceBootstrapping(Properties properties) throws IOException, InstantiationException, IllegalAccessException {
    // Get the credentials that will be used to authenticate to the Chef server
    String rsContinent = DataStoreFactory.findProperty(properties, MemStore.class.newInstance(), RS_CONTINENT, "rackspace-cloudservers-us");
    String rsUser = DataStoreFactory.findProperty(properties, MemStore.class.newInstance(), RS_USERNAME, "asf-gora");
    String rsApiKey = DataStoreFactory.findProperty(properties, MemStore.class.newInstance(), RS_APIKEY, null);
    String rsRegion = DataStoreFactory.findProperty(properties, MemStore.class.newInstance(), RS_REGION, "DFW");
    String client = DataStoreFactory.findProperty(properties, MemStore.class.newInstance(), CHEF_CLIENT, System.getProperty("user.name"));
    String organization = DataStoreFactory.findProperty(properties, MemStore.class.newInstance(), CHEF_ORGANIZATION, null);
    String pemFile = System.getProperty("user.home") + "/.chef/" + client + ".pem";
    String credential = Files.toString(new File(pemFile), Charsets.UTF_8);
    // Provide the validator information to let the nodes to auto-register themselves
    // in the Chef server during bootstrap
    String validator = organization + "-validator";
    String validatorPemFile = System.getProperty("user.home") + "/.chef/" + validator + ".pem";
    String validatorCredential = Files.toString(new File(validatorPemFile), Charsets.UTF_8);
    Properties chefConfig = new Properties();
    chefConfig.put(ChefProperties.CHEF_VALIDATOR_NAME, validator);
    chefConfig.put(ChefProperties.CHEF_VALIDATOR_CREDENTIAL, validatorCredential);
    // Create the connection to the Chef server
    ChefContext chefContext = ContextBuilder.newBuilder("chef").endpoint("https://api.opscode.com/organizations/" + organization).credentials(client, credential).overrides(chefConfig).buildView(ChefContext.class);
    // Create the connection to the compute provider. Note that ssh will be used to bootstrap chef
    ComputeServiceContext computeContext = ContextBuilder.newBuilder(rsContinent).endpoint(rsRegion).credentials(rsUser, rsApiKey).modules(ImmutableSet.<Module>of(new SshjSshClientModule())).buildView(ComputeServiceContext.class);
    // Group all nodes in both Chef and the compute provider by this group
    String group = "jclouds-chef-goraci";
    // Set the recipe to install and the configuration values to override
    String recipe = "apache2";
    JsonBall attributes = new JsonBall("{\"apache\": {\"listen_ports\": \"8080\"}}");
    // Check to see if the recipe you want exists
    List<String> runlist = null;
    Iterable<? extends CookbookVersion> cookbookVersions = chefContext.getChefService().listCookbookVersions();
    if (any(cookbookVersions, CookbookVersionPredicates.containsRecipe(recipe))) {
        runlist = new RunListBuilder().addRecipe(recipe).build();
    }
    for (Iterator<String> iterator = runlist.iterator(); iterator.hasNext(); ) {
        String string = (String) iterator.next();
        LOG.info(string);
    }
    // Update the chef service with the run list you wish to apply to all nodes in the group
    // and also provide the json configuration used to customize the desired values
    BootstrapConfig config = BootstrapConfig.builder().runList(runlist).attributes(attributes).build();
    chefContext.getChefService().updateBootstrapConfigForGroup(group, config);
    // Build the script that will bootstrap the node
    Statement bootstrap = chefContext.getChefService().createBootstrapScriptForGroup(group);
    TemplateBuilder templateBuilder = computeContext.getComputeService().templateBuilder();
    templateBuilder.options(runScript(bootstrap));
    // Run a node on the compute provider that bootstraps chef
    try {
        Set<? extends NodeMetadata> nodes = computeContext.getComputeService().createNodesInGroup(group, 1, templateBuilder.build());
        for (NodeMetadata nodeMetadata : nodes) {
            LOG.info("<< node %s: %s%n", nodeMetadata.getId(), concat(nodeMetadata.getPrivateAddresses(), nodeMetadata.getPublicAddresses()));
        }
    } catch (RunNodesException e) {
        throw new RuntimeException(e.getMessage());
    }
    // Release resources
    chefContext.close();
    computeContext.close();
}
Also used : Statement(org.jclouds.scriptbuilder.domain.Statement) BootstrapConfig(org.jclouds.chef.domain.BootstrapConfig) TemplateBuilder(org.jclouds.compute.domain.TemplateBuilder) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) Properties(java.util.Properties) ChefProperties(org.jclouds.chef.config.ChefProperties) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) ChefContext(org.jclouds.chef.ChefContext) MemStore(org.apache.gora.memory.store.MemStore) RunNodesException(org.jclouds.compute.RunNodesException) SshjSshClientModule(org.jclouds.sshj.config.SshjSshClientModule) RunListBuilder(org.jclouds.chef.util.RunListBuilder) Module(com.google.inject.Module) SshjSshClientModule(org.jclouds.sshj.config.SshjSshClientModule) JsonBall(org.jclouds.domain.JsonBall) File(java.io.File)

Example 5 with SshjSshClientModule

use of org.jclouds.sshj.config.SshjSshClientModule in project hive by apache.

the class CloudComputeService method initComputeServiceContext.

private ComputeServiceContext initComputeServiceContext(CloudComputeConfig.CloudComputeProvider provider, String identity, String credential) {
    Properties overrides = new Properties();
    overrides.put(ComputeServiceProperties.POLL_INITIAL_PERIOD, String.valueOf(60L * 1000L));
    overrides.put(ComputeServiceProperties.POLL_MAX_PERIOD, String.valueOf(600L * 1000L));
    overrides.put(Constants.PROPERTY_MAX_RETRIES, String.valueOf(60));
    return ContextBuilder.newBuilder(provider.getmJcloudsId()).credentials(identity, credential).modules(ImmutableSet.of(new SshjSshClientModule(), new Log4JLoggingModule())).overrides(overrides).buildView(ComputeServiceContext.class);
}
Also used : SshjSshClientModule(org.jclouds.sshj.config.SshjSshClientModule) Log4JLoggingModule(org.jclouds.logging.log4j.config.Log4JLoggingModule) ComputeServiceProperties(org.jclouds.compute.config.ComputeServiceProperties)

Aggregations

SshjSshClientModule (org.jclouds.sshj.config.SshjSshClientModule)8 Module (com.google.inject.Module)7 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)7 Properties (java.util.Properties)6 ContextBuilder (org.jclouds.ContextBuilder)3 ComputeServiceProperties (org.jclouds.compute.config.ComputeServiceProperties)3 EnterpriseConfigurationModule (org.jclouds.enterprise.config.EnterpriseConfigurationModule)3 SLF4JLoggingModule (org.jclouds.logging.slf4j.config.SLF4JLoggingModule)3 ChefProperties (org.jclouds.chef.config.ChefProperties)2 File (java.io.File)1 MemStore (org.apache.gora.memory.store.MemStore)1 ChefContext (org.jclouds.chef.ChefContext)1 BootstrapConfig (org.jclouds.chef.domain.BootstrapConfig)1 RunListBuilder (org.jclouds.chef.util.RunListBuilder)1 RunNodesException (org.jclouds.compute.RunNodesException)1 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)1 TemplateBuilder (org.jclouds.compute.domain.TemplateBuilder)1 JsonBall (org.jclouds.domain.JsonBall)1 Log4JLoggingModule (org.jclouds.logging.log4j.config.Log4JLoggingModule)1 Statement (org.jclouds.scriptbuilder.domain.Statement)1