use of org.jclouds.compute.ComputeService in project fabric8 by jboss-fuse.
the class CloudFirewallEdit method findTargetComputeService.
/**
* Finds the {@link ComputeService} to use based on the provider option or the target {@link Container} metadata.
* @return
*/
private ComputeService findTargetComputeService() {
if (!Strings.isNullOrEmpty(targetContainerName) && getCurator().getZookeeperClient().isConnected()) {
CreateJCloudsContainerMetadata metadata = getContainerCloudMetadata(targetContainerName);
if (metadata != null) {
CreateJCloudsContainerOptions options = metadata.getCreateOptions();
contextName = options.getContextName();
}
}
if (!Strings.isNullOrEmpty(contextName)) {
for (ComputeService computeService : computeServices) {
if (computeService.getContext().unwrap().getName().equals(contextName)) {
return computeService;
}
}
}
if (computeServices == null || computeServices.size() == 0) {
System.out.println("No compute services are available.");
return null;
} else if (computeServices != null && computeServices.size() == 0) {
return computeServices.get(0);
} else {
System.out.println("Multiple cloud provider service available. Please select one using the --provider option.");
return null;
}
}
use of org.jclouds.compute.ComputeService in project fabric8 by jboss-fuse.
the class ToTemplate method apply.
public static Template apply(CreateJCloudsContainerOptions options) {
ComputeService service = options.getComputeService();
TemplateOptions templateOptions = service.templateOptions();
TemplateBuilder builder = service.templateBuilder().any();
applyInstanceType(builder, options);
applyImageType(builder, options);
applyLocation(builder, options);
applyProviderSpecificOptions(templateOptions, options);
Optional<AdminAccess> adminAccess = ToAdminAccess.apply(options);
if (adminAccess.isPresent()) {
templateOptions.runScript(adminAccess.get());
}
builder = builder.options(templateOptions);
return builder.build();
}
use of org.jclouds.compute.ComputeService in project fabric8 by jboss-fuse.
the class CloudUtils method waitForComputeService.
/**
* Returns the compute service when it becomes registered to the OSGi service registry.
*
* @param name
* @return
*/
public static synchronized ComputeService waitForComputeService(BundleContext bundleContext, String name) {
ComputeService computeService = null;
try {
for (int r = 0; r < 6; r++) {
ServiceReference[] references = bundleContext.getAllServiceReferences(ComputeService.class.getName(), "(" + Constants.NAME + "=" + name + ")");
if (references != null && references.length > 0) {
computeService = (ComputeService) bundleContext.getService(references[0]);
return computeService;
}
Thread.sleep(10000L);
}
} catch (Exception e) {
LOGGER.error("Error while waiting for service.", e);
}
return computeService;
}
use of org.jclouds.compute.ComputeService in project fabric8 by jboss-fuse.
the class ComputeRegistryImpl method list.
@Override
public List<ComputeService> list() {
assertValid();
List<ComputeService> list = new ArrayList<ComputeService>();
for (Map.Entry<String, DynamicReference<ComputeService>> entry : computeServices.entrySet()) {
ComputeService computeService = entry.getValue().getIfPresent();
if (computeService != null) {
list.add(computeService);
}
}
return list;
}
use of org.jclouds.compute.ComputeService in project iobserve-analysis by research-iobserve.
the class AbstractActionScript method getComputeServiceForContainer.
/**
* Returns a compute service client to use for further queries to the cloud provider.
*
* @param container
* the resource container for which to get the compute service
* @return the corresponding compute service
*/
protected ComputeService getComputeServiceForContainer(final ResourceContainerCloud container) {
final CloudProvider provider = container.getInstanceType().getProvider();
final ComputeServiceContext context = ContextBuilder.newBuilder(provider.getName()).credentials(provider.getIdentity(), provider.getCredential()).modules(// NOCS
ImmutableSet.<Module>of(new SLF4JLoggingModule(), new SshjSshClientModule())).buildView(ComputeServiceContext.class);
final ComputeService client = context.getComputeService();
return client;
}
Aggregations