This file is indexed.

/usr/bin/onevcenter is in opennebula-tools 4.12.3+dfsg-3.1build1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#!/usr/bin/env ruby

# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs        #
#                                                                            #
# 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.                                             #
#--------------------------------------------------------------------------- #

ONE_LOCATION=ENV["ONE_LOCATION"]

if !ONE_LOCATION
    RUBY_LIB_LOCATION="/usr/lib/one/ruby"
    REMOTES_LOCATION="/var/lib/one/remotes/"
else
    RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
    REMOTES_LOCATION=ONE_LOCATION+"/var/remotes/"
end

$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+"/cli"
$: << REMOTES_LOCATION+"vmm/vcenter/"

require 'command_parser'
require 'one_helper/onehost_helper'
require 'one_helper/onecluster_helper'
require 'vcenter_driver'

cmd=CommandParser::CmdParser.new(ARGV) do

    usage "`onevcenter` <command> [<args>] [<options>]"
    version OpenNebulaHelper::ONE_VERSION

    helper = OneHostHelper.new

    before_proc do
        helper.set_client(options)
    end

    ########################################################################
    # Global Options
    ########################################################################
    cmd_options=CommandParser::OPTIONS-[CommandParser::VERBOSE]
    set :option, cmd_options+OpenNebulaHelper::CLIENT_OPTIONS


    VCENTER = {
        :name   => "vcenter",
        :large  => "--vcenter vCenter" ,
        :description => "The vCenter hostname",
        :format => String
    }

    USER = {
        :name   => "vuser",
        :large  => "--vuser username" ,
        :description => "The username to interact with vCenter",
        :format => String
    }

    PASS = {
        :name   => "vpass",
        :large  => "--vpass password",
        :description => "The password for the user",
        :format => String
    }

    ############################################################################
    # Import clusters
    ############################################################################
    hosts_desc = <<-EOT.unindent
        Import vCenter clusters as OpenNebula hosts
    EOT

    command :hosts, hosts_desc, :options=>[ VCENTER, USER, PASS ] do
        if  options[:vuser].nil? ||
            options[:vpass].nil? ||
            options[:vcenter].nil?
            STDERR.puts "vCenter connection parameters are mandatory to import"\
                        " host:\n"\
                        "\t --vcenter vCenter hostname\n"\
                        "\t --vuser username to login in vcenter\n"\
                        "\t --vpass password for the user"
            exit -1
        end

        begin
            STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."

            vc = VCenterDriver::VIClient.new_connection(
                    :user     => options[:vuser],
                    :password => options[:vpass],
                    :host     => options[:vcenter])

            STDOUT.print "done!\n\n"

            STDOUT.print "Exploring vCenter resources..."

            rs = vc.hierarchy

            STDOUT.print "done!\n\n"

            rs.each {|dc, cluster|
                STDOUT.print "Do you want to process datacenter #{dc} [y/n]? "

                next if STDIN.gets.strip.downcase != 'y'

                if cluster.empty?
                    STDOUT.puts "    No clusters found in #{dc}..."
                    next
                end

                cluster.each{ |c|
                    STDOUT.print "  * Import cluster #{c} [y/n]? "

                    next if STDIN.gets.strip.downcase != 'y'

                    r, m = VCenterDriver::VCenterHost.to_one(c, vc)

                    if r == 0
                        STDOUT.puts "    OpenNebula host #{c} with id #{m}"\
                            " successfully created."
                    else
                        STDOUT.puts "    Error: #{m}"
                    end

                    STDOUT.puts
                }
            }
        rescue Exception => e
            STDOUT.puts "error: #{e.message}"
            exit -1
        end

        exit 0
    end

    templates_desc = <<-EOT.unindent
        Import vCenter VM Templates into OpenNebula
    EOT

    command :templates, templates_desc, :options=>[ VCENTER, USER, PASS ] do
        if  options[:vuser].nil? ||
            options[:vpass].nil? ||
            options[:vcenter].nil?
            STDERR.puts "vCenter connection parameters are mandatory to import"\
                        " VM templates:\n"\
                        "\t --vcenter vCenter hostname\n"\
                        "\t --vuser username to login in vcenter\n"\
                        "\t --vpass password for the user"
            exit -1
        end

        begin
            STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."

            vc = VCenterDriver::VIClient.new_connection(
                    :user     => options[:vuser],
                    :password => options[:vpass],
                    :host     => options[:vcenter])

            STDOUT.print "done!\n\n"

            STDOUT.print "Looking for VM Templates..."

            rs = vc.vm_templates

            STDOUT.print "done!\n"

            rs.each {|dc, tmps|
                STDOUT.print "\nDo you want to process datacenter #{dc} [y/n]? "

                next if STDIN.gets.strip.downcase != 'y'

                if tmps.empty?
                    STDOUT.print "    No new VM Templates found in #{dc}...\n\n"
                    next
                end

                tmps.each{ |t|
                    STDOUT.print "\n  * VM Template found:\n"\
                                 "      - Name   : #{t[:name]}\n"\
                                 "      - UUID   : #{t[:uuid]}\n"\
                                 "      - Cluster: #{t[:host]}\n"\
                                 "    Import this VM template [y/n]? "

                    next if STDIN.gets.strip.downcase != 'y'

                    one_t = ::OpenNebula::Template.new(
                                ::OpenNebula::Template.build_xml, vc.one)

                    rc = one_t.allocate(t[:one])

                    if ::OpenNebula.is_error?(rc)
                        STDOUT.puts "    Error creating template: #{rc.message}\n"
                    else
                        STDOUT.puts "    OpenNebula template #{one_t.id} created!\n"
                    end
                }
            }
        rescue Exception => e
            STDOUT.puts "error: #{e.message}"
            exit -1
        end

        exit 0
    end

    vms_desc = <<-EOT.unindent
        Import vCenter running Virtual Machines into OpenNebula
    EOT

    command :vms, vms_desc, :options=>[ VCENTER, USER, PASS ] do
        if  options[:vuser].nil? ||
            options[:vpass].nil? ||
            options[:vcenter].nil?
            STDERR.puts "vCenter connection parameters are mandatory to import"\
                        " VM templates:\n"\
                        "\t --vcenter vCenter hostname\n"\
                        "\t --vuser username to login in vcenter\n"\
                        "\t --vpass password for the user"
            exit -1
        end

        begin
            STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."

            vc = VCenterDriver::VIClient.new_connection(
                    :user     => options[:vuser],
                    :password => options[:vpass],
                    :host     => options[:vcenter])

            STDOUT.print "done!\n\n"

            STDOUT.print "Looking for running Virtual Machines..."

            rs = vc.running_vms

            STDOUT.print "done!\n"

            rs.each {|dc, tmps|
                STDOUT.print "\nDo you want to process datacenter #{dc} [y/n]? "

                next if STDIN.gets.strip.downcase != 'y'

                if tmps.empty?
                    STDOUT.print "    No new running Virtual Machines found in"\
                                 " #{dc}...\n\n"
                    next
                end

                tmps.each{ |v|
                    STDOUT.print "\n  * Running Virtual Machine found:\n"\
                                 "      - Name   : #{v[:name]}\n"\
                                 "      - UUID   : #{v[:uuid]}\n"\
                                 "      - Cluster: #{v[:host]}\n"\
                                 "    Import this Virtual Machine [y/n]? "

                    next if STDIN.gets.strip.downcase != 'y'

                    one_v = ::OpenNebula::VirtualMachine.new(
                                ::OpenNebula::VirtualMachine.build_xml, vc.one)

                    rc = one_v.allocate(v[:one])

                    if ::OpenNebula.is_error?(rc)
                        STDOUT.puts "    Error creating Virtual Machine: "\
                                    "#{rc.message}\n"
                    end

                    rc = one_v.deploy v[:host_id]

                    if ::OpenNebula.is_error?(rc)
                        STDOUT.puts "    Error creating Virtual Machine: "\
                                    "#{rc.message}\n"
                    else
                        STDOUT.puts "    OpenNebula VM #{one_v.id} "\
                                    "created!\n"
                    end
                }
            }
        rescue Exception => e
            STDOUT.puts "error: #{e.message}"
            exit -1
        end

        exit 0
    end

    network_desc = <<-EOT.unindent
        Import vCenter networks into OpenNebula
    EOT

    command :networks, network_desc, :options=>[ VCENTER, USER, PASS ] do
        if  options[:vuser].nil? ||
            options[:vpass].nil? ||
            options[:vcenter].nil?
            STDERR.puts "vCenter connection parameters are mandatory to import"\
                        " vCenter networks:\n"\
                        "\t --vcenter vCenter hostname\n"\
                        "\t --vuser username to login in vcenter\n"\
                        "\t --vpass password for the user"
            exit -1
        end

        begin
            STDOUT.print "\nConnecting to vCenter: #{options[:vcenter]}..."

            vc = VCenterDriver::VIClient.new_connection(
                    :user     => options[:vuser],
                    :password => options[:vpass],
                    :host     => options[:vcenter])

            STDOUT.print "done!\n\n"

            STDOUT.print "Looking for vCenter networks..."

            rs = vc.vcenter_networks

            STDOUT.print "done!\n"

            rs.each {|dc, tmps|
                STDOUT.print "\nDo you want to process datacenter #{dc} [y/n]? "

                next if STDIN.gets.strip.downcase != 'y'

                if tmps.empty?
                    STDOUT.print "    No new Networks found in #{dc}...\n\n"
                    next
                end

                tmps.each{ |n|
                    print_str =  "\n  * Network found:\n"\
                                 "      - Name    : #{n[:name]}\n"\
                                 "      - Type    : #{n[:type]}\n"
                    print_str += "      - VLAN ID : #{n[:vlan]}\n" if n[:vlan]
                    print_str += "    Import this Network [y/n]? "

                    STDOUT.print print_str

                    next if STDIN.gets.strip.downcase != 'y'

                    # Size

                    STDOUT.print "    How many VMs are you planning"\
                                 " to fit into this network [255]? "

                    size = STDIN.gets.strip

                    size = "255" if size.to_i.to_s != size

                    # Type

                    STDOUT.print "    What type of Virtual Network"\
                                 " do you want to create (IPv[4],IPv[6]"\
                                 ",[E]thernet) ?"

                    type = STDIN.gets.strip

                    ar_str =  "\nAR=[TYPE=\""

                    case type.downcase
                        when "4"
                            ar_str += "IP4\""
                            STDOUT.print "    Please input the first IP "\
                                         "in the range: "
                            ip = STDIN.gets.strip
                            ar_str += ",IP=" + ip

                            STDOUT.print "    Please input the first MAC "\
                                         "in the range [Enter for default]: "
                            mac = STDIN.gets.strip
                            ar_str += ",MAC=" + mac if !mac.empty?
                        when "6"
                            ar_str += "IP6\""
                            STDOUT.print "    Please input the first MAC "\
                                         "in the range [Enter for default]: "
                            mac = STDIN.gets.strip
                            ar_str += ",MAC=" + mac if !mac.empty?

                            STDOUT.print "    Please input the GLOBAL PREFIX "\
                                         "[Enter for default]: "
                            gp = STDIN.gets.strip
                            ar_str += ",GLOBAL_PREFIX=" + gp if !gp.empty?

                            STDOUT.print "    Please input the ULA PREFIX "\
                                         "[Enter for default]: "
                            up = STDIN.gets.strip
                            ar_str += ",ULA_PREFIX=" + up if !up.empty?
                        when "e"
                            ar_str += "ETHER\""
                            STDOUT.print "    Please input the first MAC "\
                                 "in the range [Enter for default]: "
                            mac = STDIN.gets.strip
                            ar_str += ",MAC=" + mac if !mac.empty?
                        else
                         STDOUT.puts "    Type [#{type}] not supported,"\
                                    " defaulting to Ethernet."
                         ar_str += "ETHER\""
                         STDOUT.print "    Please input the first MAC "\
                              "in the range [Enter for default]: "
                         mac = STDIN.gets.strip
                         ar_str += ",MAC=" + mac if !mac.empty?
                    end

                    ar_str += ",SIZE = \"#{size}\"]"

                    one_vn = ::OpenNebula::VirtualNetwork.new(
                                ::OpenNebula::Template.build_xml, vc.one)

                    vnet_template =  n[:one] + ar_str
                    
                    rc = one_vn.allocate(vnet_template)

                    if ::OpenNebula.is_error?(rc)
                        STDOUT.puts "    Error creating virtual network: " +
                                    " #{rc.message}\n"
                    else
                        STDOUT.puts "    OpenNebula virtual network " + 
                                    "#{one_vn.id} created with size #{size}!\n"
                    end
                }
            }
        rescue Exception => e
            STDOUT.puts "error: #{e.message}"
            exit -1
        end

        exit 0
    end
end