Skip to content

Instantly share code, notes, and snippets.

@zack-shoylev
zack-shoylev / gist:5579710
Created May 14, 2013 21:28
Sample jclouds maven pom file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>rackspace</groupId>
<artifactId>rackspace</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
@zack-shoylev
zack-shoylev / gist:6238185
Created August 15, 2013 04:06
JCloudsNova.java example for devstack
package org.jclouds.examples.rackspace;
import static com.google.common.io.Closeables.closeQuietly;
import java.io.Closeable;
import java.util.Set;
import org.jclouds.ContextBuilder;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
@zack-shoylev
zack-shoylev / pom.xml
Last active December 22, 2015 18:59
Download jclouds dependencies
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
@zack-shoylev
zack-shoylev / logback.xml
Created September 10, 2013 23:32
jclouds logging xml example
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
@zack-shoylev
zack-shoylev / JCloudsWorkshop.java
Last active December 22, 2015 19:09
Full code for JCloudsWorkshop.java
package org.jclouds.workshop;
import static com.google.common.base.Charsets.UTF_8;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.jclouds.compute.predicates.NodePredicates.inGroup;
import static org.jclouds.scriptbuilder.domain.Statements.exec;
import static org.jclouds.util.Predicates2.retry;
import java.io.BufferedReader;
import java.io.Closeable;
@zack-shoylev
zack-shoylev / JCloudsWorkshop.java
Last active December 22, 2015 19:09
Skeleton for JCloudsWorkshop.java
package org.jclouds.workshop;
import static com.google.common.base.Charsets.UTF_8;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.jclouds.compute.predicates.NodePredicates.inGroup;
import static org.jclouds.scriptbuilder.domain.Statements.exec;
import static org.jclouds.util.Predicates2.retry;
import java.io.BufferedReader;
import java.io.Closeable;
@zack-shoylev
zack-shoylev / init.java
Last active December 22, 2015 19:09
Initialize jclouds example
// Get credentials from a file, if it exists. First line should be "user;password"
if( (new File("credentials.txt")).exists() ) {
BufferedReader br = null;
try {
br = (new BufferedReader(new FileReader("credentials.txt")));
String[] credentials = br.readLine().split(";");
user = credentials[0];
password = credentials[1];
}
@zack-shoylev
zack-shoylev / createNode.java
Last active December 22, 2015 19:09
Create a compute node with jclouds
try {
// Use jclouds to generate a keypair
Map<String,String> keys = SshKeys.generate();
// Get the private key from the keypair map
privateKey = keys.get("private");
Files.write(privateKey, new File("jclouds.pem"), UTF_8);
// Uses security groups if available (determines right approach automatically) to enable SSH and HTTP
TemplateOptions options = compute.templateOptions().inboundPorts(22, 80);
@zack-shoylev
zack-shoylev / createNodeNova.java
Last active December 22, 2015 19:09
Nova-specific code for creating a node
try {
zone = nova.getApi().getConfiguredZones().iterator().next();
System.out.println("Zone: " + zone);
Map<String,String> keys = SshKeys.generate();
privateKey = keys.get("private");
Files.write(privateKey, new File("jclouds.pem"), UTF_8);
KeyPairApi kpa = nova.getApi().getKeyPairExtensionForZone(zone).get();
kpa.delete("jclouds");
kpa.createWithPublicKey("jclouds", keys.get("public"));
@zack-shoylev
zack-shoylev / shellscript
Created September 11, 2013 00:44
Make a custom Ubuntu image on devstack
wget http://uec-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64-disk1.img
glance image-create --name ubuntu --disk-format=raw --container-format=bare --file precise-server-cloudimg-amd64-disk1.img
nova boot jclouds-vm --flavor 1 --image <image id> --key-name jclouds --security-groups jclouds-workshop --poll