Class: Vcli::CLI::Modify

Inherits:
Thor
  • Object
show all
Defined in:
lib/vcli/cli/modify.rb

Instance Method Summary collapse

Instance Method Details

#ipObject



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
# File 'lib/vcli/cli/modify.rb', line 10

def ip( )
  abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target,
                      :abiquo_username => Vcli::user,
                      :abiquo_password => Vcli::password)
  vdc=options[:vdc].to_s
  va=options[:va].to_s
  vmid=options[:vmid].to_s
  vlanid=options[:vlanid].to_s
  ipid=options[:ipid].to_s
  l = AbiquoAPI::Link.new(:href => '/api/cloud/virtualdatacenters/' + vdc + '/virtualappliances/'+va+'/virtualmachines/'+vmid, 
                          :type => 'application/vnd.abiquo.virtualmachine+json',
                          :client => abq)
  vm=l.get
  link2=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/'+vdc+'/privatenetworks/'+vlanid+'/ips/'+ipid,
                                :type => 'application/vnd.abiquo.privateip+json',
                                :client => abq) 
  ips=link2.get
  while vm.state == "LOCKED" or vm.state == "ON"
    sleep 10
    puts "Waiting for Machine to Power off"
    vm=l.get
  end
  vm.link(:nic0).href=ips.url
  vm.link(:nic0).title=ips.ip
  vm.link(:nic0).rel="nic0"
  vm.link(:nic0).type="application/vnd.abiquo.privateip+json"
  reqoptions=Hash.new
  reqoptions[:accept]  = 'application/vnd.abiquo.acceptedrequest+json'
  response=abq.put(l,vm,reqoptions)
  puts "Waiting for Machine to Reconfigure"
  sleep 10
  tries ||= 5
  begin
    response2=l.get
    while response2.state == "LOCKED"
      response2=l.get
      sleep 10
      print "."
    end
  rescue Exception=> e
    retry unless (tries -= 1).zero?  
  end
end