Class: ClcMachine::Machine
- Inherits:
-
Object
- Object
- ClcMachine::Machine
- Defined in:
- lib/clc_machine.rb
Instance Attribute Summary collapse
-
#data_bag ⇒ Object
readonly
Returns the value of attribute data_bag.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#secrets ⇒ Object
readonly
Returns the value of attribute secrets.
Instance Method Summary collapse
- #connection ⇒ Object
- #delete(name) ⇒ Object
- #get(name = nil) ⇒ Object
-
#initialize(options) ⇒ Machine
constructor
A new instance of Machine.
Constructor Details
#initialize(options) ⇒ Machine
Returns a new instance of Machine.
11 12 13 14 15 16 |
# File 'lib/clc_machine.rb', line 11 def initialize() = set_chef() @data_bag = DataBag.new([:stamp]) @secrets = SecretDataBag.new([:stamp]) end |
Instance Attribute Details
#data_bag ⇒ Object (readonly)
Returns the value of attribute data_bag.
19 20 21 |
# File 'lib/clc_machine.rb', line 19 def data_bag @data_bag end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
18 19 20 |
# File 'lib/clc_machine.rb', line 18 def end |
#secrets ⇒ Object (readonly)
Returns the value of attribute secrets.
20 21 22 |
# File 'lib/clc_machine.rb', line 20 def secrets @secrets end |
Instance Method Details
#connection ⇒ Object
22 23 24 |
# File 'lib/clc_machine.rb', line 22 def connection RbVmomi::VIM.connect end |
#delete(name) ⇒ Object
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 |
# File 'lib/clc_machine.rb', line 36 def delete(name) if name.is_a?(String) vm = get(name) if vm config = Chef::Config.merge!({ :driver_options => }) machine_spec = ChefMetal::ChefMachineSpec.new({'name' => name}, Cheffish.default_chef_server(config)) driver = ChefMetal.driver_for_url("vsphere://#{vsphere_options[:host]}", config) action_handler = ChefMetal::ActionHandler.new machine_spec.location = { 'driver_url' => driver.driver_url, 'server_id' => vm.config.instanceUuid} chef_server = Cheffish.default_chef_server(config) begin driver.destroy_machine(action_handler, machine_spec, :convergence_options => { :chef_server => chef_server }) rescue Chef::Exceptions::PrivateKeyMissing, Net::HTTPServerException, Errno::ETIMEDOUT puts "Unable to delete node on the chef server. See previous message." end puts "succesfully deleted #{name}" else puts "VM #{name} does not exist. I shall destroy nothing." end else to_be_deleted = [] print 'Looking for matching machines ' get.each do |v| check = v['name'] print '.' if name.match(check) to_be_deleted.push(check) end end if to_be_deleted.count > 0 puts "\nReady to delete #{to_be_deleted.inspect}" confirm = ask("Continue? (Y/N) ") { |q| q.validate = /\A[yYnN]\Z/ } if confirm.downcase == 'y' to_be_deleted.each do |m| delete m end else puts 'No action taken. Exiting.' exit 0 end else puts "\nNo matching machines found. Exiting." exit 0 end end end |
#get(name = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/clc_machine.rb', line 26 def get(name = nil) stamp = data_bag.vsphere_datacenter([:hypervisor_type]) if name find_vm(stamp, [:folder], name) else folder = find_folder(stamp, [:folder]) folder.childEntity.each end end |