61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/provisioner/cli.rb', line 61
def execute
options = {}
optparser = OptionParser.new do |o|
o.banner = "Usage: #{File.basename($0)} [options] <action>"
o.separator ""
o.separator "Provision a machine described by the JSON template `machine_metadata` in the vCloud organisation"
o.separator "described in the JSON config file `org_config`"
o.separator ""
o.separator "e.g. vcloud-box-spinner -u johndoe -o orgs/staging.json -m machines/frontend-1.json create"
o.separator ""
o.separator "[Available actions]:"
o.separator " #{Provisioner::AVAILABLE_ACTIONS.join(', ')}"
o.separator ""
o.separator "[Available options]:"
o.on("-c", "--credential", "=GROUP", "fog credential group") do |v|
options[:credential] = v
end
o.on("-u", "--user", "=USERNAME", "vCloud username") do |v|
options[:user] = v
end
o.on("-p", "--password", "=PASSWORD", "vCloud password") do |v|
options[:password] = v
end
o.on("-F", "--ssh-config", "=FILENAME", "SSH config file(s) to use (can be specified multiple times)") do |v|
options[:ssh_config] ||= []
options[:ssh_config].push(v)
end
options[:org_config] = {}
o.on("-o", "--org-config", "=ORG-CONFIG-JSON",
"The organisation configuration JSON file path") do |v|
options[:org_config] = MultiJson.load(File.read(v), :symbolize_names => true)
end
options[:machine_metadata] = {}
o.on("-m", "--machine-config", "=METADATA",
"The machine configuration JSON file path") do |v|
options[:machine_metadata] = MultiJson.load(File.read(v), :symbolize_names => true)
end
o.on('-s', '--setup-script', "=SETUP-SCRIPT", "path to setup script that should run after machine is brought up") do |v|
options[:setup_script] = v
end
o.on("-d", "--debug", "Enable debugging output") do
options[:debug] = true
end
o.on("-v", "--verbose", "Enable verbose output") do
options[:log_level] = 0
end
o.on_tail("-h", "--help", "Show usage instructions") do
puts o
exit
end
end
begin
optparser.parse!(@args)
if @args.length != 1
raise ConfigurationError, "#{File.basename($0)} takes one argument"
end
action = @args[0]
if options[:user] && options[:password].nil? then
options[:password] = ask("vCloud password: ") { |q| q.echo = false }
end
provisioner_opts = self.class.process(options)
provisioner = VcloudBoxProvisioner.build provisioner_opts
provisioner.execute(action)
rescue OptionParser::InvalidArgument, ConfigurationError => e
$stderr.puts "Error: #{e}"
$stderr.puts
$stderr.puts optparser
exit 1
end
end
|