knife-vcair 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +89 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile +4 -0
- data/Guardfile +23 -0
- data/LICENSE +202 -0
- data/README.md +197 -0
- data/Rakefile +35 -0
- data/example.env +5 -0
- data/install-linux-vcair-example.sh +22 -0
- data/install-winrm-vcair-example.bat +36 -0
- data/knife-vcair.gemspec +35 -0
- data/lib/chef/knife/cloud/vcair_server_create_options.rb +73 -0
- data/lib/chef/knife/cloud/vcair_service.rb +57 -0
- data/lib/chef/knife/cloud/vcair_service_options.rb +77 -0
- data/lib/chef/knife/vcair_helpers.rb +94 -0
- data/lib/chef/knife/vcair_image_list.rb +51 -0
- data/lib/chef/knife/vcair_ip_list.rb +59 -0
- data/lib/chef/knife/vcair_network_list.rb +57 -0
- data/lib/chef/knife/vcair_server_create.rb +231 -0
- data/lib/chef/knife/vcair_server_delete.rb +34 -0
- data/lib/chef/knife/vcair_server_list.rb +33 -0
- data/lib/chef/knife/vcair_server_show.rb +37 -0
- data/lib/chef/knife/vcair_vm_delete.rb +51 -0
- data/lib/chef/knife/vcair_vm_list.rb +62 -0
- data/lib/knife-vcair/version.rb +6 -0
- data/spec/integration/config/knife.rb +9 -0
- data/spec/integration/config/validation.pem +27 -0
- data/spec/integration/vchs_spec.rb +108 -0
- data/spec/spec_helper.rb +73 -0
- data/spec/unit/lib/chef/knife/vcair_server_create_spec.rb +231 -0
- data/spec/utils/knifeutils.rb +35 -0
- data/spec/utils/matchers.rb +29 -0
- metadata +257 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@getchef.com>)
|
3
|
+
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife/cloud/server/delete_options'
|
20
|
+
require 'chef/knife/cloud/server/delete_command'
|
21
|
+
require 'chef/knife/cloud/vcair_service'
|
22
|
+
require 'chef/knife/cloud/vcair_service_options'
|
23
|
+
require 'chef/knife/vcair_helpers'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Knife
|
27
|
+
class Cloud
|
28
|
+
class VcairVmDelete < ServerDeleteCommand
|
29
|
+
include ServerDeleteOptions
|
30
|
+
include VcairServiceOptions
|
31
|
+
include VcairHelpers
|
32
|
+
|
33
|
+
banner "knife vcair vm delete INSTANCEID [INSTANCEID] (options)"
|
34
|
+
|
35
|
+
def execute_command
|
36
|
+
@name_args.each do |server_name|
|
37
|
+
vapp = vdc.vapps.get_by_name(server_name)
|
38
|
+
if vapp
|
39
|
+
vapp.power_off
|
40
|
+
vapp.undeploy
|
41
|
+
vapp.destroy
|
42
|
+
else
|
43
|
+
ui.warn("No VApp named '#{server_name}' was found.")
|
44
|
+
end
|
45
|
+
delete_from_chef(server_name)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Matt Ray (<matt@getchef.com>)
|
3
|
+
# Author:: Seth Thomas (<sthomas@getchef.com>)
|
4
|
+
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'chef/knife/cloud/list_resource_command'
|
21
|
+
require 'chef/knife/vcair_helpers'
|
22
|
+
require 'chef/knife/cloud/vcair_service_options'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Knife
|
26
|
+
class Cloud
|
27
|
+
class VcairVmList < ResourceListCommand
|
28
|
+
include VcairHelpers
|
29
|
+
include VcairServiceOptions
|
30
|
+
|
31
|
+
banner "knife vcair vm list (options)"
|
32
|
+
|
33
|
+
def query_resource
|
34
|
+
vms = []
|
35
|
+
vdc.vapps.all.each do |vapp|
|
36
|
+
vms << vapp.vms.all
|
37
|
+
end
|
38
|
+
vms.flatten
|
39
|
+
end
|
40
|
+
|
41
|
+
def before_exec_command
|
42
|
+
@columns_with_info = [
|
43
|
+
{:label => 'vAPP', :key => 'vapp_name'},
|
44
|
+
{:label => 'Name', :key => 'name'},
|
45
|
+
{:label => 'IP', :key => 'ip_address'},
|
46
|
+
{:label => 'CPU', :key => 'cpu'},
|
47
|
+
{:label => 'Memory', :key => 'memory'},
|
48
|
+
{:label => 'OS', :key => 'operating_system'},
|
49
|
+
{:label => 'Owner', :key => 'vapp', :value_callback => method(:owner) },
|
50
|
+
{:label => 'Status', :key => 'status'}
|
51
|
+
]
|
52
|
+
@sort_by_field = 'vapp_name'
|
53
|
+
end
|
54
|
+
|
55
|
+
def owner(vapp)
|
56
|
+
vapp.owner[0][:name]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
current_dir = File.dirname(__FILE__)
|
2
|
+
node_name "chef0"
|
3
|
+
client_key "#{current_dir}/validation.pem"
|
4
|
+
validation_client_name "validation"
|
5
|
+
validation_key "#{current_dir}/validation.pem"
|
6
|
+
chef_server_url "http://localhost:8889"
|
7
|
+
cache_type 'BasicFile'
|
8
|
+
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
|
9
|
+
cookbook_path ["#{current_dir}/chef-repo/cookbooks"]
|
@@ -0,0 +1,27 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
MIIEogIBAAKCAQEA7TfhToresZudM5gaBfzM/eHrGuJtN8uMaG51fLk9rNVwOxIw
|
3
|
+
eb9AmWJSQgftRj4AJSnt8Jv+QyAafjg79rEmCpd2K+toN1fXiVsf/ld/VdMI5vCd
|
4
|
+
usJc8aC4OFIVrLetm9eq+joXiCSLfEYP1w4d1gc9wqr54rnGVgQdWv31NhqXX7Tl
|
5
|
+
2bHRoEsfIFM7Vr5zC9Rv6XEtrwezSpzQ+ru707UOCOHNnH1TDxNDz+L71xJnGXD6
|
6
|
+
uh596hVm2GiXJ8lyCVJTs/RZ+HKtRuxYOJztdCQAXbd6DDjTBax/cCEzzoxK/LMc
|
7
|
+
1K/zWCKN8yM/XpiFqNuBB0yrqS5Y4zlROY0ssQIDAQABAoIBAQDmC1HYvD1YGePq
|
8
|
+
O+/IrK8S6jr4WGq4OBIS2EPhTzbrXBU5g9s0xe7ckIfa9xr4CnpTkATqWCzMZd6r
|
9
|
+
Vtd31bVhgh6cWu829F3WG2O8YJfg4AX7B46+pWxC+qyMGbZhR8L5pb1ualWVtnL6
|
10
|
+
cms8D7mJbH5NQUeRwrz/f4AEVNGuw165PhglXnRq3zxs97jdNH6av0na1VLAmUeR
|
11
|
+
vmYToLoIsK5yLeNzMfRRrQkq4ndUvad2ahqsz+p/xUjfYneBz4uujE/PcCgi423Q
|
12
|
+
FMH1NtPpzmuZuABU53wUMW4BXsSGv+34UMhRTazcBPRBYjKT6l6F7Tt9wPFxrtVn
|
13
|
+
KYI9dI0tAoGBAPzBwLsUuyEJtSd2zW63f7EhhG/2rSBm1g9Bcs1sHZtXIX3JN51X
|
14
|
+
hd+ckXQcLgQYn8syGW1+WcuaHGyp7v3G0yr6b38FWwEnmD85Mq5da1dyio2udBdK
|
15
|
+
Xm8MfY94yP8qSH3bUDKEl+cV9X5rtzbQAorMXb/Qkc4vErWfABVBKeLPAoGBAPBD
|
16
|
+
FjGxER9YU4hFV2vn5qElfxa799Vl0uSvao0lSkTpA/sHFxAkRQc/mo1PBClaH0ba
|
17
|
+
Hqr141o5pGUDgLqpO3kEY5vYBOaFXLFdFCcL+1YUR6t0bX+WCHuq21Cs6Gu4+qNA
|
18
|
+
D4dpsSPDXfatyXWM5PF2d4FwO2XnL25Yt+rg6dh/AoGAbEfk9UCQWjr6bImswH3E
|
19
|
+
KnIddonK6VKk6aw0LmTe2imdo3GMbc+M/prohUF9RSv3aOlxk0LJ3TuMadDzHa0L
|
20
|
+
0iGvmk8FCZ2Yz50FZUWIMtJTIRdXjJLDmfdT4x7vnMDUhXZrCPlcyhbSMPKcbtL2
|
21
|
+
A9hBYWdMz3PDJCOVuYVNGGkCgYEAhSxKUwTYfs1Qj8oPqOoDdfL4vLs3pfsoqEVr
|
22
|
+
BA1VW1jlMfE+IV5ZPKlOm2De56TijT09nnloqYwlyS/l3JENPAjoxWs5XCUzucPj
|
23
|
+
9bi4eYAIMcr5Hq0kypdrtQ4CTiNcGbzaXq6A11fk72RotFWCWSzXFNIGuncoXTuj
|
24
|
+
xfcg5zUCf3TQrwpcBB1Hf9hm6lUVpptvUZJAQtkWoaWXUPRY0CjcVdDc5ak4xqL2
|
25
|
+
FcAuJwV95b3qLyPESJ8zUBLOg3DcT1X9mrvRuKgC/Ie6k4R+oxU/nXi4vsPXlvg4
|
26
|
+
yap6MUYSjPOa7eCrhg2zFZiqO6VLEogPc1nsjb9Zl2UWLLYyCVz=
|
27
|
+
-----END RSA PRIVATE KEY-----
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# Copyright: Copyright (c) 2012 Opscode, Inc.
|
2
|
+
# License: Apache License, Version 2.0
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
# Author:: Ameya Varade (<ameya.varade@clogeny.com>)
|
17
|
+
|
18
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
19
|
+
|
20
|
+
def init_test
|
21
|
+
#We may not need knife.rb for now but we might need while writing create, list, delete test cases.
|
22
|
+
puts "\nCreating Test Data\n"
|
23
|
+
create_file("#{temp_dir}", "validation.pem", "../integration/config/validation.pem" )
|
24
|
+
create_file("#{temp_dir}", "knife.rb", "../integration/config/knife.rb")
|
25
|
+
end
|
26
|
+
|
27
|
+
def cleanup_test_data
|
28
|
+
puts "\nCleaning Test Data\n"
|
29
|
+
FileUtils.rm_rf("#{temp_dir}")
|
30
|
+
puts "\nDone\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_gem_file_name
|
34
|
+
"knife-vcair-" + Knife::Vcair::VERSION + ".gem"
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'knife-vcair' do
|
38
|
+
include RSpec::KnifeUtils
|
39
|
+
before(:all) { init_test }
|
40
|
+
after(:all) { cleanup_test_data }
|
41
|
+
context 'gem' do
|
42
|
+
# context 'build' do
|
43
|
+
# let(:command) { "gem build knife-vcair.gemspec" }
|
44
|
+
# it 'should succeed' do
|
45
|
+
# match_status("should succeed")
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# context 'install ' do
|
50
|
+
# let(:command) { "gem install " + get_gem_file_name }
|
51
|
+
# it 'should succeed' do
|
52
|
+
# match_status("should succeed")
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
|
56
|
+
describe 'knife' do
|
57
|
+
#context 'vcair' do
|
58
|
+
# context 'image list --help' do
|
59
|
+
# let(:command) { "knife vcair image list --help" }
|
60
|
+
# it 'should succeed' do
|
61
|
+
# should have_outcome :stdout => /--help/
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
# context 'network list --help' do
|
65
|
+
# let(:command) { "knife vcair network list --help" }
|
66
|
+
# it 'should succeed' do
|
67
|
+
# should have_outcome :stdout => /--help/
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
|
71
|
+
# context 'server create --help' do
|
72
|
+
# let(:command) { "knife vcair server create --help" }
|
73
|
+
# it 'should succeed' do
|
74
|
+
# should have_outcome :stdout => /--help/
|
75
|
+
# end
|
76
|
+
# end
|
77
|
+
|
78
|
+
# context 'server create --help' do
|
79
|
+
# let(:command) { "knife vcair server create" }
|
80
|
+
# it 'should succeed' do
|
81
|
+
# should have_outcome :stdout => /--help/
|
82
|
+
# end
|
83
|
+
# end
|
84
|
+
|
85
|
+
# context 'server delete --help' do
|
86
|
+
# let(:command) { "knife vcair server delete --help" }
|
87
|
+
# it 'should succeed' do
|
88
|
+
# should have_outcome :stdout => /--help/
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
|
92
|
+
# context 'server list --help' do
|
93
|
+
# let(:command) { "knife vcair server list --help" }
|
94
|
+
# it 'should succeed' do
|
95
|
+
# should have_outcome :stdout => /--help/
|
96
|
+
# end
|
97
|
+
# end
|
98
|
+
#end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'uninstall ' do
|
102
|
+
let(:command) { "gem uninstall knife-vcair -v '#{KnifeVCloud::VERSION}'" }
|
103
|
+
it 'should succeed' do
|
104
|
+
match_status("should succeed")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Chirag Jog (<chirag@clogeny.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
20
|
+
|
21
|
+
require 'chef/knife/bootstrap'
|
22
|
+
require 'chef/knife/vcair_helpers'
|
23
|
+
# require 'winrm'
|
24
|
+
# require 'em-winrm'
|
25
|
+
require 'chef'
|
26
|
+
require 'fog'
|
27
|
+
require 'dotenv'
|
28
|
+
#Dotenv.load unless ENV['VCLOUD_DIRECTOR_USERNAME']
|
29
|
+
Dotenv.load
|
30
|
+
|
31
|
+
|
32
|
+
# require 'chef/knife/vcloud_base'
|
33
|
+
# require 'chef/knife/vcloud_server_create'
|
34
|
+
# require 'chef/knife/vcloud_server_delete'
|
35
|
+
# require 'chef/knife/vcloud_server_list'
|
36
|
+
# require 'knife-vcloud/version'
|
37
|
+
require 'chef/knife/winrm_base'
|
38
|
+
require 'chef/knife/bootstrap_windows_winrm'
|
39
|
+
require 'chef/knife/vcair_server_create'
|
40
|
+
require 'chef/knife/vcair_server_delete'
|
41
|
+
require 'chef/knife/bootstrap_windows_ssh'
|
42
|
+
require 'knife-vcair/version'
|
43
|
+
|
44
|
+
require 'test/knife-utils/test_bed'
|
45
|
+
require 'resource_spec_helper'
|
46
|
+
|
47
|
+
require "securerandom"
|
48
|
+
require 'tmpdir'
|
49
|
+
require 'fileutils'
|
50
|
+
require File.expand_path(File.dirname(__FILE__) +'/utils/knifeutils')
|
51
|
+
require File.expand_path(File.dirname(__FILE__) +'/utils/matchers')
|
52
|
+
|
53
|
+
def temp_dir
|
54
|
+
@_temp_dir ||= Dir.mktmpdir
|
55
|
+
end
|
56
|
+
|
57
|
+
def match_status(test_run_expect)
|
58
|
+
if "#{test_run_expect}" == "should fail"
|
59
|
+
should_not have_outcome :status => 0
|
60
|
+
elsif "#{test_run_expect}" == "should succeed"
|
61
|
+
should have_outcome :status => 0
|
62
|
+
elsif "#{test_run_expect}" == "should return empty list"
|
63
|
+
should have_outcome :status => 0
|
64
|
+
else
|
65
|
+
should have_outcome :status => 0
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_file(file_dir, file_name, data_to_write_file_path)
|
70
|
+
data_to_write = File.read(File.expand_path("#{data_to_write_file_path}", __FILE__))
|
71
|
+
File.open("#{file_dir}/#{file_name}", 'w') {|f| f.write(data_to_write)}
|
72
|
+
puts "Creating: #{file_name}"
|
73
|
+
end
|
@@ -0,0 +1,231 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Vulk <wolfpack@vulk.co>
|
3
|
+
# Copyright:: Copyright (c) 2014 Chef Inc
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require File.expand_path('../../../../../spec_helper', __FILE__)
|
20
|
+
require 'fog'
|
21
|
+
require 'chef/knife/bootstrap'
|
22
|
+
require 'chef/knife/bootstrap_windows_winrm'
|
23
|
+
|
24
|
+
def vcair
|
25
|
+
@vcair ||= Fog::Compute::VcloudDirector.new(
|
26
|
+
:connection_options => {
|
27
|
+
:ssl_verify_peer => false,
|
28
|
+
:connect_timeout => 200,
|
29
|
+
:read_timeout => 200
|
30
|
+
}
|
31
|
+
)
|
32
|
+
end
|
33
|
+
|
34
|
+
## TODO: make sure variables are consistent for VCAir/Vcloud Director.. etc
|
35
|
+
|
36
|
+
describe Chef::Knife::Cloud::VcairServerCreate do
|
37
|
+
before(:each) do
|
38
|
+
@knife_vcair_create = Chef::Knife::Cloud::VcairServerCreate.new
|
39
|
+
@knife_vcair_create.stub(:tcp_test_ssh).and_return(true)
|
40
|
+
@knife_vcair_create.stub(:tcp_test_winrm).and_return(true)
|
41
|
+
{
|
42
|
+
:image => 'image',
|
43
|
+
:vcair_password => ENV['VCAIR_PASSWORD'] || 'vcair_password',
|
44
|
+
:vcair_username => ENV['VCAIR_USERNAME'] || 'vcair_username',
|
45
|
+
:vcair_api_host => ENV['VCAIR_HOST'] || 'vcair_host',
|
46
|
+
:vcair_org => ENV['VCAIR_ORG'] || 'vcair_org',
|
47
|
+
:vcair_catalog_item => ENV['VCLOUD_CATALOG_ITEM'] || 'vcair_catalog_item',
|
48
|
+
:vcair_vm_name => ((ENV['VCAIR_VMNAME']).nil? ? ('TESTING-KNIFE' + rand.to_s) : (ENV['VCAIR_VMNAME']) + rand.to_s),
|
49
|
+
:vcair_api_version => '5.6',
|
50
|
+
:chef_node_name => 'chef_node_name',
|
51
|
+
}.each do |key, value|
|
52
|
+
@knife_vcair_create.config[key] = value
|
53
|
+
end
|
54
|
+
|
55
|
+
@knife_vcair_create.stub(:puts)
|
56
|
+
@knife_vcair_create.stub(:print)
|
57
|
+
|
58
|
+
@vcair_connection = double(Fog::Compute::VcloudDirector)
|
59
|
+
#@vcair_org = double(Fog::Compute::VcloudDirector::....
|
60
|
+
|
61
|
+
# [ <Fog::Compute::VcloudDirector::Organization
|
62
|
+
# id="5856ae9f-22c7-4453-952a-12868fdce6e4",
|
63
|
+
# name="M511664989-4904",
|
64
|
+
# type="application/vnd.vmware.vcloud.org+xml",
|
65
|
+
# href="https://p3v11-vcd.vcair.vmware.com:443/api/org/5856ae9f-22c7-4453-952a-12868fdce6e4",
|
66
|
+
# description=NonLoaded,
|
67
|
+
# full_name=NonLoaded
|
68
|
+
# >]
|
69
|
+
|
70
|
+
@catalog_items = [double(:href => "image", :password_enabled? => true)]
|
71
|
+
@catalogs = [double(:href => "catalog", :catalog_items => @catalog_items)]
|
72
|
+
@vcair_connection.stub_chain(:catalogs).and_return( @catalogs )
|
73
|
+
@network = double(:name => "network", :href => "vcair_network")
|
74
|
+
@vcair_connection.stub_chain(:networks, :all, :find).and_return( @network )
|
75
|
+
@vcair_vapps = double()
|
76
|
+
@new_vapp = double(:name => "name", :href => "vapp", :children => {:href => "children"})
|
77
|
+
@new_server = double(
|
78
|
+
:id => "id",
|
79
|
+
:network => {:network_name => "vcair_network", :network_mode => "POOL" },
|
80
|
+
:password => 'password',
|
81
|
+
:cpu => 'cpu',
|
82
|
+
:memory => 'memory'
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "run" do
|
87
|
+
before do
|
88
|
+
#Fog::Compute::VcloudDirector.should_receive(:new).and_return(@vcair_connection)
|
89
|
+
#@vcair_connection.should_receive(:servers).and_return( @vcair_vapps )
|
90
|
+
#@vcair_vapps.should_receive(:create).and_return( @new_vapp )
|
91
|
+
#@new_vapp.should_receive(:wait_for)
|
92
|
+
#@new_server.should_receive(:wait_for).twice
|
93
|
+
#@new_server.should_receive(:power_on).and_return(true)
|
94
|
+
#@new_server.should_receive(:network=).and_return(@new_server.network)
|
95
|
+
#@vcair_connection.should_receive(:get_vapp).and_return( @new_vapp )
|
96
|
+
#@vcair_connection.should_receive(:get_server).and_return( @new_server )
|
97
|
+
end
|
98
|
+
|
99
|
+
it "creates an vapp and bootstraps it" do
|
100
|
+
# TODO: mock out the vcair_connetion completely
|
101
|
+
#Fog::Compute::VcloudDirector.should_receive(:new).and_return(@vcair_connection)
|
102
|
+
#@new_server.should_receive(:save)
|
103
|
+
@bootstrap = Chef::Knife::Bootstrap.new
|
104
|
+
Chef::Knife::Bootstrap.stub(:new).and_return(@bootstrap)
|
105
|
+
#@bootstrap.should_receive(:run)
|
106
|
+
@knife_vcair_create.run
|
107
|
+
end
|
108
|
+
|
109
|
+
# it "creates an vapp with non-default CPU/Memory" do
|
110
|
+
# # Fog::Vcloud::Compute.should_receive(:new).and_return(@vcair_connection)
|
111
|
+
# @new_network = {:IpAddress => "IpAddress"}
|
112
|
+
# @new_server.stub(:network).and_return(@new_network)
|
113
|
+
# @knife_vcair_create.config[:vcair_cpus] = 'cpu'
|
114
|
+
# @knife_vcair_create.config[:vcair_memory] = 'memory'
|
115
|
+
# @new_server.should_receive(:cpu=).and_return(@new_server.cpu)
|
116
|
+
# @new_server.should_receive(:memory=).and_return(@new_server.memory)
|
117
|
+
# @new_server.should_receive(:save).exactly(3).times
|
118
|
+
|
119
|
+
# @bootstrap = Chef::Knife::Bootstrap.new
|
120
|
+
# Chef::Knife::Bootstrap.stub(:new).and_return(@bootstrap)
|
121
|
+
# @bootstrap.should_receive(:run)
|
122
|
+
# @knife_vcair_create.run
|
123
|
+
# end
|
124
|
+
|
125
|
+
# it "should bootstrap windows when bootstrap protocol is winrm" do
|
126
|
+
# # Fog::Vcloud::Compute.should_receive(:new).and_return(@vcair_connection)
|
127
|
+
# @new_server.should_receive(:save)
|
128
|
+
# @knife_vcair_create.config[:bootstrap_protocol] = 'winrm'
|
129
|
+
# @bootstrap = Chef::Knife::BootstrapWindowsWinrm.new
|
130
|
+
# Chef::Knife::BootstrapWindowsWinrm.stub(:new).and_return(@bootstrap)
|
131
|
+
# @bootstrap.should_receive(:run)
|
132
|
+
# @knife_vcair_create.run
|
133
|
+
# end
|
134
|
+
|
135
|
+
# it "should set the password on server if the image is not password enabled" do
|
136
|
+
# Fog::Vcloud::Compute.stub(:new).and_return(@vcair_connection)
|
137
|
+
# @catalog_items[0] =double(:href => "image", :password_enabled? => false)
|
138
|
+
# @new_network = {:IpAddress => "IpAddress"}
|
139
|
+
# @new_server.stub(:network).and_return(@new_network)
|
140
|
+
# @new_server.should_receive(:password=)
|
141
|
+
# @new_server.should_receive(:save).twice
|
142
|
+
# @bootstrap = Chef::Knife::Bootstrap.new
|
143
|
+
# Chef::Knife::Bootstrap.stub!(:new).and_return(@bootstrap)
|
144
|
+
# @bootstrap.should_receive(:run)
|
145
|
+
# @knife_vcair_create.run
|
146
|
+
# end
|
147
|
+
|
148
|
+
# it "should not bootstrap when no_bootstrap set" do
|
149
|
+
# Fog::Vcloud::Compute.stub(:new).and_return(@vcair_connection)
|
150
|
+
# @new_server.should_receive(:save)
|
151
|
+
# @knife_vcair_create.config[:no_bootstrap] = true
|
152
|
+
# @bootstrap = Chef::Knife::Bootstrap.new
|
153
|
+
# @bootstrap.should_not_receive(:run)
|
154
|
+
# lambda { @knife_vcair_create.run }.should raise_error SystemExit
|
155
|
+
# end
|
156
|
+
|
157
|
+
# end
|
158
|
+
# describe "run" do
|
159
|
+
# before do
|
160
|
+
# @knife_vcair_create.ui.stub(:error)
|
161
|
+
# end
|
162
|
+
# it 'should fail if compulsory params - image are not set' do
|
163
|
+
# @knife_vcair_create.config[:image] = nil
|
164
|
+
# lambda { @knife_vcair_create.run }.should raise_error SystemExit
|
165
|
+
# end
|
166
|
+
# it 'should fail if compulsory params - network are not set' do
|
167
|
+
# @knife_vcair_create.config[:vcair_network] = nil
|
168
|
+
# lambda { @knife_vcair_create.run }.should raise_error SystemExit
|
169
|
+
# end
|
170
|
+
|
171
|
+
# end
|
172
|
+
# describe "when configuring the bootstrap process" do
|
173
|
+
# before do
|
174
|
+
# @knife_vcair_create.config[:ssh_user] = "ubuntu"
|
175
|
+
# @knife_vcair_create.config[:chef_node_name] = "blarf"
|
176
|
+
# @knife_vcair_create.config[:template_file] = '~/.chef/templates/my-bootstrap.sh.erb'
|
177
|
+
# @knife_vcair_create.config[:distro] = 'ubuntu-10.04-magic-sparkles'
|
178
|
+
# @knife_vcair_create.config[:run_list] = ['role[base]']
|
179
|
+
# @knife_vcair_create.config[:json_attributes] = "{'my_attributes':{'foo':'bar'}"
|
180
|
+
# @knife_vcair_create.config[:bootstrap_protocol] = nil
|
181
|
+
|
182
|
+
# @new_server.stub(:name).and_return("server_name")
|
183
|
+
# @fqdn = mock()
|
184
|
+
# @bootstrap = @knife_vcair_create.bootstrap_for_node(@new_server, @fqdn)
|
185
|
+
# end
|
186
|
+
|
187
|
+
# it "configures sets the bootstrap's run_list" do
|
188
|
+
# @bootstrap.config[:run_list].should == ['role[base]']
|
189
|
+
# end
|
190
|
+
|
191
|
+
# it "configures the bootstrap to use the correct ssh_user login" do
|
192
|
+
# @bootstrap.config[:ssh_user].should == 'ubuntu'
|
193
|
+
# end
|
194
|
+
|
195
|
+
# it "configures the bootstrap to use the configured node name if provided" do
|
196
|
+
# @bootstrap.config[:chef_node_name].should == 'blarf'
|
197
|
+
# end
|
198
|
+
|
199
|
+
# it "configures the bootstrap to use the vcair server name if no explicit node name is set" do
|
200
|
+
# @knife_vcair_create.config[:chef_node_name] = nil
|
201
|
+
|
202
|
+
# bootstrap = @knife_vcair_create.bootstrap_for_node(@new_server, @fqdn)
|
203
|
+
# bootstrap.config[:chef_node_name].should == @new_server.name
|
204
|
+
# end
|
205
|
+
|
206
|
+
# it "configures the bootstrap to use prerelease versions of chef if specified" do
|
207
|
+
# @bootstrap.config[:prerelease].should be_false
|
208
|
+
|
209
|
+
# @knife_vcair_create.config[:prerelease] = true
|
210
|
+
|
211
|
+
# bootstrap = @knife_vcair_create.bootstrap_for_node(@new_server, @fqdn)
|
212
|
+
# bootstrap.config[:prerelease].should be_true
|
213
|
+
# end
|
214
|
+
|
215
|
+
# it "configures the bootstrap to use the desired distro-specific bootstrap script" do
|
216
|
+
# @bootstrap.config[:distro].should == 'ubuntu-10.04-magic-sparkles'
|
217
|
+
# end
|
218
|
+
|
219
|
+
# it "configures the bootstrap to use sudo" do
|
220
|
+
# @bootstrap.config[:use_sudo].should be_true
|
221
|
+
# end
|
222
|
+
|
223
|
+
# it "configured the bootstrap to use the desired template" do
|
224
|
+
# @bootstrap.config[:template_file].should == '~/.chef/templates/my-bootstrap.sh.erb'
|
225
|
+
# end
|
226
|
+
|
227
|
+
# it "configured the bootstrap to set an vcair hint (via Chef::Config)" do
|
228
|
+
# Chef::Config[:knife][:hints]["vcair"].should_not be_nil
|
229
|
+
# end
|
230
|
+
end
|
231
|
+
end
|