knife-vcair 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Author:: TODO
|
2
|
+
# Copyright::
|
3
|
+
|
4
|
+
require 'bundler'
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubygems/package_task'
|
9
|
+
|
10
|
+
task :default => :all
|
11
|
+
task :all => [:spec, :uninstall, :install]
|
12
|
+
|
13
|
+
# Packaging
|
14
|
+
GEM_NAME = "knife-vcair"
|
15
|
+
require File.dirname(__FILE__) + '/lib/knife-vcair/version'
|
16
|
+
spec = eval(File.read("knife-vcair.gemspec"))
|
17
|
+
Gem::PackageTask.new(spec) do |pkg|
|
18
|
+
pkg.gem_spec = spec
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "uninstall #{GEM_NAME}-#{Knife::Vcair::VERSION}.gem from system..."
|
22
|
+
task :uninstall do
|
23
|
+
sh %{gem uninstall #{GEM_NAME} -x -v #{Knife::Vcair::VERSION} }
|
24
|
+
end
|
25
|
+
|
26
|
+
# rspec
|
27
|
+
begin
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
desc "Run all specs in spec directory"
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
31
|
+
t.pattern = 'spec/unit/**/*_spec.rb'
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
STDERR.puts "\n*** RSpec not available. (sudo) gem install rspec to run unit tests. ***\n\n"
|
35
|
+
end
|
data/example.env
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
# Cargo culted from https://github.com/opscode/opscode-omnitruck/blob/master/views/install.sh.erb
|
3
|
+
|
4
|
+
if test -f "/etc/lsb-release" && grep -q DISTRIB_ID /etc/lsb-release; then
|
5
|
+
platform=`grep DISTRIB_ID /etc/lsb-release | cut -d "=" -f 2 | tr '[A-Z]' '[a-z]'`
|
6
|
+
platform_version=`grep DISTRIB_RELEASE /etc/lsb-release | cut -d "=" -f 2`
|
7
|
+
elif test -f "/etc/debian_version"; then
|
8
|
+
platform="debian"
|
9
|
+
platform_version=`cat /etc/debian_version`
|
10
|
+
elif test -f "/etc/redhat-release"; then
|
11
|
+
platform=`sed 's/^\(.\+\) release.*/\1/' /etc/redhat-release | tr '[A-Z]' '[a-z]'`
|
12
|
+
platform_version=`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release`
|
13
|
+
fi
|
14
|
+
|
15
|
+
if test "$platform" = "ubuntu"; then
|
16
|
+
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
|
17
|
+
sed -i 's/dns.*/dns-nameservers 8.8.8.8 8.8.4.4/g' /etc/network/interfaces
|
18
|
+
fi
|
19
|
+
|
20
|
+
if test "$platform" = "centos"; then
|
21
|
+
printf "nameserver 8.8.8.8\nnameserver 8.8.4.4" >> /etc/resolv.conf
|
22
|
+
fi
|
@@ -0,0 +1,36 @@
|
|
1
|
+
@echo off
|
2
|
+
|
3
|
+
if “%1%” == “precustomization” (
|
4
|
+
@rem First Boot
|
5
|
+
echo Do precustomization tasks
|
6
|
+
cmd.exe /c winrm quickconfig -q
|
7
|
+
cmd.exe /c winrm quickconfig -transport:http
|
8
|
+
cmd.exe /c winrm set winrm/config @{MaxTimeoutms="1800000"}
|
9
|
+
cmd.exe /c winrm set winrm/config/winrs @{MaxMemoryPerShellMB="300"}
|
10
|
+
cmd.exe /c winrm set winrm/config/service @{AllowUnencrypted="true"}
|
11
|
+
cmd.exe /c winrm set winrm/config/service/auth @{Basic="true"}
|
12
|
+
cmd.exe /c winrm set winrm/config/client/auth @{Basic="true"}
|
13
|
+
cmd.exe /c winrm set winrm/config/listener?Address=*+Transport=HTTP @{Port="5985"}
|
14
|
+
@rem Make sure winrm is off for this boot, but enabled on next
|
15
|
+
cmd.exe /c net stop winrm
|
16
|
+
cmd.exe /c sc config winrm start= auto
|
17
|
+
cmd.exe /c net accounts /maxpwage:unlimited
|
18
|
+
echo %DATE% %TIME% > C:\vm-is-customized
|
19
|
+
|
20
|
+
) else if “%1%” == “postcustomization” (
|
21
|
+
@rem Second Boot / start winrm, just incase, and fix firewall
|
22
|
+
cmd.exe /c net start winrm
|
23
|
+
cmd.exe /c netsh advfirewall firewall set rule group="remote administration" new enable=yes
|
24
|
+
cmd.exe /c netsh advfirewall firewall set rule name="WinRM" profile=public protocol=tcp localport=5985 remoteip=localsubnet new remoteip=any
|
25
|
+
cmd.exe /c reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
|
26
|
+
cmd.exe /c netsh advfirewall firewall set rule name="RDP" profile=public protocol=tcp localport=3389 remoteip=localsubnet new remoteip=any
|
27
|
+
|
28
|
+
@rem Password Setting, Force Password Change, and Autologin currently seem broken
|
29
|
+
@rem Forcing the password here at least allows us to connect remotely
|
30
|
+
cmd.exe /c net user administrator Password1
|
31
|
+
@rem Incase DNS failed to be set
|
32
|
+
@rem cmd.exe /c netsh interface ipv4 add dnsserver "Ethernet" address=8.8.8.8
|
33
|
+
@rem cmd.exe /c netsh interface ipv4 add dnsserver "Ethernet0" address=8.8.8.8
|
34
|
+
echo %DATE% %TIME% > C:\vm-is-ready
|
35
|
+
|
36
|
+
)
|
data/knife-vcair.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "knife-vcair/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "knife-vcair"
|
7
|
+
s.version = Knife::Vcair::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.extra_rdoc_files = ["README.md", "LICENSE" ]
|
11
|
+
s.authors = ["Matt Ray", "Chris McClimans", "Taylor Carpenter", "Wavell Watson", "eth Thomas"]
|
12
|
+
s.email = ["matt@chef.io", "wolfpack@vulk.co", "sthomas@chef.io"]
|
13
|
+
s.homepage = "https://github.com/chef-partners/knife-vcair"
|
14
|
+
s.summary = %q{VMware vcair support for Chef's Knife command}
|
15
|
+
s.description = s.summary
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "fog", ">= 1.23"
|
23
|
+
s.add_dependency "knife-cloud", ">= 1.0.1"
|
24
|
+
s.add_dependency "knife-windows", ">= 0.8.3"
|
25
|
+
|
26
|
+
s.add_development_dependency 'chef', '>= 11.16.2', '< 12'
|
27
|
+
s.add_development_dependency 'rspec', '~> 2.14'
|
28
|
+
s.add_development_dependency 'rake', '~> 10.1'
|
29
|
+
s.add_development_dependency 'guard-rspec', ["~> 4.2"]
|
30
|
+
s.add_development_dependency 'activesupport'
|
31
|
+
|
32
|
+
%w(rspec-core rspec-expectations rspec-mocks rspec_junit_formatter).each { |gem|
|
33
|
+
s.add_development_dependency gem
|
34
|
+
}
|
35
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Author:: "Vulk Wolfpack" <wolfpack@vulk.co>
|
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/create_options'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class Cloud
|
24
|
+
module VcairServerCreateOptions
|
25
|
+
|
26
|
+
def self.included(includer)
|
27
|
+
includer.class_eval do
|
28
|
+
include ServerCreateOptions
|
29
|
+
|
30
|
+
# availble in knife.rb -short
|
31
|
+
option :vcair_customization_script,
|
32
|
+
:long => "--customization-script SCRIPTFILE",
|
33
|
+
:short => "-B SCRIPTFILE",
|
34
|
+
:description => "The Bat or Shell script to provision the instance with",
|
35
|
+
:default => nil,
|
36
|
+
:proc => Proc.new { |o| Chef::Config[:knife][:vcair_customization_script] = o }
|
37
|
+
|
38
|
+
option :vcair_cpus,
|
39
|
+
:long => "--cpus CPUS",
|
40
|
+
:short => "-C CPUS",
|
41
|
+
:description => "Defines the number of vCPUS per VM. Possible values are 1,2,4,8",
|
42
|
+
:proc => Proc.new { |o| Chef::Config[:knife][:vcair_cpus] = o }
|
43
|
+
|
44
|
+
option :vcair_memory,
|
45
|
+
:long => "--memory MEMORY",
|
46
|
+
:short => "-M MEMORY",
|
47
|
+
:description => "Defines the number of MB of memory. [512,1024,1536,2048,4096,8192,12288,16384]",
|
48
|
+
:proc => Proc.new { |o| Chef::Config[:knife][:vcair_memory] = o }
|
49
|
+
|
50
|
+
option :vcair_net,
|
51
|
+
:long => "--vcair-net NETWORKNAME",
|
52
|
+
:description => "Your VCAIR NETWORK",
|
53
|
+
:default => nil,
|
54
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:vcair_net] = key }
|
55
|
+
|
56
|
+
# TODO - Define your cloud specific create server options here. Example.
|
57
|
+
# Vcair Server create params.
|
58
|
+
# option :private_network,
|
59
|
+
#:long => "--vcair-private-network",
|
60
|
+
#:description => "Use the private IP for bootstrapping rather than the public IP",
|
61
|
+
#:boolean => true,
|
62
|
+
#:default => false
|
63
|
+
# option :public_ip,
|
64
|
+
#:long => "--vcair-public-ip",
|
65
|
+
#:description => "Public IP from the avaliable pool to setup SNAT/DNAT for
|
66
|
+
#:default => nil
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
# Author:: "Vulk Wolfpack" <wolfpack@vulk.co>
|
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/fog/service'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class Cloud
|
24
|
+
class VcairService < FogService
|
25
|
+
|
26
|
+
def initialize(options = {})
|
27
|
+
Chef::Log.debug("vcair_username #{Chef::Config[:knife][:vcair_username]}")
|
28
|
+
Chef::Log.debug("vcair_org #{Chef::Config[:knife][:vcair_org]}")
|
29
|
+
Chef::Log.debug("vcair_api_host #{Chef::Config[:knife][:vcair_api_host]}")
|
30
|
+
Chef::Log.debug("vcair_api_version #{Chef::Config[:knife][:vcair_api_version]}")
|
31
|
+
Chef::Log.debug("vcair_show_progress #{Chef::Config[:knife][:vcair_show_progress]}")
|
32
|
+
|
33
|
+
username = [
|
34
|
+
Chef::Config[:knife][:vcair_username],
|
35
|
+
Chef::Config[:knife][:vcair_org]
|
36
|
+
].join('@')
|
37
|
+
|
38
|
+
super(options.merge({
|
39
|
+
:auth_params => {
|
40
|
+
:provider => 'vclouddirector',
|
41
|
+
:vcloud_director_username => username,
|
42
|
+
:vcloud_director_password => Chef::Config[:knife][:vcair_password],
|
43
|
+
:vcloud_director_host => Chef::Config[:knife][:vcair_api_host],
|
44
|
+
:vcloud_director_api_version => Chef::Config[:knife][:vcair_api_version],
|
45
|
+
:vcloud_director_show_progress => false
|
46
|
+
}
|
47
|
+
}))
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_api_endpoint
|
51
|
+
@auth_params.merge!({:vcair_api_host => Chef::Config[:knife][:vcair_api_host]}) unless Chef::Config[:knife][:api_endpoint].nil?
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# Author:: "Vulk Wolfpack" <wolfpack@vulk.co>
|
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/fog/options'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class Cloud
|
24
|
+
module VcairServiceOptions
|
25
|
+
|
26
|
+
def self.included(includer)
|
27
|
+
includer.class_eval do
|
28
|
+
include FogOptions
|
29
|
+
|
30
|
+
# vcair connection params
|
31
|
+
option :vcair_api_version,
|
32
|
+
:long => "--vcair-api-version VERSION",
|
33
|
+
:description => "The VCAIR API version",
|
34
|
+
:default => '5.6',
|
35
|
+
:proc => Proc.new { |u| Chef::Config[:knife][:vcair_api_version] = u }
|
36
|
+
|
37
|
+
option :vcair_api_host,
|
38
|
+
:short => "-U API_HOST",
|
39
|
+
:long => "--vcair-api-host HOST",
|
40
|
+
:description => "The VCAIR API endpoint",
|
41
|
+
:proc => Proc.new { |u| Chef::Config[:knife][:vcair_api_host] = u }
|
42
|
+
|
43
|
+
option :vcair_org,
|
44
|
+
:short => "-O ORG",
|
45
|
+
:long => "--vcair-org ORG",
|
46
|
+
:description => "The VCAIR ORG",
|
47
|
+
:proc => Proc.new { |u| Chef::Config[:knife][:vcair_org] = u }
|
48
|
+
|
49
|
+
option :vcair_username,
|
50
|
+
:short => "-A USERNAME",
|
51
|
+
:long => "--vcair-username USERNAME",
|
52
|
+
:description => "Your VCAIR username",
|
53
|
+
:proc => Proc.new { |username| Chef::Config[:knife][:vcair_username] = username }
|
54
|
+
|
55
|
+
option :vcair_password,
|
56
|
+
:short => "-K PASSWORD",
|
57
|
+
:long => "--vcair-password PASSWORD",
|
58
|
+
:description => "Your VCAIR password",
|
59
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:vcair_password] = key }
|
60
|
+
|
61
|
+
option :vcair_vdc,
|
62
|
+
:long => "--vcair-vdc VDCNAME",
|
63
|
+
:description => "Your VCAIR VDC",
|
64
|
+
:default => nil,
|
65
|
+
:proc => Proc.new { |key| Chef::Config[:knife][:vcair_vdc] = key }
|
66
|
+
|
67
|
+
option :vcair_show_progress,
|
68
|
+
:long => "--vcair-show-progress BOOL",
|
69
|
+
:description => "Show VCAIR API Progress",
|
70
|
+
:default => false
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#
|
2
|
+
# Author:: "Vulk Wolfpack" <wolfpack@vulk.co>
|
3
|
+
# Copyright:: Chef Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'chef/knife/cloud/vcair_service_options'
|
7
|
+
|
8
|
+
class Chef
|
9
|
+
class Knife
|
10
|
+
class Cloud
|
11
|
+
module VcairHelpers
|
12
|
+
|
13
|
+
def create_service_instance
|
14
|
+
VcairService.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def org
|
18
|
+
@org ||= @service.connection.organizations.get_by_name(
|
19
|
+
config_value(:vcair_org))
|
20
|
+
end
|
21
|
+
|
22
|
+
def vdc
|
23
|
+
if config_value(:vcair_vdc)
|
24
|
+
@vdc ||= org.vdcs.get_by_name(config_value(:vcair_vdc))
|
25
|
+
else
|
26
|
+
@vdc ||= org.vdcs.first
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def net
|
31
|
+
if config_value(:vcair_net)
|
32
|
+
@net ||= org.networks.get_by_name(config_value(:vcair_net))
|
33
|
+
else
|
34
|
+
# Grab first non-isolated (bridged, natRouted) network
|
35
|
+
@net ||= org.networks.find { |n| n if !n.fence_mode.match("isolated") }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def template
|
40
|
+
# TODO: find by catalog item ID and/or NAME
|
41
|
+
# TODO: add option to search just public and/or private catalogs
|
42
|
+
@template ||= org.catalogs.map do |cat|
|
43
|
+
cat.catalog_items.get_by_name(config_value(:image))
|
44
|
+
end.compact.first
|
45
|
+
end
|
46
|
+
|
47
|
+
def vapp
|
48
|
+
@vapp ||= vdc.vapps.get_by_name(config_value(:chef_node_name))
|
49
|
+
end
|
50
|
+
|
51
|
+
def vm
|
52
|
+
@vm ||= vapp.vms.find {|v| v.vapp_name == config_value(:chef_node_name)}
|
53
|
+
end
|
54
|
+
|
55
|
+
def network_config
|
56
|
+
@network_config ||= vapp.network_config.find do |n|
|
57
|
+
n if n[:networkName].match(net.name)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def config_value(key)
|
63
|
+
key = key.to_sym
|
64
|
+
Chef::Config[:knife][key] || config[key]
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_id(value)
|
68
|
+
value['id']
|
69
|
+
end
|
70
|
+
|
71
|
+
def msg_pair(label, value, color=:cyan)
|
72
|
+
if value && !value.to_s.empty?
|
73
|
+
puts "#{ui.color(label, color)}: #{value}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def validate!(keys=[:vcair_username, :vcair_password, :vcair_api_host, :vcair_org, :vcair_api_version])
|
78
|
+
errors = []
|
79
|
+
keys.each do |k|
|
80
|
+
pretty_key = k.to_s.gsub(/_/, ' ').gsub(/\w+/){ |w| (w =~ /(ssh)/i) ? w.upcase : w.capitalize }
|
81
|
+
if config_value(k).nil?
|
82
|
+
errors << "You did not provide a valid '#{pretty_key}' value. Please set knife[:#{k}] in your knife.rb or pass as an option."
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
if errors.each{|e| ui.error(e)}.any?
|
87
|
+
exit 1
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -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/list_resource_command'
|
20
|
+
require 'chef/knife/vcair_helpers'
|
21
|
+
require 'chef/knife/cloud/vcair_service_options'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Knife
|
25
|
+
class Cloud
|
26
|
+
class VcairImageList < ResourceListCommand
|
27
|
+
include VcairHelpers
|
28
|
+
include VcairServiceOptions
|
29
|
+
|
30
|
+
banner "knife vcair image list (options)"
|
31
|
+
|
32
|
+
def query_resource
|
33
|
+
images = []
|
34
|
+
org.catalogs.each do |catalog|
|
35
|
+
images << catalog.catalog_items.all
|
36
|
+
end
|
37
|
+
images.flatten
|
38
|
+
end
|
39
|
+
|
40
|
+
def before_exec_command
|
41
|
+
@columns_with_info = [
|
42
|
+
{:label => 'Name', :key => 'name'},
|
43
|
+
{:label => 'Description', :key => 'description'}
|
44
|
+
]
|
45
|
+
@sort_by_field = "name"
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|