Merge "Adding nova creating and deleting for client"
This commit is contained in:
commit
60d6a29184
|
@ -7,3 +7,5 @@ berks-cookbooks/
|
||||||
Berksfile.lock
|
Berksfile.lock
|
||||||
Vagrantfile
|
Vagrantfile
|
||||||
Gemfile.lock
|
Gemfile.lock
|
||||||
|
local-mode-cache
|
||||||
|
nodes/
|
||||||
|
|
14
.kitchen.yml
14
.kitchen.yml
|
@ -7,11 +7,19 @@ provisioner:
|
||||||
|
|
||||||
platforms:
|
platforms:
|
||||||
- name: ubuntu-14.04
|
- name: ubuntu-14.04
|
||||||
- name: ubuntu-12.04
|
- name: centos-6.6
|
||||||
|
- name: centos-7.0
|
||||||
|
|
||||||
suites:
|
suites:
|
||||||
- name: default
|
- name: default
|
||||||
run_list:
|
run_list:
|
||||||
- recipe[openstack::default]
|
- recipe[openstack_client::default]
|
||||||
- recipe[openstack::_example_swift]
|
attributes:
|
||||||
|
- name: swift
|
||||||
|
run_list:
|
||||||
|
- recipe[openstack_client::_example_swift]
|
||||||
|
attributes:
|
||||||
|
- name: nova
|
||||||
|
run_list:
|
||||||
|
- recipe[openstack_client::_example_nova]
|
||||||
attributes:
|
attributes:
|
||||||
|
|
2
Gemfile
2
Gemfile
|
@ -8,6 +8,8 @@ gem 'chefspec', '~> 4.0.0'
|
||||||
gem 'rspec', '~> 3.0.0'
|
gem 'rspec', '~> 3.0.0'
|
||||||
gem 'foodcritic', '~> 4.0'
|
gem 'foodcritic', '~> 4.0'
|
||||||
gem 'rubocop', '~> 0.29.1'
|
gem 'rubocop', '~> 0.29.1'
|
||||||
|
gem 'chef-sugar'
|
||||||
|
gem 'fog'
|
||||||
|
|
||||||
gem 'rake', '~> 10.0'
|
gem 'rake', '~> 10.0'
|
||||||
gem 'test-kitchen'
|
gem 'test-kitchen'
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
if defined?(ChefSpec)
|
||||||
|
def create_openstack_client_nova_server(resource_name)
|
||||||
|
ChefSpec::Matchers::ResourceMatcher.new(
|
||||||
|
:openstack_client_nova_server,
|
||||||
|
:create,
|
||||||
|
resource_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_openstack_client_nova_server(resource_name)
|
||||||
|
ChefSpec::Matchers::ResourceMatcher.new(
|
||||||
|
:openstack_client_nova_server,
|
||||||
|
:delete,
|
||||||
|
resource_name)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,36 @@
|
||||||
|
#
|
||||||
|
# Cookbook Name:: openstack-client
|
||||||
|
# Library:: nova
|
||||||
|
# Author:: JJ Asghar
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
module Openstack
|
||||||
|
module Client
|
||||||
|
# this is required to shut up rubocop
|
||||||
|
module Nova
|
||||||
|
include Openstack::Client
|
||||||
|
|
||||||
|
def nova # rubocop:disable all
|
||||||
|
@nova ||= Fog::Compute.new(provider: 'openstack',
|
||||||
|
openstack_username: new_resource.openstack_username,
|
||||||
|
openstack_api_key: new_resource.openstack_password,
|
||||||
|
openstack_auth_url: new_resource.openstack_auth_url,
|
||||||
|
openstack_tenant: new_resource.openstack_tenant,
|
||||||
|
openstack_region: new_resource.openstack_region
|
||||||
|
) # rubocop:disable all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,5 @@
|
||||||
# Encoding: utf-8
|
# Encoding: utf-8
|
||||||
name 'openstack-client'
|
name 'openstack_client'
|
||||||
maintainer 'openstack-chef'
|
maintainer 'openstack-chef'
|
||||||
maintainer_email 'opscode-chef-openstack@googlegroups.com'
|
maintainer_email 'opscode-chef-openstack@googlegroups.com'
|
||||||
license 'Apache2'
|
license 'Apache2'
|
||||||
|
@ -8,7 +8,9 @@ long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||||
version '11.0.0'
|
version '11.0.0'
|
||||||
|
|
||||||
supports 'ubuntu', '>= 14.04'
|
supports 'ubuntu', '>= 14.04'
|
||||||
|
supports 'centos', '>= 6.5'
|
||||||
|
|
||||||
depends 'apt', '~> 2.6.1'
|
depends 'apt', '~> 2.6.1'
|
||||||
depends 'build-essential', '~> 2.1.3'
|
depends 'build-essential', '~> 2.1.3'
|
||||||
depends 'xml', '~> 1.2.13'
|
depends 'xml', '~> 1.2.13'
|
||||||
|
depends 'yum', '~> 3.5.4'
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
#
|
||||||
|
# Cookbook Name:: openstack-client
|
||||||
|
# Provider:: nova_server
|
||||||
|
# Author:: JJ Asghar
|
||||||
|
#
|
||||||
|
# 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 'tempfile'
|
||||||
|
require 'chef/digester'
|
||||||
|
|
||||||
|
include Openstack::Client::Nova
|
||||||
|
|
||||||
|
def whyrun_supported?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
action :create do
|
||||||
|
require 'fog'
|
||||||
|
name = new_resource.name
|
||||||
|
image = new_resource.image
|
||||||
|
flavor = new_resource.flavor
|
||||||
|
|
||||||
|
ruby_block 'create a server' do
|
||||||
|
block do
|
||||||
|
nova.create_server(name, image, flavor)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
new_resource.updated_by_last_action(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
action :delete do
|
||||||
|
require 'fog'
|
||||||
|
id = new_resource.id
|
||||||
|
|
||||||
|
ruby_block 'delete a server' do
|
||||||
|
block do
|
||||||
|
nova.delete_server(id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
new_resource.updated_by_last_action(true)
|
||||||
|
end
|
|
@ -0,0 +1,40 @@
|
||||||
|
#
|
||||||
|
# Cookbook Name:: openstack-client
|
||||||
|
# Provider:: _example_nova
|
||||||
|
# Author:: JJ Asghar
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
include_recipe 'openstack_client::default'
|
||||||
|
|
||||||
|
openstack_client_nova_server 'test1' do
|
||||||
|
openstack_username 'USERNAME'
|
||||||
|
openstack_password 'PASSWORD'
|
||||||
|
openstack_auth_url 'https://mybackendopenstack:35357/v2.0/tokens'
|
||||||
|
openstack_tenant 'Project'
|
||||||
|
openstack_region 'region-a'
|
||||||
|
image 'bec3cab5-4722-40b9-a78a-3489218e22fe'
|
||||||
|
flavor '101'
|
||||||
|
action :create
|
||||||
|
end
|
||||||
|
|
||||||
|
openstack_client_nova_server 'test' do
|
||||||
|
openstack_username 'USERNAME'
|
||||||
|
openstack_password 'PASSWORD'
|
||||||
|
openstack_auth_url 'https://mybackendopenstack:35357/v2.0/tokens'
|
||||||
|
openstack_tenant 'Project'
|
||||||
|
openstack_region 'region-a'
|
||||||
|
id 'c6ab5354-baa4-4ea3-af27-ef3eb874472e'
|
||||||
|
action :delete
|
||||||
|
end
|
|
@ -8,26 +8,25 @@
|
||||||
|
|
||||||
# Required to install fog
|
# Required to install fog
|
||||||
|
|
||||||
if platform_family?('debian')
|
case node['platform_family']
|
||||||
|
when 'debian'
|
||||||
node.override['apt']['compile_time_update'] = true
|
node.override['apt']['compile_time_update'] = true
|
||||||
include_recipe 'apt'
|
include_recipe 'apt'
|
||||||
|
|
||||||
|
node.set['build-essential']['compile_time'] = true
|
||||||
|
include_recipe 'build-essential'
|
||||||
|
when 'redhat'
|
||||||
|
include_recipe 'yum'
|
||||||
end
|
end
|
||||||
|
|
||||||
node.set['build-essential']['compile_time'] = true
|
include_recipe 'xml::ruby'
|
||||||
include_recipe 'build-essential'
|
|
||||||
|
|
||||||
chef_gem 'nokogiri' do
|
chef_gem 'nokogiri' do
|
||||||
version node['openstack-client']['nokogiri_version']
|
version node['openstack-client']['nokogiri_version']
|
||||||
action :upgrade
|
action :upgrade
|
||||||
end
|
end
|
||||||
|
|
||||||
include_recipe 'xml::ruby'
|
|
||||||
|
|
||||||
chef_gem 'fog' do
|
chef_gem 'fog' do
|
||||||
version node['openstack-client']['fog_version']
|
version node['openstack-client']['fog_version']
|
||||||
action :upgrade
|
action :upgrade
|
||||||
end
|
end
|
||||||
|
|
||||||
# Load fog for the cloud_monitoring library
|
|
||||||
# https://sethvargo.com/using-gems-with-chef/
|
|
||||||
require 'fog'
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
#
|
||||||
|
# Cookbook Name:: openstack-client
|
||||||
|
# Resource:: nova_server
|
||||||
|
# Author:: JJ Asghar
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
actions :create, :delete
|
||||||
|
|
||||||
|
default_action :create
|
||||||
|
|
||||||
|
BOOLEAN = [TrueClass, FalseClass]
|
||||||
|
|
||||||
|
attribute :openstack_username, kind_of: String, required: true
|
||||||
|
attribute :openstack_password, kind_of: String, required: true
|
||||||
|
attribute :openstack_tenant, kind_of: String, required: true
|
||||||
|
attribute :openstack_region, kind_of: String, default: 'RegionOne'
|
||||||
|
attribute :openstack_auth_url, kind_of: String, required: true
|
||||||
|
attribute :name, kind_of: String, name_attribute: true
|
||||||
|
attribute :id, kind_of: String, name_attribute: true
|
||||||
|
attribute :image, kind_of: String, required: true
|
||||||
|
attribute :flavor, kind_of: String
|
||||||
|
|
||||||
|
def initialize(*args)
|
||||||
|
super
|
||||||
|
@action = :create
|
||||||
|
end
|
|
@ -0,0 +1,45 @@
|
||||||
|
# Encoding: utf-8
|
||||||
|
|
||||||
|
require_relative 'spec_helper'
|
||||||
|
|
||||||
|
describe 'openstack_client::_example_nova' do
|
||||||
|
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
|
||||||
|
let(:node) { runner.node }
|
||||||
|
let(:chef_run) { runner.converge(described_recipe) }
|
||||||
|
|
||||||
|
it 'spins up a test machine' do
|
||||||
|
expect(chef_run).to create_openstack_client_nova_server(
|
||||||
|
'test1'
|
||||||
|
).with(
|
||||||
|
action: [:create]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'openstack_client::_example_nova' do
|
||||||
|
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
|
||||||
|
let(:node) { runner.node }
|
||||||
|
let(:chef_run) { runner.converge(described_recipe) }
|
||||||
|
|
||||||
|
it 'deletes a test machine' do
|
||||||
|
expect(chef_run).to delete_openstack_client_nova_server(
|
||||||
|
'test'
|
||||||
|
).with(
|
||||||
|
action: [:delete]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'openstack_client::_example_nova' do
|
||||||
|
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
|
||||||
|
let(:node) { runner.node }
|
||||||
|
let(:chef_run) { runner.converge(described_recipe) }
|
||||||
|
|
||||||
|
it 'install the nokogiri gem' do
|
||||||
|
expect(chef_run).to install_chef_gem('nokogiri')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'install the fog gem' do
|
||||||
|
expect(chef_run).to upgrade_chef_gem('fog')
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,8 +4,8 @@ require 'chefspec'
|
||||||
require 'chefspec/berkshelf'
|
require 'chefspec/berkshelf'
|
||||||
require 'chef/application'
|
require 'chef/application'
|
||||||
|
|
||||||
::LOG_LEVEL = :fatal
|
LOG_LEVEL = :fatal
|
||||||
::UBUNTU_OPTS = {
|
UBUNTU_OPTS = {
|
||||||
platform: 'ubuntu',
|
platform: 'ubuntu',
|
||||||
version: '14.04',
|
version: '14.04',
|
||||||
log_level: ::LOG_LEVEL
|
log_level: ::LOG_LEVEL
|
||||||
|
|
Loading…
Reference in New Issue