This repository was archived by the owner on Mar 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Quick Start
dols edited this page Aug 11, 2012
·
6 revisions
Note that Chef support is not complete
- Setup a Chef Server or Register for Opscode Hosted Chef
- Register for the Opscode Hosted Chef
- confirm your email entitled Please validate your Opscode user account
- Create an api client and save the private key
- On Opscode Hosted Chef
- create client
- save the private key to ~/.chef/CLIENT_NAME.pem
- On Opscode Hosted Chef
- Ensure you are using a recent JDK 6
- clone and build jclouds chef locally
- Setup your project to include jclouds-chef
Setup your ant build.xml to obtain a classpath ref to jclouds-chef
<project name="your_project" default="your_target" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<artifact:dependencies pathId="jclouds-chef.classpath">
<dependency groupId="org.jclouds" artifactId="jclouds-chef" version="1.0-SNAPSHOT" />
</artifact:dependencies>
Setup your Maven pom to include jclouds-chef
<dependencies>
<dependency>
<groupId>org.jclouds.api</groupId>
<artifactId>chef</artifactId>
<version>1.5.0-beta.9</version>
</dependency>
</dependencies>
Setup your project.clj jclouds-chef
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[org.jclouds/jclouds-chef "1.0-SNAPSHOT"]]
- Start coding
String client = "CLIENT_NAME";
String pemFile = System.getProperty("user.home") + "/.chef/" + client + ".pem";
String credential = Files.toString(new File(keyfile), Charsets.UTF_8);
// specify the chef server you want, or opscode hosted chef
Properties overrides = new Properties();
// default is localhost:4000
overrides.setProperty("chef.endpoint", "https://api.opscode.com/organizations/YOUR_ORG");
// create a context where you can access the chef client, asyncClient, and service features
ChefContext context = new ChefContextFactory().createContext(client, credential,
ImmutableSet.<Module> of(), overrides);
// The raw api has access to all chef features as exposed in the Chef REST api
Set<String> databags = context.getApi().listDatabags();
// ChefService has helpers for common commands
context.getChefService().createNodeAndPopulateAutomaticAttributes(nodeName, ImmutableSet.of("role[prod]"));
// release resources
context.close();
(ns chef.example
(:use org.jclouds.chef))
(def client "CLIENT_NAME")
;; load the rsa key from ~/.chef/CLIENT_NAME.pem
(def credential (load-pem client))
;; define a chef service you can use directly or within the with-chef-service closure
;; note that the default :chef.endpoint is localhost:8000
(def chef (chef-service "chef" client credential :chef.endpoint "https://api.opscode.com/organizations/YOUR_ORG"))
(with-chef-service [chef]
(create-databag "cluster-config")
(update-databag-item "cluster-config" {:id "master" :name "myhost.com"}))
;; note that you can create your chef connection like this to do in-memory testing
(def chef (chef-service "transientchef" "" ""))
;; note you can also pass in chef.endpoint as a system property if you are using only one chef org/server
- Validate on the Console