Class: VagrantPlugins::Deltacloud::DeltacloudClient
- Inherits:
-
Object
- Object
- VagrantPlugins::Deltacloud::DeltacloudClient
- Defined in:
- lib/vagrant-deltacloud-provider/client/deltacloud.rb
Instance Method Summary collapse
- #add_public_key(env, name, public_key) ⇒ Object
- #attach_volume(env, volume_id) ⇒ Object
- #create_snapshot(env, instance_id, image_name) ⇒ Object
- #create_volume(env, volume_name, volume_size_in_gbs) ⇒ Object
- #delete_public_key(env, key_id) ⇒ Object
- #destroy_instance(env, instance_id) ⇒ Object
- #destroy_snapshot(env, image_id) ⇒ Object
- #destroy_volume(env, volume_id) ⇒ Object
- #detach_volume(env, volume_id) ⇒ Object
- #get_instance_details(env, instance_id) ⇒ Object
-
#initialize ⇒ DeltacloudClient
constructor
A new instance of DeltacloudClient.
- #launch_instance(env, name, image_id, size_id, public_key_name) ⇒ Object
- #list_hardware_profiles(env) ⇒ Object
- #list_images(env) ⇒ Object
- #list_instances(env) ⇒ Object
- #list_networks(env) ⇒ Object
- #list_public_keys(env) ⇒ Object
- #list_volumes(env) ⇒ Object
- #reboot_instance(env, instance_id) ⇒ Object
- #start_instance(env, instance_id) ⇒ Object
- #stop_instance(env, instance_id) ⇒ Object
- #volume_info(env, volume_id) ⇒ Object
Methods included from HttpUtils
Methods included from HttpUtils::RequestLogger
Constructor Details
#initialize ⇒ DeltacloudClient
Returns a new instance of DeltacloudClient.
14 15 16 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 14 def initialize @logger = Log4r::Logger.new('vagrant_deltacloud::deltacloud') end |
Instance Method Details
#add_public_key(env, name, public_key) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 23 def add_public_key(env, name, public_key) response = post( env, '/keys', 'name' => name, 'public_key' => public_key ) JSON.parse(response) end |
#attach_volume(env, volume_id) ⇒ Object
127 128 129 130 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 127 def attach_volume(env, volume_id) response = post(env, '/storage_volumes/' + volume_id + '/attach') JSON.parse(response) end |
#create_snapshot(env, instance_id, image_name) ⇒ Object
147 148 149 150 151 152 153 154 155 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 147 def create_snapshot(env, instance_id, image_name) response = post( env, '/images', 'instance_id' => instance_id, 'name' => image_name ) JSON.parse(response) end |
#create_volume(env, volume_name, volume_size_in_gbs) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 109 def create_volume(env, volume_name, volume_size_in_gbs) response = post( env, '/storage_volumes', 'name' => volume_name, 'capacity' => volume_size_in_gbs ) JSON.parse(response) end |
#delete_public_key(env, key_id) ⇒ Object
33 34 35 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 33 def delete_public_key(env, key_id) delete(env, '/keys/' + key_id) end |
#destroy_instance(env, instance_id) ⇒ Object
105 106 107 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 105 def destroy_instance(env, instance_id) delete(env, '/instances/' + instance_id) end |
#destroy_snapshot(env, image_id) ⇒ Object
157 158 159 160 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 157 def destroy_snapshot(env, image_id) response = delete(env, '/images/' + image_id) JSON.parse(response) end |
#destroy_volume(env, volume_id) ⇒ Object
142 143 144 145 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 142 def destroy_volume(env, volume_id) response = delete(env, '/storage_volumes/' + volume_id) JSON.parse(response) end |
#detach_volume(env, volume_id) ⇒ Object
137 138 139 140 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 137 def detach_volume(env, volume_id) response = post(env, '/storage_volumes/' + volume_id + '/detach') JSON.parse(response) end |
#get_instance_details(env, instance_id) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 65 def get_instance_details(env, instance_id) instance_details = get(env, '/instances/' + instance_id) i = JSON.parse(instance_details)['instance'] ip_address = nil ip_address = i['private_addresses'][0]['address'] if i['private_addresses'][0] ip_address = i['public_addresses'][0]['address'] if i['public_addresses'][0] Instance.new(i['id'], i['name'], i['state'], i['authentication']['keyname'], ip_address) end |
#launch_instance(env, name, image_id, size_id, public_key_name) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 74 def launch_instance(env, name, image_id, size_id, public_key_name) response = post( env, '/instances', 'name' => name, 'image_id' => image_id, 'hwp_id' => size_id, 'keyname' => public_key_name ) i = JSON.parse(response)['instance'] ip_address = nil ip_address = i['private_addresses'][0]['address'] if i['private_addresses'][0] ip_address = i['public_addresses'][0]['address'] if i['public_addresses'][0] Instance.new(i['id'], i['name'], i['state'], i['authentication']['keyname'], ip_address) end |
#list_hardware_profiles(env) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 45 def list_hardware_profiles(env) hardware_profile_list = get(env, '/hardware_profiles') JSON.parse(hardware_profile_list)['hardware_profiles'].map do |hp| HardwareProfile.new( hp['id'], hp['name'], hp['properties']['cpu'], hp['properties']['memory'], hp['properties']['storage']) end end |
#list_images(env) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 37 def list_images(env) image_list = get(env, '/images') JSON.parse(image_list)['images'].map do |i| Image.new( i['id'], i['name'], i['visibility'], i['size'], i['min_ram'], i['min_disk']) end end |
#list_instances(env) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 54 def list_instances(env) instance_list = get(env, '/instances') JSON.parse(instance_list)['instances'].map do |i| ip_address = nil ip_address = i['private_addresses'][0]['address'] if i['private_addresses'][0] ip_address = i['public_addresses'][0]['address'] if i['public_addresses'][0] Instance.new( i['id'], i['name'], i['state'], i['authentication']['keyname'], ip_address) end end |
#list_networks(env) ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 162 def list_networks(env) network_list = get(env, '/networks') JSON.parse(network_list)['networks'].map do |n| Network.new( n['id'], n['name'], n['state'], n['address_blocks'], n['subnets'].map do |s| Subnet.new(s['id'], s['href']) end ) end end |
#list_public_keys(env) ⇒ Object
18 19 20 21 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 18 def list_public_keys(env) key_list = get(env, '/keys') JSON.parse(key_list) end |
#list_volumes(env) ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 119 def list_volumes(env) volume_list = get(env, '/storage_volumes') JSON.parse(volume_list)['storage_volumes'].map do |v| Volume.new( v['id'], v['name'], v['size'], v['status'], v['bootable'], v['instance_id'], v['device']) end end |
#reboot_instance(env, instance_id) ⇒ Object
100 101 102 103 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 100 def reboot_instance(env, instance_id) response = post(env, '/instances/' + instance_id + '/reboot') JSON.parse(response) end |
#start_instance(env, instance_id) ⇒ Object
95 96 97 98 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 95 def start_instance(env, instance_id) response = post(env, '/instances/' + instance_id + '/start') JSON.parse(response) end |
#stop_instance(env, instance_id) ⇒ Object
90 91 92 93 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 90 def stop_instance(env, instance_id) response = post(env, '/instances/' + instance_id + '/stop') JSON.parse(response) end |
#volume_info(env, volume_id) ⇒ Object
132 133 134 135 |
# File 'lib/vagrant-deltacloud-provider/client/deltacloud.rb', line 132 def volume_info(env, volume_id) response = get(env, '/storage_volumes/' + volume_id) JSON.parse(response) end |