Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenStack support to knife-server command. #51

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ tmp
.rbenv-version
.ruby-version
.rbx/
bin/
15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 1.9.2
- ruby-head
- 1.9.3
- 2.0.0
- 2.1.0

env:
- "CHEF_VERSION=11.4.0"
- "CHEF_VERSION=10.24.0"
- "CHEF_VERSION=0.10.10"
- "CHEF_VERSION=11.4.0"
- "CHEF_VERSION=10.24.0"
- "CHEF_VERSION=0.10.10"

matrix:
allow_failures:
- rvm: ruby-head
- rvm: ruby-head
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ knife server bootstrap linode \
--ssh-password 'testing1234'
```

To spin up your Chef Server on [OpenStack][openstack]:

```bash
knife server bootstrap openstack \
--node-name openstack.example.com \
--openstack-node-name openstack \
--openstack-username $OS_USERNAME \
--openstack-password $OS_PASSWORD \
--openstack-auth-url $OS_AUTH_URL \
--ssh-password 'testing1234'
``

Or maybe you want to try out a Chef Server using [Vagrant][vagrant_site]?

```bash
Expand Down Expand Up @@ -403,6 +415,15 @@ to make future cloud adapter support easier to add.
Provisions a Linode instance and sets up an Open Source Chef Server as
described [above](#knife-server-bootstrap).

### <a name="knife-server-bootstrap-openstack"></a> knife server bootstrap openstack

**Note:** You must install the [knife-openstack gem][knife-openstack] to use this
subcommand. This was done to keep the dependencies of this library lighter and
to make future cloud adapter support easier to add.

Provisions a Openstack instance and sets up an Open Source Chef Server as
described [above](#knife-server-bootstrap).

#### Configuration

This subcommand imports all relavent options from the knife-linode gem. For
Expand Down Expand Up @@ -622,5 +643,7 @@ Apache License, Version 2.0 (see [LICENSE][license])
[install_chef]: http://www.opscode.com/chef/install/
[knife-ec2]: https://github.com/opscode/knife-ec2
[knife-linode]: https://github.com/opscode/knife-linode
[knife-openstack]: https://github.com/opscode/knife-openstack
[stevendanna]: https://github.com/stevendanna
[vagrant_site]: http://vagrantup.com/
[openstack]: http://openstack.org
1 change: 1 addition & 0 deletions knife-server.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Gem::Specification.new do |gem|

gem.add_development_dependency "knife-ec2", ">= 0.5.12"
gem.add_development_dependency "knife-linode"
gem.add_development_dependency "knife-openstack"

gem.add_development_dependency "rspec", "~> 2.13.0"
gem.add_development_dependency "fakefs", "~> 0.4.0"
Expand Down
3 changes: 2 additions & 1 deletion lib/chef/knife/server_bootstrap_ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def ec2_bootstrap
ENV['NO_TEST'] = "1" if config[:no_test]
bootstrap = Chef::Knife::Ec2ServerCreate.new
Chef::Knife::Ec2ServerCreate.options.keys.each do |attr|
bootstrap.config[attr] = config_val(attr)
value = config_val(attr)
bootstrap.config[attr] = value unless ((value.is_a?(Array) and value[1].nil?) or value.nil?)
end
bootstrap.config[:tags] = bootstrap_tags
bootstrap.config[:distro] = bootstrap_distro
Expand Down
3 changes: 2 additions & 1 deletion lib/chef/knife/server_bootstrap_linode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def linode_bootstrap
ENV['NO_TEST'] = "1" if config[:no_test]
bootstrap = Chef::Knife::LinodeServerCreate.new
Chef::Knife::LinodeServerCreate.options.keys.each do |attr|
bootstrap.config[attr] = config_val(attr)
value = config_val(attr)
bootstrap.config[attr] = value unless ((value.is_a?(Array) and value[1].nil?) or value.nil?)
end
bootstrap.config[:distro] = bootstrap_distro
bootstrap
Expand Down
122 changes: 122 additions & 0 deletions lib/chef/knife/server_bootstrap_openstack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#
# Author:: John Bellone (<jbellone@bloomberg.net>)
# Copyright:: Copyright (c) 2014 Bloomberg Finance L.P.
# License:: Apache License, Version 2.0
#
# 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.
#

require 'chef/knife/server_bootstrap_base'

class Chef
class Knife
class ServerBootstrapOpenstack < Knife

banner "knife server bootstrap openstack (options)"

include Knife::ServerBootstrapBase

deps do
require 'knife/server/ssh'
require 'knife/server/credentials'

begin
require 'chef/knife/openstack_server_create'
require 'fog'
Chef::Knife::OpenstackServerCreate.load_deps

current_options = self.options
self.options = Chef::Knife::OpenstackServerCreate.options.dup
self.options.merge!(current_options)
rescue LoadError => ex
ui.error [
"Knife plugin knife-openstack could not be loaded.",
"Please add the knife-openstack gem to your Gemfile or",
"install the gem manually with `gem install knife-openstack'.",
"(#{ex.message})"
].join(" ")
exit 1
end
end

def run
validate!
openstack_bootstrap.run
fetch_validation_key
create_root_client
install_client_key
end

def openstack_bootstrap
ENV['WEBUI_PASSWORD'] = config_val(:webui_password)
ENV['AMQP_PASSWORD'] = config_val(:amqp_password)
ENV['NO_TEST'] = "1" if config[:no_test]
bootstrap = Chef::Knife::OpenstackServerCreate.new
Chef::Knife::OpenstackServerCreate.options.keys.each do |attr|
value = config_val(attr)
bootstrap.config[attr] = value unless ((value.is_a?(Array) and value[1].nil?) or value.nil?)
end
bootstrap.config[:distro] = bootstrap_distro
bootstrap
end

def openstack_connection
@openstack_connection ||= Fog::Compute.new(
:provider => :openstack,
:openstack_username => config_val(:openstack_username),
:openstack_password => config_val(:openstack_password),
:openstack_auth_url => config_val(:openstack_auth_url),
:openstack_tenant => config_val(:openstack_tenant),
:openstack_region => config_val(:openstack_region)
)
end

def server_ip_address
server = openstack_connection.servers.find do |s|
s.status == 1 && s.name == config_val(:openstack_node_name)
end

server && server.public_ip_address
end

private

def validate!
if config[:chef_node_name].nil?
ui.error "You did not provide a valid --node-name value."
exit 1
end
if config_val(:platform) == "auto"
ui.error "Auto platform mode cannot be used with knife-openstack plugin"
exit 1
end
end

def ssh_connection
opts = {
:host => server_ip_address,
:user => config_val(:ssh_user),
:port => config_val(:ssh_port),
:keys => [config_val(:identity_file)].compact,
:password => config_val(:ssh_password)
}
if config_val(:host_key_verify) == false
opts[:user_known_hosts_file] = "/dev/null"
opts[:paranoid] = false
end

::Knife::Server::SSH.new(opts)
end
end
end
end
3 changes: 2 additions & 1 deletion lib/chef/knife/server_bootstrap_standalone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def standalone_bootstrap
bootstrap = Chef::Knife::Bootstrap.new
bootstrap.name_args = [ config[:host] ]
Chef::Knife::Bootstrap.options.keys.each do |attr|
bootstrap.config[attr] = config_val(attr)
value = config_val(attr)
bootstrap.config[attr] = value unless ((value.is_a?(Array) and value[1].nil?) or value.nil?)
end
bootstrap.ui = self.ui
bootstrap.config[:distro] = bootstrap_distro
Expand Down
Loading