fog 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. data/Gemfile.lock +11 -6
  2. data/changelog.txt +49 -0
  3. data/fog.gemspec +5 -4
  4. data/lib/fog.rb +1 -1
  5. data/lib/fog/aws/cloud_formation.rb +124 -0
  6. data/lib/fog/aws/elb.rb +4 -1
  7. data/lib/fog/aws/iam.rb +6 -0
  8. data/lib/fog/aws/parsers/cloud_formation/basic.rb +12 -0
  9. data/lib/fog/aws/parsers/cloud_formation/create_stack.rb +19 -0
  10. data/lib/fog/aws/parsers/cloud_formation/describe_stack_events.rb +31 -0
  11. data/lib/fog/aws/parsers/cloud_formation/describe_stack_resources.rb +31 -0
  12. data/lib/fog/aws/parsers/cloud_formation/describe_stacks.rb +72 -0
  13. data/lib/fog/aws/parsers/cloud_formation/get_template.rb +19 -0
  14. data/lib/fog/aws/parsers/cloud_formation/validate_template.rb +52 -0
  15. data/lib/fog/aws/parsers/iam/login_profile.rb +27 -0
  16. data/lib/fog/aws/parsers/iam/upload_server_certificate.rb +26 -0
  17. data/lib/fog/aws/parsers/rds/authorize_db_security_group_ingress.rb +38 -0
  18. data/lib/fog/aws/parsers/rds/create_db_instance.rb +34 -0
  19. data/lib/fog/aws/parsers/rds/create_db_instance_read_replica.rb +34 -0
  20. data/lib/fog/aws/parsers/rds/create_db_parameter_group.rb +35 -0
  21. data/lib/fog/aws/parsers/rds/create_db_security_group.rb +38 -0
  22. data/lib/fog/aws/parsers/rds/create_db_snapshot.rb +35 -0
  23. data/lib/fog/aws/parsers/rds/db_parser.rb +123 -0
  24. data/lib/fog/aws/parsers/rds/delete_db_instance.rb +35 -0
  25. data/lib/fog/aws/parsers/rds/delete_db_parameter_group.rb +27 -0
  26. data/lib/fog/aws/parsers/rds/delete_db_security_group.rb +33 -0
  27. data/lib/fog/aws/parsers/rds/delete_db_snapshot.rb +34 -0
  28. data/lib/fog/aws/parsers/rds/describe_db_instances.rb +36 -0
  29. data/lib/fog/aws/parsers/rds/describe_db_parameter_groups.rb +38 -0
  30. data/lib/fog/aws/parsers/rds/describe_db_parameters.rb +44 -0
  31. data/lib/fog/aws/parsers/rds/describe_db_security_groups.rb +39 -0
  32. data/lib/fog/aws/parsers/rds/describe_db_snapshots.rb +39 -0
  33. data/lib/fog/aws/parsers/rds/modify_db_instance.rb +34 -0
  34. data/lib/fog/aws/parsers/rds/modify_db_parameter_group.rb +28 -0
  35. data/lib/fog/aws/parsers/rds/reboot_db_instance.rb +35 -0
  36. data/lib/fog/aws/parsers/rds/restore_db_instance_from_db_snapshot.rb +34 -0
  37. data/lib/fog/aws/parsers/rds/restore_db_instance_to_point_in_time.rb +35 -0
  38. data/lib/fog/aws/parsers/rds/revoke_db_security_group_ingress.rb +39 -0
  39. data/lib/fog/aws/parsers/rds/security_group_parser.rb +39 -0
  40. data/lib/fog/aws/parsers/rds/snapshot_parser.rb +40 -0
  41. data/lib/fog/aws/rds.rb +161 -0
  42. data/lib/fog/aws/rds/models/parameter.rb +21 -0
  43. data/lib/fog/aws/rds/models/parameter_group.rb +36 -0
  44. data/lib/fog/aws/rds/models/parameter_groups.rb +27 -0
  45. data/lib/fog/aws/rds/models/parameters.rb +37 -0
  46. data/lib/fog/aws/rds/models/security_group.rb +73 -0
  47. data/lib/fog/aws/rds/models/security_groups.rb +43 -0
  48. data/lib/fog/aws/rds/models/server.rb +105 -0
  49. data/lib/fog/aws/rds/models/servers.rb +27 -0
  50. data/lib/fog/aws/rds/models/snapshot.rb +49 -0
  51. data/lib/fog/aws/rds/models/snapshots.rb +45 -0
  52. data/lib/fog/aws/requests/cloud_formation/create_stack.rb +71 -0
  53. data/lib/fog/aws/requests/cloud_formation/delete_stack.rb +30 -0
  54. data/lib/fog/aws/requests/cloud_formation/describe_stack_events.rb +44 -0
  55. data/lib/fog/aws/requests/cloud_formation/describe_stack_resources.rb +43 -0
  56. data/lib/fog/aws/requests/cloud_formation/describe_stacks.rb +42 -0
  57. data/lib/fog/aws/requests/cloud_formation/get_template.rb +32 -0
  58. data/lib/fog/aws/requests/cloud_formation/validate_template.rb +34 -0
  59. data/lib/fog/aws/requests/elb/create_load_balancer.rb +4 -0
  60. data/lib/fog/aws/requests/iam/create_login_profile.rb +36 -0
  61. data/lib/fog/aws/requests/iam/delete_login_profile.rb +31 -0
  62. data/lib/fog/aws/requests/iam/delete_server_certificate.rb +32 -0
  63. data/lib/fog/aws/requests/iam/get_login_profile.rb +35 -0
  64. data/lib/fog/aws/requests/iam/update_login_profile.rb +33 -0
  65. data/lib/fog/aws/requests/iam/upload_server_certificate.rb +45 -0
  66. data/lib/fog/aws/requests/rds/authorize_db_security_group_ingress.rb +43 -0
  67. data/lib/fog/aws/requests/rds/create_db_instance.rb +56 -0
  68. data/lib/fog/aws/requests/rds/create_db_instance_read_replica.rb +42 -0
  69. data/lib/fog/aws/requests/rds/create_db_parameter_group.rb +41 -0
  70. data/lib/fog/aws/requests/rds/create_db_security_group.rb +37 -0
  71. data/lib/fog/aws/requests/rds/create_db_snapshot.rb +36 -0
  72. data/lib/fog/aws/requests/rds/delete_db_instance.rb +40 -0
  73. data/lib/fog/aws/requests/rds/delete_db_parameter_group.rb +36 -0
  74. data/lib/fog/aws/requests/rds/delete_db_security_group.rb +36 -0
  75. data/lib/fog/aws/requests/rds/delete_db_snapshot.rb +36 -0
  76. data/lib/fog/aws/requests/rds/describe_db_instances.rb +42 -0
  77. data/lib/fog/aws/requests/rds/describe_db_parameter_groups.rb +45 -0
  78. data/lib/fog/aws/requests/rds/describe_db_parameters.rb +46 -0
  79. data/lib/fog/aws/requests/rds/describe_db_security_groups.rb +39 -0
  80. data/lib/fog/aws/requests/rds/describe_db_snapshots.rb +42 -0
  81. data/lib/fog/aws/requests/rds/modify_db_instance.rb +54 -0
  82. data/lib/fog/aws/requests/rds/modify_db_parameter_group.rb +55 -0
  83. data/lib/fog/aws/requests/rds/reboot_db_instance.rb +34 -0
  84. data/lib/fog/aws/requests/rds/restore_db_instance_from_db_snapshot.rb +34 -0
  85. data/lib/fog/aws/requests/rds/restore_db_instance_to_point_in_time.rb +35 -0
  86. data/lib/fog/aws/requests/rds/revoke_db_security_group_ingress.rb +44 -0
  87. data/lib/fog/aws/simpledb.rb +21 -7
  88. data/lib/fog/bin.rb +2 -1
  89. data/lib/fog/bin/aws.rb +8 -0
  90. data/lib/fog/bin/virtual_box.rb +52 -0
  91. data/lib/fog/cdn/aws.rb +9 -8
  92. data/lib/fog/cdn/rackspace.rb +6 -6
  93. data/lib/fog/cdn/requests/rackspace/post_container.rb +30 -0
  94. data/lib/fog/cdn/requests/rackspace/put_container.rb +1 -1
  95. data/lib/fog/compute.rb +6 -3
  96. data/lib/fog/compute/aws.rb +11 -7
  97. data/lib/fog/compute/bluebox.rb +5 -6
  98. data/lib/fog/compute/brightbox.rb +3 -0
  99. data/lib/fog/compute/go_grid.rb +5 -6
  100. data/lib/fog/compute/linode.rb +5 -6
  101. data/lib/fog/compute/models/aws/flavors.rb +19 -18
  102. data/lib/fog/compute/models/aws/server.rb +23 -0
  103. data/lib/fog/compute/models/aws/tag.rb +1 -1
  104. data/lib/fog/compute/models/brightbox/server.rb +7 -1
  105. data/lib/fog/compute/models/virtual_box/medium.rb +87 -0
  106. data/lib/fog/compute/models/virtual_box/medium_format.rb +34 -0
  107. data/lib/fog/compute/models/virtual_box/mediums.rb +32 -0
  108. data/lib/fog/compute/models/virtual_box/nat_engine.rb +65 -0
  109. data/lib/fog/compute/models/virtual_box/nat_redirect.rb +91 -0
  110. data/lib/fog/compute/models/virtual_box/nat_redirects.rb +41 -0
  111. data/lib/fog/compute/models/virtual_box/network_adapter.rb +82 -0
  112. data/lib/fog/compute/models/virtual_box/network_adapters.rb +42 -0
  113. data/lib/fog/compute/models/virtual_box/server.rb +241 -0
  114. data/lib/fog/compute/models/virtual_box/servers.rb +41 -0
  115. data/lib/fog/compute/models/virtual_box/storage_controller.rb +83 -0
  116. data/lib/fog/compute/models/virtual_box/storage_controllers.rb +38 -0
  117. data/lib/fog/compute/models/voxel/servers.rb +7 -6
  118. data/lib/fog/compute/new_servers.rb +5 -6
  119. data/lib/fog/compute/parsers/aws/monitor_unmonitor_instances.rb +35 -0
  120. data/lib/fog/compute/rackspace.rb +7 -7
  121. data/lib/fog/compute/requests/aws/delete_tags.rb +12 -9
  122. data/lib/fog/compute/requests/aws/monitor_instances.rb +52 -0
  123. data/lib/fog/compute/requests/aws/revoke_security_group_ingress.rb +24 -8
  124. data/lib/fog/compute/requests/aws/unmonitor_instances.rb +53 -0
  125. data/lib/fog/compute/requests/brightbox/activate_console_server.rb +20 -0
  126. data/lib/fog/compute/requests/brightbox/add_listeners_load_balancer.rb +20 -0
  127. data/lib/fog/compute/requests/brightbox/remove_listeners_load_balancer.rb +20 -0
  128. data/lib/fog/compute/slicehost.rb +5 -6
  129. data/lib/fog/compute/virtual_box.rb +48 -0
  130. data/lib/fog/compute/voxel.rb +30 -27
  131. data/lib/fog/core.rb +1 -0
  132. data/lib/fog/core/attributes.rb +3 -1
  133. data/lib/fog/core/collection.rb +2 -2
  134. data/lib/fog/core/credentials.rb +13 -3
  135. data/lib/fog/core/scp.rb +0 -4
  136. data/lib/fog/core/service.rb +0 -8
  137. data/lib/fog/core/ssh.rb +0 -4
  138. data/lib/fog/dns.rb +3 -3
  139. data/lib/fog/dns/aws.rb +8 -8
  140. data/lib/fog/dns/bluebox.rb +5 -7
  141. data/lib/fog/dns/dnsimple.rb +7 -7
  142. data/lib/fog/dns/linode.rb +5 -6
  143. data/lib/fog/dns/models/dnsimple/record.rb +11 -1
  144. data/lib/fog/dns/models/dnsimple/records.rb +7 -7
  145. data/lib/fog/dns/models/dnsimple/zones.rb +2 -1
  146. data/lib/fog/dns/requests/dnsimple/get_record.rb +34 -0
  147. data/lib/fog/dns/slicehost.rb +5 -6
  148. data/lib/fog/dns/zerigo.rb +5 -7
  149. data/lib/fog/providers.rb +2 -1
  150. data/lib/fog/providers/aws.rb +10 -8
  151. data/lib/fog/providers/virtual_box.rb +11 -0
  152. data/lib/fog/storage.rb +21 -0
  153. data/lib/fog/storage/aws.rb +16 -32
  154. data/lib/fog/storage/google.rb +6 -27
  155. data/lib/fog/storage/local.rb +7 -7
  156. data/lib/fog/storage/models/rackspace/directory.rb +1 -1
  157. data/lib/fog/storage/models/rackspace/file.rb +1 -0
  158. data/lib/fog/storage/rackspace.rb +5 -27
  159. data/lib/fog/storage/requests/aws/put_object.rb +2 -2
  160. data/lib/fog/storage/requests/aws/upload_part.rb +1 -1
  161. data/lib/fog/storage/requests/google/put_object.rb +2 -2
  162. data/lib/fog/storage/requests/rackspace/put_object.rb +1 -1
  163. data/tests/aws/requests/cloud_formation/stack_tests.rb +130 -0
  164. data/tests/aws/requests/iam/login_profile_tests.rb +64 -0
  165. data/tests/aws/requests/rds/helper.rb +169 -0
  166. data/tests/aws/requests/rds/instance_tests.rb +129 -0
  167. data/tests/aws/requests/rds/model_tests.rb +98 -0
  168. data/tests/aws/requests/rds/parameter_group_tests.rb +68 -0
  169. data/tests/aws/requests/rds/parameter_request_tests.rb +35 -0
  170. data/tests/compute/models/aws/server_monitor_tests.rb +47 -0
  171. data/tests/compute/models/server_tests.rb +7 -23
  172. data/tests/compute/parsers/aws/monitor_unmonitor_instances_tests.rb +49 -0
  173. data/tests/compute/requests/aws/security_group_tests.rb +69 -52
  174. data/tests/compute/requests/aws/tag_tests.rb +5 -5
  175. data/tests/compute/requests/brightbox/helper.rb +7 -6
  176. data/tests/compute/requests/brightbox/server_tests.rb +5 -0
  177. data/tests/compute/requests/voxel/server_tests.rb +2 -3
  178. data/tests/storage/requests/aws/bucket_tests.rb +10 -0
  179. metadata +148 -12
@@ -0,0 +1,34 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module VirtualBox
5
+ class Compute
6
+
7
+ class MediumFormat < Fog::Model
8
+
9
+ identity :id
10
+
11
+ # attribute :capabilities
12
+ attribute :name
13
+
14
+ private
15
+
16
+ def raw
17
+ @raw
18
+ end
19
+
20
+ def raw=(new_raw)
21
+ @raw = new_raw
22
+ raw_attributes = {}
23
+ for key in [:id, :name]
24
+ raw_attributes[key] = @raw.send(key)
25
+ end
26
+ merge_attributes(raw_attributes)
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,32 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/compute/models/virtual_box/medium'
3
+
4
+ module Fog
5
+ module VirtualBox
6
+ class Compute
7
+
8
+ class Mediums < Fog::Collection
9
+
10
+ model Fog::VirtualBox::Compute::Medium
11
+
12
+ def all
13
+ data = []
14
+ data.concat(connection.dvd_images)
15
+ data.concat(connection.floppy_images)
16
+ data.concat(connection.hard_disks)
17
+ data = data.map do |medium|
18
+ {:raw => medium}
19
+ end
20
+ load(data)
21
+ end
22
+
23
+ def get(medium_identity)
24
+ data = connection.find_medium(medium_identity)
25
+ new(:raw => data)
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,65 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module VirtualBox
5
+ class Compute
6
+
7
+ class NATEngine < Fog::Model
8
+
9
+ # identity :?
10
+
11
+ attribute :alias_mode
12
+ attribute :dns_pass_domain
13
+ attribute :dns_proxy
14
+ attribute :dns_use_host_resolver
15
+ attribute :host_ip
16
+ attribute :network
17
+ attribute :redirects
18
+ attribute :tftp_boot_file
19
+ attribute :tftp_next_server
20
+ attribute :tftp_prefix
21
+
22
+ attr_accessor :machine, :network_adapter
23
+
24
+ # def save
25
+ # unless identity
26
+ # requires :identity, :bus, :machine
27
+ # with_session do |session|
28
+ # self.raw = session.machine.add_storage_controller(identity, bus)
29
+ # end
30
+ # true
31
+ # else
32
+ # raise Fog::Errors::Error.new('Updating an existing storage_controller is not yet implemented. Contributions welcome!')
33
+ # end
34
+ # end
35
+
36
+ undef_method :redirects
37
+ def redirects
38
+ Fog::VirtualBox::Compute::NATRedirects.new(
39
+ :connection => connection,
40
+ :machine => machine,
41
+ :nat_engine => self
42
+ )
43
+ end
44
+
45
+ private
46
+
47
+ def raw
48
+ @raw
49
+ end
50
+
51
+ def raw=(new_raw)
52
+ @raw = new_raw
53
+ raw_attributes = {}
54
+ for key in [:alias_mode, :dns_pass_domain, :dns_proxy, :dns_use_host_resolver, :host_ip, :network, :redirects, :tftp_boot_file, :tftp_next_server, :tftp_prefix]
55
+ raw_attributes[key] = @raw.send(key)
56
+ end
57
+ merge_attributes(raw_attributes)
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,91 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module VirtualBox
5
+ class Compute
6
+
7
+ class NATRedirect < Fog::Model
8
+
9
+ identity :name
10
+
11
+ attribute :name
12
+ attribute :protocol
13
+ attribute :host_ip
14
+ attribute :host_port
15
+ attribute :guest_ip
16
+ attribute :guest_port
17
+
18
+ attr_accessor :machine, :nat_engine
19
+
20
+ def destroy
21
+ requires :nat_engine, :name
22
+ with_session do |session|
23
+ raw_network_adapter = session.machine.get_network_adapter(nat_engine.network_adapter.slot)
24
+ raw_nat_engine = raw_network_adapter.nat_driver
25
+ raw_nat_engine.remove_redirect(name)
26
+ session.machine.save_settings
27
+ end
28
+ true
29
+ end
30
+
31
+ def initialize(attributes = {})
32
+ self.name = ''
33
+ self.protocol = :tcp
34
+ self.host_ip = ''
35
+ self.guest_ip = ''
36
+ super
37
+ end
38
+
39
+ undef_method :protocol=
40
+ def protocol=(new_protocol)
41
+ attributes[:protocol] = case new_protocol
42
+ when '0'
43
+ :udp
44
+ when '1'
45
+ :tcp
46
+ else
47
+ new_protocol
48
+ end
49
+ end
50
+
51
+ def save
52
+ requires :nat_engine, :name, :protocol, :host_ip, :host_port, :guest_ip, :guest_port
53
+ with_session do |session|
54
+ raw_network_adapter = session.machine.get_network_adapter(nat_engine.network_adapter.slot)
55
+ raw_nat_engine = raw_network_adapter.nat_driver
56
+ raw_nat_engine.add_redirect(name, protocol, host_ip, host_port, guest_ip, guest_port)
57
+ session.machine.save_settings
58
+ end
59
+ true
60
+ end
61
+
62
+ private
63
+
64
+ def raw
65
+ @raw
66
+ end
67
+
68
+ def raw=(new_raw)
69
+ @raw = new_raw
70
+ name, protocol, host_ip, host_port, guest_ip, guest_port = new_raw.split(',')
71
+ raw_attributes = {:name => name, :protocol => protocol, :host_ip => host_ip, :host_port => host_port, :guest_ip => guest_ip, :guest_port => guest_port}
72
+ merge_attributes(raw_attributes)
73
+ end
74
+
75
+ def session
76
+ ::VirtualBox::Lib.lib.session
77
+ end
78
+
79
+ def with_session
80
+ raw_machine = machine.instance_variable_get(:@raw)
81
+ raw_machine.lock_machine(session, :write)
82
+ yield session
83
+ session.unlock_machine
84
+ end
85
+
86
+ end
87
+
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,41 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/compute/models/virtual_box/nat_redirect'
3
+
4
+ module Fog
5
+ module VirtualBox
6
+ class Compute
7
+
8
+ class NATRedirects < Fog::Collection
9
+
10
+ model Fog::VirtualBox::Compute::NATRedirect
11
+
12
+ attr_accessor :machine, :nat_engine
13
+
14
+ def all
15
+ requires :machine, :nat_engine
16
+ data = nat_engine.instance_variable_get(:@raw).redirects.map do |nat_redirect|
17
+ {
18
+ :machine => machine,
19
+ :raw => nat_redirect
20
+ }
21
+ end
22
+ load(data)
23
+ end
24
+
25
+ def get(nat_redirect_name)
26
+ requires :machine, :nat_engine
27
+ all.detect do |nat_redirect|
28
+ nat_redirect.name == nat_redirect_name
29
+ end
30
+ end
31
+
32
+ def new(attributes = {})
33
+ requires :machine, :nat_engine
34
+ super({:machine => machine, :nat_engine => nat_engine}.merge!(attributes))
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,82 @@
1
+ require 'fog/core/model'
2
+ require 'fog/compute/models/virtual_box/nat_engine'
3
+
4
+ module Fog
5
+ module VirtualBox
6
+ class Compute
7
+
8
+ class NetworkAdapter < Fog::Model
9
+
10
+ identity :slot
11
+
12
+ attribute :adapter_type
13
+ attribute :attachment_type
14
+ attribute :bandwidth_limit
15
+ attribute :boot_priority
16
+ attribute :cable_connected
17
+ attribute :enabled
18
+ attribute :host_interface
19
+ attribute :internal_network
20
+ attribute :line_speed
21
+ attribute :mac_address
22
+ attribute :nat_driver
23
+ attribute :nat_network
24
+ attribute :trace_enabled
25
+ attribute :trace_file
26
+ attribute :vde_network
27
+
28
+ attr_accessor :machine
29
+
30
+ def save
31
+ with_session do |session|
32
+ session_raw = session.machine.get_network_adapter(slot)
33
+ # for attribute in [:adapter_type, :bandwidth_limit, :boot_priority, :cable_connected, :enabled, :host_interface, :internal_network, :line_speed, :mac_address, :nat_network, :trace_enabled, :trace_file]
34
+ # session_raw.send("#{attribute}=", attributes[attribute])
35
+ # end
36
+ session_raw.mac_address = mac_address
37
+ session.machine.save_settings
38
+ end
39
+ end
40
+
41
+ undef_method :nat_driver
42
+ def nat_driver
43
+ Fog::VirtualBox::Compute::NATEngine.new(
44
+ :connection => connection,
45
+ :machine => machine,
46
+ :network_adapter => self,
47
+ :raw => raw.nat_driver
48
+ )
49
+ end
50
+
51
+ private
52
+
53
+ def raw
54
+ @raw
55
+ end
56
+
57
+ def raw=(new_raw)
58
+ @raw = new_raw
59
+ raw_attributes = {}
60
+ for key in [:adapter_type, :attachment_type, :bandwidth_limit, :boot_priority, :cable_connected, :enabled, :host_interface, :internal_network, :line_speed, :mac_address, :nat_driver, :nat_network, :slot, :trace_enabled, :trace_file]
61
+ raw_attributes[key] = @raw.send(key)
62
+ end
63
+ merge_attributes(raw_attributes)
64
+ end
65
+
66
+ def session
67
+ ::VirtualBox::Lib.lib.session
68
+ end
69
+
70
+ def with_session
71
+ raw_machine = machine.instance_variable_get(:@raw)
72
+ raw_machine.lock_machine(session, :write)
73
+ yield session
74
+ session.unlock_machine
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,42 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/compute/models/virtual_box/network_adapter'
3
+
4
+ module Fog
5
+ module VirtualBox
6
+ class Compute
7
+
8
+ class NetworkAdapters < Fog::Collection
9
+
10
+ model Fog::VirtualBox::Compute::NetworkAdapter
11
+
12
+ attr_accessor :machine
13
+
14
+ def all
15
+ requires :machine
16
+ data = []
17
+ raw_machine = machine.instance_variable_get(:@raw)
18
+ connection.system_properties.network_adapter_count.times do |index|
19
+ data << {
20
+ :raw => raw_machine.get_network_adapter(index)
21
+ }
22
+ end
23
+ load(data)
24
+ end
25
+
26
+ def get(network_adapter_slot)
27
+ requires :machine
28
+ raw_machine = machine.instance_variable_get(:@raw)
29
+ network_adapter = raw_machine.get_network_adapter(network_adapter_slot)
30
+ new(:raw => network_adapter)
31
+ end
32
+
33
+ def new(attributes = {})
34
+ requires :machine
35
+ super({ :machine => machine }.merge!(attributes))
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,241 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module VirtualBox
5
+ class Compute
6
+
7
+ class Server < Fog::Model
8
+
9
+ identity :id
10
+
11
+ attribute :description
12
+ attribute :memory_size
13
+ attribute :name
14
+ attribute :os, :aliases => :os_type_id
15
+ attribute :rtc_use_utc
16
+ attribute :session_state
17
+ attribute :status, :aliases => :state
18
+ attribute :vram_size
19
+
20
+ # property :accelerate_2d_video_enabled, T_BOOL
21
+ # property :accelerate_3d_enabled, T_BOOL
22
+ # property :access_error, :VirtualBoxErrorInfo, :readonly => true
23
+ # property :accessible, T_BOOL, :readonly => true
24
+ # property :audio_adapter, :AudioAdapter, :readonly => true
25
+ # property :bandwidth_control, :BandwidthControl, :readonly => true
26
+ # property :bios_settings, :BIOSSettings, :readonly => true
27
+ # property :chipset_type, :ChipsetType
28
+ # property :clipboard_mode, :ClipboardMode
29
+ # property :cpu_count, T_UINT32
30
+ # property :cpu_execution_cap, T_UINT64
31
+ # property :cpu_hot_plug_enabled, T_BOOL
32
+ # property :current_snapshot, :Snapshot, :readonly => true
33
+ # property :current_state_modified, T_BOOL, :readonly => true
34
+ # property :fault_tolerance_address, WSTRING
35
+ # property :fault_tolerance_password, WSTRING
36
+ # property :fault_tolerance_port, T_UINT64
37
+ # property :fault_tolerance_state, :FaultToleranceState
38
+ # property :fault_tolerance_sync_interval, T_UINT64
39
+ # property :firmware_type, :FirmwareType
40
+ # property :guest_property_notification_patterns, WSTRING
41
+ # property :hardware_uuid, WSTRING
42
+ # property :hardware_version, WSTRING
43
+ # property :hpet_enabled, T_BOOL
44
+ # property :io_cache_enabled, T_BOOL
45
+ # property :io_cache_size, T_UINT32
46
+ # property :keyboard_hid_type, T_UINT32
47
+ # property :last_state_change, T_INT64, :readonly => true
48
+ # property :log_folder, WSTRING, :readonly => true
49
+ # property :medium_attachments, [:MediumAttachment], :readonly => true
50
+ # property :memory_balloon_size, T_UINT64
51
+ # property :monitor_count, T_UINT64
52
+ # property :page_fusion_enabled, T_BOOL
53
+ # property :parent, :VirtualBox, :readonly => true
54
+ # property :pci_device_assignments, [:PciDeviceAttachment], :readonly => true
55
+ # property :pointing_hid_type, T_UINT32
56
+ # property :session_pid, T_UINT64, :readonly => true
57
+ # property :session_type, WSTRING, :readonly => true
58
+ # property :settings_file_path, WSTRING, :readonly => true
59
+ # property :settings_modified, T_BOOL, :readonly => true
60
+ # property :shared_folders, [:SharedFolder], :readonly => true
61
+ # property :snapshot_count, T_UINT32, :readonly => true
62
+ # property :snapshot_folder, WSTRING
63
+ # property :state_file_path, WSTRING, :readonly => true
64
+ # property :storage_controllers, [:StorageController], :readonly => true
65
+ # property :teleporter_address, WSTRING
66
+ # property :teleporter_enabled, T_BOOL
67
+ # property :teleporter_password, WSTRING
68
+ # property :teleporter_port, T_UINT32
69
+ # property :usb_controller, :USBController, :readonly => true
70
+ # property :vrde_server, :VRDEServer, :readonly => true
71
+
72
+ attr_writer :private_key, :private_key_path, :public_key, :public_key_path, :username
73
+
74
+ def initialize(attributes={})
75
+ self.memory_size = 256
76
+ self.rtc_use_utc = true
77
+ self.vram_size = 8
78
+ super
79
+ end
80
+
81
+ def destroy
82
+ requires :name, :raw
83
+ unless raw.state == :powered_off
84
+ stop
85
+ wait_for { raw.session_state == :closed }
86
+ end
87
+ raw.unregister(:full)
88
+ config_file = connection.compose_machine_filename(name)
89
+ config_directory = config_file.split(File::SEPARATOR)[0...-1].join(File::SEPARATOR)
90
+ FileUtils.rm_rf(config_directory)
91
+ true
92
+ end
93
+
94
+ def network_adapters
95
+ Fog::VirtualBox::Compute::NetworkAdapters.new(
96
+ :connection => connection,
97
+ :machine => self
98
+ )
99
+ end
100
+
101
+ def private_ip_address
102
+ nil
103
+ end
104
+
105
+ def private_key_path
106
+ @private_key_path ||= Fog.credentials[:private_key_path]
107
+ @private_key_path &&= File.expand_path(@private_key_path)
108
+ end
109
+
110
+ def private_key
111
+ @private_key ||= private_key_path && File.read(private_key_path)
112
+ end
113
+
114
+ def public_ip_address
115
+ nil
116
+ end
117
+
118
+ def public_key_path
119
+ @public_key_path ||= Fog.credentials[:public_key_path]
120
+ @public_key_path &&= File.expand_path(@public_key_path)
121
+ end
122
+
123
+ def public_key
124
+ @public_key ||= public_key_path && File.read(public_key_path)
125
+ end
126
+
127
+ def ready?
128
+ status == :running
129
+ end
130
+
131
+ def reboot
132
+ requires :raw
133
+ session.console.reset
134
+ true
135
+ end
136
+
137
+ def save
138
+ unless identity
139
+ requires :name, :os
140
+ self.raw = connection.create_machine(nil, name, os)
141
+ connection.register_machine(raw)
142
+ with_session do |session|
143
+ for attribute in [:description, :memory_size, :rtc_use_utc, :vram_size]
144
+ session.machine.send(:"#{attribute}=", attributes[attribute])
145
+ end
146
+ session.machine.save_settings
147
+ end
148
+ true
149
+ else
150
+ raise Fog::Errors::Error.new('Updating an existing server is not yet implemented. Contributions welcome!')
151
+ end
152
+ end
153
+
154
+ def scp(local_path, remote_path)
155
+ raise 'Not Implemented'
156
+ # requires :addresses, :username
157
+ #
158
+ # options = {}
159
+ # options[:key_data] = [private_key] if private_key
160
+ # Fog::SCP.new(addresses['public'].first, username, options).upload(local_path, remote_path)
161
+ end
162
+
163
+ def setup(credentials = {})
164
+ raise 'Not Implemented'
165
+ # requires :addresses, :identity, :public_key, :username
166
+ # Fog::SSH.new(addresses['public'].first, username, credentials).run([
167
+ # %{mkdir .ssh},
168
+ # %{echo "#{public_key}" >> ~/.ssh/authorized_keys},
169
+ # %{passwd -l #{username}},
170
+ # %{echo "#{attributes.to_json}" >> ~/attributes.json},
171
+ # %{echo "#{metadata.to_json}" >> ~/metadata.json}
172
+ # ])
173
+ # rescue Errno::ECONNREFUSED
174
+ # sleep(1)
175
+ # retry
176
+ end
177
+
178
+ def ssh(commands)
179
+ raise 'Not Implemented'
180
+ # requires :addresses, :identity, :username
181
+ #
182
+ # options = {}
183
+ # options[:key_data] = [private_key] if private_key
184
+ # Fog::SSH.new(addresses['public'].first, username, options).run(commands)
185
+ end
186
+
187
+ def start(type = 'headless')
188
+ requires :raw
189
+ # session, type in ['gui', 'headless'], key[=value]\n env variables
190
+ raw.launch_vm_process(session, type, '').wait
191
+ true
192
+ end
193
+
194
+ def stop
195
+ requires :raw
196
+ session.console.power_down.wait
197
+ true
198
+ end
199
+
200
+ def storage_controllers
201
+ Fog::VirtualBox::Compute::StorageControllers.new(
202
+ :connection => connection,
203
+ :machine => self
204
+ )
205
+ end
206
+
207
+ def username
208
+ @username ||= 'root'
209
+ end
210
+
211
+ private
212
+
213
+ def raw
214
+ @raw
215
+ end
216
+
217
+ def raw=(new_raw)
218
+ @raw = new_raw
219
+ raw_attributes = {}
220
+ for key in [:id, :description, :memory_size, :name, :os_type_id, :state]
221
+ raw_attributes[key] = @raw.send(key)
222
+ end
223
+ merge_attributes(raw_attributes)
224
+ end
225
+
226
+ def session
227
+ ::VirtualBox::Lib.lib.session
228
+ end
229
+
230
+ def with_session
231
+ raw.lock_machine(session, :write)
232
+ yield session
233
+ session.unlock_machine
234
+ end
235
+
236
+ end
237
+
238
+ end
239
+ end
240
+
241
+ end