fog-terremark 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rubocop.yml +20 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +17 -0
  7. data/CONTRIBUTING.md +18 -0
  8. data/CONTRIBUTORS.md +10 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.md +20 -0
  11. data/README.md +36 -0
  12. data/Rakefile +11 -0
  13. data/fog-terremark.gemspec +34 -0
  14. data/gemfiles/Gemfile.1.9.2- +8 -0
  15. data/gemfiles/Gemfile.1.9.3+ +7 -0
  16. data/lib/fog/compute/terremark.rb +62 -0
  17. data/lib/fog/compute/terremark/common.rb +18 -0
  18. data/lib/fog/compute/terremark/mock.rb +144 -0
  19. data/lib/fog/compute/terremark/models/address.rb +23 -0
  20. data/lib/fog/compute/terremark/models/addresses.rb +33 -0
  21. data/lib/fog/compute/terremark/models/image.rb +17 -0
  22. data/lib/fog/compute/terremark/models/images.rb +26 -0
  23. data/lib/fog/compute/terremark/models/internetservice.rb +60 -0
  24. data/lib/fog/compute/terremark/models/internetservices.rb +24 -0
  25. data/lib/fog/compute/terremark/models/network.rb +29 -0
  26. data/lib/fog/compute/terremark/models/networks.rb +37 -0
  27. data/lib/fog/compute/terremark/models/nodeservice.rb +44 -0
  28. data/lib/fog/compute/terremark/models/nodeservices.rb +14 -0
  29. data/lib/fog/compute/terremark/models/server.rb +201 -0
  30. data/lib/fog/compute/terremark/models/servers.rb +35 -0
  31. data/lib/fog/compute/terremark/models/task.rb +44 -0
  32. data/lib/fog/compute/terremark/models/tasks.rb +41 -0
  33. data/lib/fog/compute/terremark/models/vdc.rb +39 -0
  34. data/lib/fog/compute/terremark/models/vdcs.rb +36 -0
  35. data/lib/fog/compute/terremark/parser.rb +16 -0
  36. data/lib/fog/compute/terremark/real.rb +67 -0
  37. data/lib/fog/compute/terremark/requests/add_internet_service.rb +54 -0
  38. data/lib/fog/compute/terremark/requests/add_node_service.rb +51 -0
  39. data/lib/fog/compute/terremark/requests/configure_vapp.rb +58 -0
  40. data/lib/fog/compute/terremark/requests/create_internet_service.rb +57 -0
  41. data/lib/fog/compute/terremark/requests/delete_internet_service.rb +21 -0
  42. data/lib/fog/compute/terremark/requests/delete_node_service.rb +21 -0
  43. data/lib/fog/compute/terremark/requests/delete_public_ip.rb +21 -0
  44. data/lib/fog/compute/terremark/requests/delete_vapp.rb +20 -0
  45. data/lib/fog/compute/terremark/requests/deploy_vapp.rb +33 -0
  46. data/lib/fog/compute/terremark/requests/get_catalog.rb +30 -0
  47. data/lib/fog/compute/terremark/requests/get_catalog_item.rb +33 -0
  48. data/lib/fog/compute/terremark/requests/get_internet_services.rb +32 -0
  49. data/lib/fog/compute/terremark/requests/get_keys_list.rb +32 -0
  50. data/lib/fog/compute/terremark/requests/get_network.rb +70 -0
  51. data/lib/fog/compute/terremark/requests/get_network_ips.rb +29 -0
  52. data/lib/fog/compute/terremark/requests/get_node_services.rb +29 -0
  53. data/lib/fog/compute/terremark/requests/get_organization.rb +89 -0
  54. data/lib/fog/compute/terremark/requests/get_organizations.rb +45 -0
  55. data/lib/fog/compute/terremark/requests/get_public_ip.rb +31 -0
  56. data/lib/fog/compute/terremark/requests/get_public_ips.rb +69 -0
  57. data/lib/fog/compute/terremark/requests/get_task.rb +37 -0
  58. data/lib/fog/compute/terremark/requests/get_tasks_list.rb +30 -0
  59. data/lib/fog/compute/terremark/requests/get_vapp.rb +40 -0
  60. data/lib/fog/compute/terremark/requests/get_vapp_template.rb +33 -0
  61. data/lib/fog/compute/terremark/requests/get_vdc.rb +153 -0
  62. data/lib/fog/compute/terremark/requests/instantiate_vapp_template.rb +75 -0
  63. data/lib/fog/compute/terremark/requests/power_off.rb +33 -0
  64. data/lib/fog/compute/terremark/requests/power_on.rb +33 -0
  65. data/lib/fog/compute/terremark/requests/power_reset.rb +33 -0
  66. data/lib/fog/compute/terremark/requests/power_shutdown.rb +22 -0
  67. data/lib/fog/parsers/terremark.rb +26 -0
  68. data/lib/fog/parsers/terremark/base.rb +23 -0
  69. data/lib/fog/parsers/terremark/get_catalog.rb +31 -0
  70. data/lib/fog/parsers/terremark/get_catalog_item.rb +30 -0
  71. data/lib/fog/parsers/terremark/get_internet_services.rb +55 -0
  72. data/lib/fog/parsers/terremark/get_keys_list.rb +36 -0
  73. data/lib/fog/parsers/terremark/get_network_ips.rb +22 -0
  74. data/lib/fog/parsers/terremark/get_node_services.rb +30 -0
  75. data/lib/fog/parsers/terremark/get_organization.rb +46 -0
  76. data/lib/fog/parsers/terremark/get_organizations.rb +27 -0
  77. data/lib/fog/parsers/terremark/get_public_ips.rb +24 -0
  78. data/lib/fog/parsers/terremark/get_tasks_list.rb +33 -0
  79. data/lib/fog/parsers/terremark/get_vapp_template.rb +29 -0
  80. data/lib/fog/parsers/terremark/get_vdc.rb +85 -0
  81. data/lib/fog/parsers/terremark/instantiate_vapp_template.rb +24 -0
  82. data/lib/fog/parsers/terremark/internet_service.rb +56 -0
  83. data/lib/fog/parsers/terremark/network.rb +37 -0
  84. data/lib/fog/parsers/terremark/node_service.rb +26 -0
  85. data/lib/fog/parsers/terremark/public_ip.rb +20 -0
  86. data/lib/fog/parsers/terremark/task.rb +23 -0
  87. data/lib/fog/parsers/terremark/vapp.rb +59 -0
  88. data/lib/fog/terremark.rb +17 -0
  89. data/lib/fog/terremark/vcloud.rb +27 -0
  90. data/lib/fog/terremark/vcloud/mock.rb +24 -0
  91. data/lib/fog/terremark/vcloud/real.rb +66 -0
  92. data/lib/fog/terremark/version.rb +5 -0
  93. data/spec/minitest_helper.rb +31 -0
  94. metadata +251 -0
@@ -0,0 +1,35 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Servers < Fog::Collection
5
+ model Fog::Compute::Terremark::Server
6
+
7
+ def all
8
+ data = []
9
+ service.get_vdc(vdc_id).body['ResourceEntities'].select do |entity|
10
+ data << service.servers.get(entity["href"].split('/').last)
11
+ end
12
+ data
13
+ end
14
+
15
+ def get(server_id)
16
+ if server_id
17
+ new(service.get_vapp(server_id).body)
18
+ else
19
+ nil
20
+ end
21
+ end
22
+
23
+ def vdc_id
24
+ @vdc_id ||= service.default_vdc_id
25
+ end
26
+
27
+ private
28
+
29
+ def vdc_id=(new_vdc_id)
30
+ @vdc_id = new_vdc_id
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,44 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Task < Fog::Model
5
+ identity :id
6
+
7
+ attribute :end_time, :aliases => 'endTime'
8
+ attribute :owner, :aliases => 'Owner'
9
+ attribute :result, :aliases => 'Result'
10
+ attribute :start_time, :aliases => 'startTime'
11
+ attribute :status
12
+ attribute :link, :aliases => 'Link'
13
+ attribute :error, :aliases => 'Error'
14
+
15
+ def initialize(attributes = {})
16
+ new_owner = attributes.delete('Owner')
17
+ new_result = attributes.delete('Result')
18
+ new_error = attributes.delete('Error')
19
+ new_cancel_link = attributes.delete('Link')
20
+
21
+ super
22
+ self.owner = service.parse(new_owner)
23
+ if new_result
24
+ self.result = service.parse(new_result)
25
+ end
26
+ self.error = service.parse(new_error) if new_error
27
+ @cancel_link = service.parse(new_cancel_link) if new_cancel_link
28
+ end
29
+
30
+ def ready?
31
+ @status == 'success'
32
+ end
33
+
34
+ private
35
+
36
+ def href=(new_href)
37
+ @id = new_href.split('/').last.to_i
38
+ end
39
+
40
+ def type=(_new_type); end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,41 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Tasks < Fog::Collection
5
+ model Fog::Compute::Terremark::Task
6
+
7
+ def all
8
+ data = service.get_tasks_list(task_list_id).body['Tasks']
9
+ load(data)
10
+ end
11
+
12
+ def get(task_id)
13
+ task = service.get_task(task_id).body
14
+ if task_id && task
15
+ new(task)
16
+ elsif !task_id
17
+ nil
18
+ end
19
+ rescue Excon::Errors::Forbidden
20
+ nil
21
+ end
22
+
23
+ def task_list_id
24
+ organization = service.get_organization(service.default_organization_id).body
25
+ @task_list_id ||=
26
+ if service.default_organization_id && organization
27
+ organization['Links'].find {|link| link['type'] == 'application/vnd.vmware.vcloud.tasksList+xml'}['href'].split('/').last.to_i
28
+ else
29
+ nil
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def task_list_id=(new_task_list_id)
36
+ @task_list_id = new_task_list_id
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,39 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Vdc < Fog::Model
5
+ identity :id
6
+
7
+ attribute :name
8
+ attribute :ResourceEntities
9
+ attribute :AvailableNetworks
10
+ attribute :links
11
+
12
+ def networks
13
+ service.networks(:vdc_id => id)
14
+ end
15
+
16
+ def addresses
17
+ service.addresses(:vdc_id => id)
18
+ end
19
+
20
+ def servers
21
+ service.servers(:vdc_id => id)
22
+ end
23
+
24
+ def images
25
+ service.images(:vdc_id => id)
26
+ end
27
+ private
28
+
29
+ def href=(new_href)
30
+ self.id = new_href.split('/').last.to_i
31
+ end
32
+
33
+ def type=(_new_type); end
34
+
35
+ def rel=(_new_rel); end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,36 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Vdcs < Fog::Collection
5
+ model Fog::Compute::Terremark::Vdc
6
+
7
+ def all
8
+ data = service.get_organization(organization_id).body['Links'].select do |entity|
9
+ entity['type'] == 'application/vnd.vmware.vcloud.vdc+xml'
10
+ end
11
+ load(data)
12
+ end
13
+
14
+ def get(vdc_id)
15
+ if vdc_id && vdc = service.get_vdc(vdc_id).body
16
+ new(vdc)
17
+ elsif !vdc_id
18
+ nil
19
+ end
20
+ rescue Excon::Errors::Forbidden
21
+ nil
22
+ end
23
+
24
+ def organization_id
25
+ @organization_id ||= service.default_organization_id
26
+ end
27
+
28
+ private
29
+
30
+ def organization_id=(new_organization_id)
31
+ @organization_id = new_organization_id
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,16 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ module Parser
5
+ def parse(data)
6
+ case data['type']
7
+ when 'application/vnd.vmware.vcloud.vApp+xml'
8
+ servers.new(data.merge!(:service => self))
9
+ else
10
+ data
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,67 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ module Real
5
+ include Common
6
+
7
+ private
8
+
9
+ def auth_token
10
+ response = @connection.request({
11
+ :expects => 200,
12
+ :headers => {
13
+ 'Authorization' => "Basic #{Base64.encode64("#{@terremark_username}:#{@terremark_password}").chomp!}",
14
+ 'Content-Type' => "application/vnd.vmware.vcloud.orgList+xml"
15
+ },
16
+ :host => @host,
17
+ :method => 'POST',
18
+ :parser => Fog::Parsers::Terremark::GetOrganizations.new,
19
+ :path => "#{@path}/login"
20
+ })
21
+ response.headers['Set-Cookie']
22
+ end
23
+
24
+ def reload
25
+ @connection.reset
26
+ end
27
+
28
+ def request(params)
29
+ unless @cookie
30
+ @cookie = auth_token
31
+ end
32
+ begin
33
+ do_request(params)
34
+ rescue Excon::Errors::Unauthorized
35
+ @cookie = auth_token
36
+ do_request(params)
37
+ end
38
+ end
39
+
40
+ def do_request(params)
41
+ headers = {}
42
+ if @cookie
43
+ headers.merge!('Cookie' => @cookie)
44
+ end
45
+ if params[:path]
46
+ if params[:override_path] == true
47
+ path = params[:path]
48
+ else
49
+ path = "#{@path}/#{params[:path]}"
50
+ end
51
+ else
52
+ path = "#{@path}"
53
+ end
54
+ @connection.request({
55
+ :body => params[:body],
56
+ :expects => params[:expects],
57
+ :headers => headers.merge!(params[:headers] || {}),
58
+ :host => @host,
59
+ :method => params[:method],
60
+ :parser => params[:parser],
61
+ :path => path
62
+ })
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,54 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ module Real
5
+ # Reserve requested resources and deploy vApp
6
+ #
7
+ # ==== Parameters
8
+ # * ip_id<~Integer> - Id of ip to add service to
9
+ # * name<~String> - Name of service
10
+ # * protocol<~String> - Protocol of service
11
+ # * port<~Integer> - Port of service
12
+ # * options<~Hash>:
13
+ # * Enabled<~Boolean>: defaults to true
14
+ # * Description<~String>: optional description
15
+ #
16
+ # ==== Returns
17
+ # * response<~Excon::Response>:
18
+ # * body<~Hash>:
19
+ # * 'endTime'<~String> - endTime of task
20
+ # * 'href'<~String> - link to task
21
+ # * 'startTime'<~String> - startTime of task
22
+ # * 'status'<~String> - status of task
23
+ # * 'type'<~String> - type of task
24
+ # * 'Owner'<~String> -
25
+ # * 'href'<~String> - href of owner
26
+ # * 'name'<~String> - name of owner
27
+ # * 'type'<~String> - type of owner
28
+ def add_internet_service(ip_id, name, protocol, port, options = {})
29
+ unless options.key?('Enabled')
30
+ options['Enabled'] = true
31
+ end
32
+ data = <<-DATA
33
+ <CreateInternetServiceRequest xml:lang="en" xmlns="urn:tmrk:vCloudExpressExtensions-1.6" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
34
+ <Name>#{name}</Name>
35
+ <Protocol>#{protocol.upcase}</Protocol>
36
+ <Port>#{port}</Port>
37
+ <Enabled>#{options['Enabled']}</Enabled>
38
+ <Description>#{options['Description']}</Description>
39
+ </CreateInternetServiceRequest>
40
+ DATA
41
+ request(
42
+ :body => data,
43
+ :expects => 200,
44
+ :headers => {'Content-Type' => 'application/xml'},
45
+ :method => 'POST',
46
+ :parser => Fog::Parsers::Terremark::InternetService.new,
47
+ :path => "api/extensions/v1.6/publicIp/#{ip_id}/internetServices",
48
+ :override_path => true
49
+ )
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,51 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ module Real
5
+ # Reserve requested resources and deploy vApp
6
+ #
7
+ # ==== Parameters
8
+ # * service_id<~String> - Id of service to add node to
9
+ # * ip<~String> - Private ip of server to add to node
10
+ # * name<~String> - Name of service
11
+ # * port<~Integer> - Port of service
12
+ # * options<~Hash>:
13
+ # * Enabled<~Boolean>: defaults to true
14
+ # * Description<~String>: optional description
15
+ #
16
+ # ==== Returns
17
+ # * response<~Excon::Response>:
18
+ # * body<~Hash>:
19
+ # * 'endTime'<~String> - endTime of task
20
+ # * 'href'<~String> - link to task
21
+ # * 'startTime'<~String> - startTime of task
22
+ # * 'status'<~String> - status of task
23
+ # * 'type'<~String> - type of task
24
+ # * 'Owner'<~String> -
25
+ # * 'href'<~String> - href of owner
26
+ # * 'name'<~String> - name of owner
27
+ # * 'type'<~String> - type of owner
28
+ def add_node_service(service_id, ip, name, port, options = {})
29
+ unless options.key?('Enabled')
30
+ options['Enabled'] = true
31
+ end
32
+
33
+ data = <<-DATA
34
+ <CreateNodeServiceRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpressExtensions-1.6"><IpAddress>#{ip}</IpAddress><Name>#{name}</Name><Port>#{port}</Port><Enabled>#{options['Enabled']}</Enabled><Description>#{options['Description']}</Description></CreateNodeServiceRequest>
35
+ DATA
36
+ response = request(
37
+ :body => data,
38
+ :expects => 200,
39
+ :headers => {'Content-Type' => 'application/vnd.tmrk.vCloud.nodeService+xml'},
40
+ :method => 'POST',
41
+ :parser => Fog::Parsers::Terremark::NodeService.new,
42
+ :path => "api/extensions/v1.6/internetService/#{service_id}/nodeServices",
43
+ :override_path => true
44
+ )
45
+
46
+ response
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,58 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ module Real
5
+ def configure_vapp(vapp_id, vapp_name, options = {})
6
+ items = ""
7
+ vapp_uri = [@host, @path, "vApp", vapp_id.to_s].join("/")
8
+
9
+ if options['vcpus']
10
+ vcpu_item = <<-DATA
11
+ <Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"> <InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">3</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">#{options['vcpus']}</VirtualQuantity></Item>
12
+ DATA
13
+ items << vcpu_item
14
+ end
15
+
16
+ if options['memory']
17
+ memory_item = <<-DATA
18
+ <Item xmlns="http://schemas.dmtf.org/ovf/envelope/1"><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">2</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">4</ResourceType>38<VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">#{options['memory']}</VirtualQuantity></Item>
19
+ DATA
20
+ items << memory_item
21
+ end
22
+ #Default root disk
23
+ virtual_disk_item = <<-DATA
24
+ <Item>
25
+ <AddressOnParent xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">0</AddressOnParent> <HostResource xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1048576</HostResource><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">9</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">17</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1048576</VirtualQuantity></Item>
26
+ DATA
27
+ items << virtual_disk_item
28
+ #Additional disks
29
+ if options['virtual_disks']
30
+ for disk in options['virtual_disks']
31
+ actual_size = disk.to_i * 1024 * 1024
32
+ virtual_disk_item = <<-DATA
33
+ <Item>
34
+ <AddressOnParent xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">-1</AddressOnParent><HostResource xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">#{actual_size}</HostResource><InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">9</InstanceID><ResourceType xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">17</ResourceType><VirtualQuantity xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">#{actual_size}</VirtualQuantity></Item>
35
+ DATA
36
+ items << virtual_disk_item
37
+ end
38
+ end
39
+
40
+ data = <<-DATA
41
+ <VApp href="#{vapp_uri}" type="application/vnd.vmware.vcloud.vApp+xml" name="#{vapp_name}" status="2" size="10485760" xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
42
+ <VirtualHardwareSection xmlns="http://schemas.dmtf.org/ovf/envelope/1"><Info>Virtual Hardware</Info>#{items}
43
+ </VirtualHardwareSection>
44
+ </VApp>
45
+ DATA
46
+
47
+ request(
48
+ :body => data,
49
+ :expects => 202,
50
+ :headers => { 'Content-Type' => 'application/vnd.vmware.vCloud.vApp+xml' },
51
+ :method => 'PUT',
52
+ :path => "vapp/#{vapp_id}"
53
+ )
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end