Skip to content

Commit

Permalink
Merge pull request #143 from opscode/adamed-open-source
Browse files Browse the repository at this point in the history
KNIFE-345: KNIFE-346: ReadMe and test deprecation cleanup contributions
  • Loading branch information
Adam Edwards committed Aug 23, 2013
2 parents 9f20ce4 + e04cac0 commit c23c1f1
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 142 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ Icon?
*.swo

Gemfile.lock
.rspec
2 changes: 0 additions & 2 deletions .rspec

This file was deleted.

3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rvm:
- 1.9.3
script: bundle exec rspec --color
- 2.0.0
script: bundle exec rspec --color --format progress
9 changes: 0 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
source 'http://rubygems.org'
gemspec

group :development do
gem 'rspec', '~> 2.7'
end

group :test do
gem 'rake', '~> 10.1'
gem 'sdoc', '~> 0.3'
end
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
Knife EC2
=========
[![Gem Version](https://badge.fury.io/rb/knife-ec2.png)](http://badge.fury.io/rb/knife-ec2)
[![Build Status](https://travis-ci.org/opscode/knife-ec2.png?branch=master)](https://travis-ci.org/opscode/knife-ec2)
[![Dependency Status](https://gemnasium.com/opscode/knife-ec2.png)](https://gemnasium.com/opscode/knife-ec2)

This is the official Opscode Knife plugin for EC2. This plugin gives knife the ability to create, bootstrap, and manage EC2 instances.


Installation
------------
If you're using bundler, simply add Chef and Knife EC2 to your `Gemfile`:

```ruby
gem 'chef'
gem 'knife-ec2'
```

If you are not using bundler, you can install the gem manually. Be sure you are running Chef 0.10.10 or higher, as earlier versions do not support plugins.

$ gem install chef

This plugin is distributed as a Ruby Gem. To install it, run:

$ gem install knife-ec2

Depending on your system's configuration, you may need to run this command with root privileges.


Configuration
-------------
In order to communicate with the Amazon's EC2 API you will have to tell Knife about your AWS Access Key and Secret Access Key. The easiest way to accomplish this is to create some entries in your `knife.rb` file:

```ruby
knife[:aws_access_key_id] = "Your AWS Access Key ID"
knife[:aws_secret_access_key] = "Your AWS Secret Access Key"
```

If your `knife.rb` file will be checked into a SCM system (ie readable by others) you may want to read the values from environment variables:

```ruby
knife[:aws_access_key_id] = ENV['AWS_ACCESS_KEY_ID']
knife[:aws_secret_access_key] = ENV['AWS_SECRET_ACCESS_KEY']
```

You also have the option of passing your AWS API Key/Secret into the individual knife subcommands using the `-A` (or `--aws-access-key-id`) `-K` (or `--aws-secret-access-key`) command options

```bash
# provision a new m1.small Ubuntu 10.04 webserver
$ knife ec2 server create -r 'role[webserver]' -I ami-7000f019 -f m1.small -A 'Your AWS Access Key ID' -K "Your AWS Secret Access Key"
```

Additionally the following options may be set in your `knife.rb`:

- flavor
- image
- availability_zone
- aws_ssh_key_id
- region
- distro
- template_file


Subcommands
-----------
This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a `--help` flag


#### `knife ec2 server create`
Provisions a new server in the Amazon EC2 and then perform a Chef bootstrap (using the SSH protocol). The goal of the bootstrap is to get Chef installed on the target system so it can run Chef Client with a Chef Server. The main assumption is a baseline OS installation exists (provided by the provisioning). It is primarily intended for Chef Client systems that talk to a Chef server.

#### `knife ec2 server delete`
Deletes an existing server in the currently configured AWS account. **By default, this does not delete the associated node and client objects from the Chef server. To do so, add the `--purge` flag**

#### `knife ec2 server list`
Outputs a list of all servers in the currently configured AWS account. **Note, this shows all instances associated with the account, some of which may not be currently managed by the Chef server.**

#### `knife ec2 instance data`
Generates instance metadata in meant to be used with Opscode's custom AMIs. This will read your knife configuration `~/.chef/knife.rb` for the validation certificate and Chef server URL to use and output in JSON format. The subcommand also accepts a list of roles/recipes that will be in the node's initial run list.

**Note**: Using Opscode's custom AMIs reflect an older way of launching instances in EC2 for Chef and should be considered DEPRECATED. Leveraging this plugins's `knife ec2 server create` subcommands with a base AMIs directly from your Linux distribution (ie Ubuntu AMIs from Canonical) is much preferred and more flexible. Although this subcommand will remain, the Opscode custom AMIs are currently out of date.

In-depth usage instructions can be found on the [Chef Wiki](http://wiki.opscode.com/display/chef/EC2+Bootstrap+Fast+Start+Guide).

License and Authors
-------------------
- Author:: Adam Jacob (<[email protected]>)

```text
Copyright 2009-2013 Opscode, Inc.
Licensed 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
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
87 changes: 0 additions & 87 deletions README.rdoc

This file was deleted.

42 changes: 23 additions & 19 deletions knife-ec2.gemspec
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "knife-ec2/version"
$:.push File.expand_path('../lib', __FILE__)
require 'knife-ec2/version'

Gem::Specification.new do |s|
s.name = "knife-ec2"
s.version = Knife::Ec2::VERSION
s.has_rdoc = true
s.authors = ["Adam Jacob","Seth Chisamore"]
s.email = ["[email protected]","[email protected]"]
s.homepage = "http://wiki.opscode.com/display/chef"
s.summary = "EC2 Support for Chef's Knife Command"
s.description = s.summary
s.extra_rdoc_files = ["README.rdoc", "LICENSE" ]
s.name = 'knife-ec2'
s.version = Knife::Ec2::VERSION
s.authors = ['Adam Jacob', 'Seth Chisamore']
s.email = ['[email protected]', '[email protected]']
s.homepage = 'https://github.com/opscode/knife-ec2'
s.summary = %q{EC2 Support for Chef\'s Knife Command}
s.description = s.summary
s.license = 'Apache 2.0'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.add_dependency "fog", "~> 1.6"
s.add_dependency "chef", ">= 0.10.10"
s.add_dependency "knife-windows", ">= 0.5.12"
%w(rspec-core rspec-expectations rspec-mocks rspec_junit_formatter).each { |gem| s.add_development_dependency gem }
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }

s.require_paths = ["lib"]
s.add_dependency 'fog', '~> 1.6'
s.add_dependency 'chef', '>= 0.10.10'
s.add_dependency 'knife-windows', '>= 0.5.12'

s.add_development_dependency 'rspec', '~> 2.14'
s.add_development_dependency 'rake', '~> 10.1'
s.add_development_dependency 'sdoc', '~> 0.3'

s.require_paths = ['lib']
end

48 changes: 24 additions & 24 deletions spec/unit/ec2_server_delete_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
:private_ip_address => '10.251.75.20',
:root_device_type => 'not_ebs' }
@knife_ec2_delete = Chef::Knife::Ec2ServerDelete.new
@ec2_servers = mock()
@ec2_servers = double()
@knife_ec2_delete.ui.stub(:confirm)
@knife_ec2_delete.stub(:msg_pair)
@ec2_server = mock(@ec2_server_attribs)
@ec2_connection = mock(Fog::Compute::AWS)
@ec2_connection.stub!(:servers).and_return(@ec2_servers)
@ec2_server = double(@ec2_server_attribs)
@ec2_connection = double(Fog::Compute::AWS)
@ec2_connection.stub(:servers).and_return(@ec2_servers)
@knife_ec2_delete.ui.stub(:warn)
end

Expand All @@ -76,12 +76,12 @@
@ec2_server.should_receive(:destroy)
@knife_ec2_delete.config[:purge] = false
@knife_ec2_delete.config[:chef_node_name] = 'baz'
mock_node = mock(Chef::Node)
mock_node.should_receive(:attribute?).with('ec2').and_return(true)
mock_node.should_receive(:[]).with('ec2').and_return('instance_id'=>'foo')
mock_search = mock(Chef::Search::Query)
mock_search.should_receive(:search).with(:node,"name:baz").and_return([[mock_node],nil,nil])
Chef::Search::Query.should_receive(:new).and_return(mock_search)
double_node = double(Chef::Node)
double_node.should_receive(:attribute?).with('ec2').and_return(true)
double_node.should_receive(:[]).with('ec2').and_return('instance_id'=>'foo')
double_search = double(Chef::Search::Query)
double_search.should_receive(:search).with(:node,"name:baz").and_return([[double_node],nil,nil])
Chef::Search::Query.should_receive(:new).and_return(double_search)
@knife_ec2_delete.name_args = []
@knife_ec2_delete.run
end
Expand All @@ -95,8 +95,8 @@
@ec2_server.should_receive(:destroy)
@knife_ec2_delete.config[:purge] = true
@knife_ec2_delete.config[:chef_node_name] = 'baz'
Chef::Node.should_receive(:load).with('baz').and_return(mock(:destroy=>true))
Chef::ApiClient.should_receive(:load).with('baz').and_return(mock(:destroy=>true))
Chef::Node.should_receive(:load).with('baz').and_return(double(:destroy=>true))
Chef::ApiClient.should_receive(:load).with('baz').and_return(double(:destroy=>true))
@knife_ec2_delete.run
end

Expand All @@ -108,13 +108,13 @@
@ec2_server.should_receive(:destroy)
@knife_ec2_delete.config[:purge] = true
@knife_ec2_delete.config[:chef_node_name] = nil
mock_search = mock(Chef::Search::Query)
mock_node = mock(Chef::Node)
mock_node.should_receive(:name).and_return("baz")
Chef::Node.should_receive(:load).with('baz').and_return(mock(:destroy=>true))
Chef::ApiClient.should_receive(:load).with('baz').and_return(mock(:destroy=>true))
mock_search.should_receive(:search).with(:node,"ec2_instance_id:i-foo").and_return([[mock_node],nil,nil])
Chef::Search::Query.should_receive(:new).and_return(mock_search)
double_search = double(Chef::Search::Query)
double_node = double(Chef::Node)
double_node.should_receive(:name).and_return("baz")
Chef::Node.should_receive(:load).with('baz').and_return(double(:destroy=>true))
Chef::ApiClient.should_receive(:load).with('baz').and_return(double(:destroy=>true))
double_search.should_receive(:search).with(:node,"ec2_instance_id:i-foo").and_return([[double_node],nil,nil])
Chef::Search::Query.should_receive(:new).and_return(double_search)
@knife_ec2_delete.run
end

Expand All @@ -126,11 +126,11 @@
@ec2_server.should_receive(:destroy)
@knife_ec2_delete.config[:purge] = true
@knife_ec2_delete.config[:chef_node_name] = nil
Chef::Node.should_receive(:load).with('i-foo').and_return(mock(:destroy=>true))
Chef::ApiClient.should_receive(:load).with('i-foo').and_return(mock(:destroy=>true))
mock_search = mock(Chef::Search::Query)
mock_search.should_receive(:search).with(:node,"ec2_instance_id:i-foo").and_return([[],nil,nil])
Chef::Search::Query.should_receive(:new).and_return(mock_search)
Chef::Node.should_receive(:load).with('i-foo').and_return(double(:destroy=>true))
Chef::ApiClient.should_receive(:load).with('i-foo').and_return(double(:destroy=>true))
double_search = double(Chef::Search::Query)
double_search.should_receive(:search).with(:node,"ec2_instance_id:i-foo").and_return([[],nil,nil])
Chef::Search::Query.should_receive(:new).and_return(double_search)
@knife_ec2_delete.run
end
end
Expand Down

0 comments on commit c23c1f1

Please sign in to comment.