Class: Vcli::CLI::Create
- Inherits:
-
Thor
- Object
- Thor
- Vcli::CLI::Create
- Defined in:
- lib/vcli/cli/create.rb
Instance Method Summary collapse
- #virtualappliance(name, vdc) ⇒ Object
- #virtualmachine(name, template, vdc, va) ⇒ Object
- #vlan(name, address, mask, gateway, vdc) ⇒ Object
Instance Method Details
#virtualappliance(name, vdc) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vcli/cli/create.rb', line 19 def virtualappliance(name,vdc) begin abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password) link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/virtualappliances' , :type => 'application/vnd.abiquo.virtualappliance+json') newvirtualappliance={name: name} response=abq.post(link,newvirtualappliance) puts "ID for Virtual Appliance - #{response.id}" rescue AbiquoAPIClient::Forbidden puts "Forbidden HTTP 403 Received" rescue AbiquoAPIClient::InvalidCredentials puts "Invalid Credentials - HTTP 401 Received" rescue AbiquoAPIClient::BadRequest puts "Bad Request - HTTP 400 or 406 Received" rescue AbiquoAPIClient::NotFound puts "Not Found - HTTP 400 Received" rescue AbiquoAPIClient::UnsupportedMediaType puts "Unsupported Media Type Specified - HTTP 415 Received" end end |
#virtualmachine(name, template, vdc, va) ⇒ Object
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 |
# File 'lib/vcli/cli/create.rb', line 75 def virtualmachine(name, template, vdc, va) begin abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password) # Link to post link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/virtualappliances/' + va + '/virtualmachines' , :type => 'application/vnd.abiquo.virtualmachine+json', :client => abq) # Link to get link for Template templatelink=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/action/templates/', :type => 'application/vnd.abiquo.virtualmachinetemplates+json', :client => abq) # Hash to populate for new virtual machine newvirtualmachine=Hash.new link2hash=Hash.new linkhash=Hash.new templates=templatelink.get templates.each {|l| if l.id.to_s == template.to_s link2hash[:title]=l.name link2hash[:rel]= "virtualmachinetemplate" link2hash[:type]="application/vnd.abiquo.virtualmachinetemplate+json" link2hash[:href]=l.url end } newvirtualmachine[:label]=name arrayforlinks=Array.new arrayforlinks[0]=link2hash newvirtualmachine[:links]=arrayforlinks cpu=[:cpu].to_s ram=[:ram].to_s vlanid=[:vlanid].to_s ipid=[:ipid].to_s description=[:description].to_s password=[:password].to_s newvirtualmachine[:cpu]= cpu if cpu.length >0 newvirtualmachine[:ram]= ram if ram.length >0 newvirtualmachine[:description]= description if description.length >0 newvirtualmachine[:password]=password if password.length >0 newvirtualmachine[:vdrpEnabled]=true # Create VirtualMachine response=abq.post(link,newvirtualmachine) puts "ID for Virtual Machine - #{response.id}" system("vcli deploy --vdc=#{vdc} --va=#{va} --vm=#{response.id}") sleep 20 puts "Powering Off VM" system("vcli poweroff --vdc=#{vdc} --va=#{va} --vm=#{response.id}") puts "Reconfiguring VM" system("vcli modify ip --vdc=#{vdc} --va=#{va} --vmid=#{response.id} --vlanid=#{vlanid} --ipid=#{ipid}") puts "Powering On VM" system("vcli poweron --vdc=#{vdc} --va=#{va} --vm=#{response.id}") puts rescue AbiquoAPIClient::Forbidden puts "Forbidden HTTP 403 Received" rescue AbiquoAPIClient::InvalidCredentials puts "Invalid Credentials - HTTP 401 Received" rescue AbiquoAPIClient::BadRequest puts "Bad Request - HTTP 400 or 406 Received" rescue AbiquoAPIClient::NotFound puts "Not Found - HTTP 400 Received" rescue AbiquoAPIClient::UnsupportedMediaType puts "Unsupported Media Type Specified - HTTP 415 Received" rescue AbiquoAPIClient::Error => e puts "Error - "+ e. end end |
#vlan(name, address, mask, gateway, vdc) ⇒ Object
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 |
# File 'lib/vcli/cli/create.rb', line 41 def vlan(name, address, mask, gateway, vdc) begin abq = AbiquoAPI.new(:abiquo_api_url => Vcli::target, :abiquo_username => Vcli::user, :abiquo_password => Vcli::password) link=AbiquoAPI::Link.new(:href => 'api/cloud/virtualdatacenters/' + vdc + '/privatenetworks' , :type => 'application/vnd.abiquo.vlan+json') # TODO Check the limits before creating new VLAN # If exceeds limit then throw an error # If within limits the create VLAN newvlan={name: name, address: address, gateway: gateway, mask: mask} response=abq.post(link,newvlan) puts "ID for VLAN - #{response.id}" rescue AbiquoAPIClient::Forbidden puts "Forbidden HTTP 403 Received" rescue AbiquoAPIClient::InvalidCredentials puts "Invalid Credentials - HTTP 401 Received" rescue AbiquoAPIClient::BadRequest puts "Bad Request - HTTP 400 or 406 Received" rescue AbiquoAPIClient::NotFound puts "Not Found - HTTP 400 Received" rescue AbiquoAPIClient::UnsupportedMediaType puts "Unsupported Media Type Specified - HTTP 415 Received" rescue AbiquoAPIClient::Error => e puts "Error - "+ e. end end |