squall 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -1
  3. data/README.md +64 -41
  4. data/Rakefile +3 -9
  5. data/lib/squall/data_store_zone.rb +20 -26
  6. data/lib/squall/disk.rb +174 -0
  7. data/lib/squall/firewall_rule.rb +34 -41
  8. data/lib/squall/hypervisor.rb +40 -38
  9. data/lib/squall/hypervisor_zone.rb +51 -63
  10. data/lib/squall/ip_address.rb +32 -37
  11. data/lib/squall/ip_address_join.rb +13 -22
  12. data/lib/squall/network.rb +36 -33
  13. data/lib/squall/network_zone.rb +27 -29
  14. data/lib/squall/payment.rb +22 -32
  15. data/lib/squall/role.rb +30 -37
  16. data/lib/squall/statistic.rb +3 -1
  17. data/lib/squall/support/base.rb +35 -31
  18. data/lib/squall/support/config.rb +25 -1
  19. data/lib/squall/support/version.rb +1 -1
  20. data/lib/squall/template.rb +7 -5
  21. data/lib/squall/transaction.rb +6 -4
  22. data/lib/squall/user.rb +84 -83
  23. data/lib/squall/user_group.rb +17 -30
  24. data/lib/squall/virtual_machine.rb +154 -178
  25. data/lib/squall/whitelist.rb +29 -40
  26. data/lib/squall.rb +27 -25
  27. data/spec/spec_helper.rb +6 -11
  28. data/spec/squall/data_store_zone_spec.rb +2 -20
  29. data/spec/squall/disk_spec.rb +189 -0
  30. data/spec/squall/firewall_rule_spec.rb +2 -32
  31. data/spec/squall/hypervisor_spec.rb +3 -47
  32. data/spec/squall/hypervisor_zone_spec.rb +3 -28
  33. data/spec/squall/ip_address_join_spec.rb +1 -15
  34. data/spec/squall/ip_address_spec.rb +10 -35
  35. data/spec/squall/network_spec.rb +20 -31
  36. data/spec/squall/network_zone_spec.rb +2 -36
  37. data/spec/squall/payment_spec.rb +2 -21
  38. data/spec/squall/role_spec.rb +4 -16
  39. data/spec/squall/support/base_spec.rb +10 -16
  40. data/spec/squall/template_spec.rb +0 -4
  41. data/spec/squall/transaction_spec.rb +1 -3
  42. data/spec/squall/user_group_spec.rb +1 -17
  43. data/spec/squall/user_spec.rb +4 -92
  44. data/spec/squall/virtual_machine_spec.rb +8 -242
  45. data/spec/squall/whitelist_spec.rb +2 -40
  46. data/spec/squall_spec.rb +2 -2
  47. data/spec/vcr_cassettes/disk/add_schedule.yml +40 -0
  48. data/spec/vcr_cassettes/disk/auto_backup_off.yml +40 -0
  49. data/spec/vcr_cassettes/disk/auto_backup_on.yml +40 -0
  50. data/spec/vcr_cassettes/disk/backups.yml +40 -0
  51. data/spec/vcr_cassettes/disk/build.yml +40 -0
  52. data/spec/vcr_cassettes/disk/create.yml +40 -0
  53. data/spec/vcr_cassettes/disk/delete.yml +38 -0
  54. data/spec/vcr_cassettes/disk/edit.yml +40 -0
  55. data/spec/vcr_cassettes/disk/iops_usage.yml +40 -0
  56. data/spec/vcr_cassettes/disk/list.yml +40 -0
  57. data/spec/vcr_cassettes/disk/migrate.yml +38 -0
  58. data/spec/vcr_cassettes/disk/schedules.yml +40 -0
  59. data/spec/vcr_cassettes/disk/unlock.yml +40 -0
  60. data/spec/vcr_cassettes/disk/vm_disk_list.yml +40 -0
  61. data/spec/vcr_cassettes/network/rebuild.yml +41 -0
  62. metadata +217 -66
  63. data/.gitignore +0 -13
  64. data/.rspec +0 -2
  65. data/.rvmrc +0 -41
  66. data/.travis.yml +0 -17
  67. data/lib/squall/support/params.rb +0 -50
  68. data/lib/squall/support/yaml.rb +0 -5
  69. data/spec/squall/support/params_spec.rb +0 -195
  70. data/squall.gemspec +0 -32
@@ -1,110 +1,112 @@
1
1
  module Squall
2
2
  # OnApp Hypervisor
3
3
  class Hypervisor < Base
4
-
5
- # Returns a list of all hypervisors
4
+ # Public: Lists all hypervisors.
5
+ #
6
+ # Returns an Array.
6
7
  def list
7
8
  req = request(:get, '/settings/hypervisors.json')
8
9
  req.collect { |hv| hv['hypervisor'] }
9
10
  end
10
11
 
11
- # Returns the hypervisor info as a hash
12
+ # Public: Retrieves hypervisor info.
12
13
  #
13
- # ==== Params
14
+ # id - The id of the hypervisor
14
15
  #
15
- # * +id+ - The id of the hypervisor
16
+ # Returns a Hash.
16
17
  def show(id)
17
18
  req = request(:get, "/settings/hypervisors/#{id}.json")
18
19
  req.first[1]
19
20
  end
20
21
 
21
- # Create a new Hypervisor
22
- #
23
- # ==== Params
22
+ # Public: Create a new Hypervisor.
24
23
  #
25
- # * +options+ - Options for creating the hypervisor
24
+ # options - Options for creating the hypervisor:
25
+ # :label - Label for the hypervisor
26
+ # :ip_address - IP for the hypervisor
27
+ # :hypervisor_type - Type of the hypervisor
26
28
  #
27
- # ==== Options
29
+ # Example
28
30
  #
29
- # * +label*+ - Label for the hypervisor
30
- # * +ip_address*+ - IP for the hypervisor
31
- # * +hypervisor_type*+ - Type of the hypervisor
31
+ # create(
32
+ # label: 'myhv',
33
+ # ip_address: '127.0.0.1',
34
+ # hypervisor_type: 'xen'
35
+ # )
32
36
  #
33
- # ==== Example
34
- #
35
- # create :label => 'myhv', :ip_address => '127.0.0.1', :hypervisor_type => 'xen'
37
+ # Returns a Hash.
36
38
  def create(options = {})
37
- params.required(:label, :ip_address, :hypervisor_type).accepts(:memory_overhead, :enabled, :hypervisor_group_id, :disable_failover).validate!(options)
38
39
  req = request(:post, '/settings/hypervisors.json', default_params(options))
39
40
  req.first[1]
40
41
  end
41
42
 
42
- # Edit a Hypervisor
43
- #
44
- # ==== Params
45
- #
46
- # * +id*+ - ID of the hypervisor
47
- # * +options+ - Params for editing the Hypervisor
43
+ # Public: Edit a Hypervisor.
48
44
  #
49
- # ==== Options
45
+ # id - ID of the hypervisor
46
+ # options - Params for editing the Hypervisor, see `#create`.
50
47
  #
51
- # See #create
48
+ # Example
52
49
  #
53
- # ==== Example
50
+ # edit 1, label: 'myhv', ip_address: '127.0.0.1'
54
51
  #
55
- # edit 1, :label => 'myhv', :ip_address => '127.0.0.1'
56
- def edit(id, options ={})
57
- params.accepts(:label, :ip_address, :hypervisor_type, :memory_overhead, :enabled, :hypervisor_group_id, :disable_failover).validate!(options)
52
+ # Returns a Hash.
53
+ def edit(id, options = {})
58
54
  request(:put, "/settings/hypervisors/#{id}.json", default_params(options))
59
55
  end
60
56
 
61
- # Reboot a hypervisor
57
+ # Public: Reboot a hypervisor.
62
58
  #
63
- # ==== Params
59
+ # id - ID of the hypervisor
64
60
  #
65
- # * +id*+ - ID of the hypervisor
61
+ # Returns a Hash.
66
62
  def reboot(id)
67
63
  response = request(:get, "/settings/hypervisors/#{id}/rebooting.json")
68
64
  response['hypervisor']
69
65
  end
70
66
 
71
- # Delete a hypervisor
67
+ # Public: Delete a hypervisor
72
68
  #
73
- # ==== Params
69
+ # id - ID of the hypervisor
74
70
  #
75
- # * +id*+ - ID of the hypervisor
71
+ # Returns a Hash.
76
72
  def delete(id)
77
73
  req = request(:delete, "/settings/hypervisors/#{id}.json")
78
74
  end
79
75
 
76
+ # TODO: Add documentation
80
77
  def virtual_machines(id)
81
78
  response = request(:get, "/settings/hypervisors/#{id}/virtual_machines.json")
82
79
  response.collect { |vm| vm['virtual_machine'] }
83
80
  end
84
81
 
82
+ # TODO: Add documentation
85
83
  def data_store_joins(id)
86
84
  response = request(:get, "/settings/hypervisors/#{id}/data_store_joins.json")
87
85
  response.collect { |dsj| dsj['data_store_join'] }
88
86
  end
89
87
 
88
+ # TODO: Add documentation
90
89
  def add_data_store_join(id, data_store_id)
91
- request(:post, "/settings/hypervisors/#{id}/data_store_joins.json", :query => {:data_store_id => data_store_id})
90
+ request(:post, "/settings/hypervisors/#{id}/data_store_joins.json", query: { data_store_id: data_store_id })
92
91
  end
93
92
 
93
+ # TODO: Add documentation
94
94
  def remove_data_store_join(id, data_store_join_id)
95
95
  request(:delete, "/settings/hypervisors/#{id}/data_store_joins/#{data_store_join_id}.json")
96
96
  end
97
97
 
98
+ # TODO: Add documentation
98
99
  def network_joins(id)
99
100
  response = request(:get, "/settings/hypervisors/#{id}/network_joins.json")
100
101
  response.collect { |nj| nj['network_join'] }
101
102
  end
102
103
 
104
+ # TODO: Add documentation
103
105
  def add_network_join(id, options)
104
- params.required(:network_id, :interface).validate!(options)
105
- request(:post, "/settings/hypervisors/#{id}/network_joins.json", :query => {:network_join => options})
106
+ request(:post, "/settings/hypervisors/#{id}/network_joins.json", query: { network_join: options })
106
107
  end
107
108
 
109
+ # TODO: Add documentation
108
110
  def remove_network_join(id, network_join_id)
109
111
  request(:delete, "/settings/hypervisors/#{id}/network_joins/#{network_join_id}.json")
110
112
  end
@@ -1,135 +1,123 @@
1
1
  module Squall
2
2
  # OnApp HypervisorZone
3
3
  class HypervisorZone < Base
4
- # Returns a list of hypervisor zones
4
+ # Public: Lists all hypervisor zones.
5
+ #
6
+ # Returns an Array.
5
7
  def list
6
8
  response = request(:get, "/settings/hypervisor_zones.json")
7
9
  response.collect { |i| i['hypervisor_group'] }
8
10
  end
9
11
 
10
- # Get the details for a hypervisor zone
12
+ # Public: Get the details for a hypervisor zone.
11
13
  #
12
- # ==== Params
14
+ # id - ID of the hypervisor zone
13
15
  #
14
- # * +id*+ - ID of the hypervisor zone
16
+ # Returns a Hash.
15
17
  def show(id)
16
18
  response = request(:get, "/settings/hypervisor_zones/#{id}.json")
17
19
  response['hypervisor_group']
18
20
  end
19
21
 
20
- # Updates an existing hypervisor zone
21
- #
22
- # ==== Params
23
- #
24
- # * +id*+ - ID of the hypervisor zone
25
- # * +options+ - Params for updating the hypervisor zone
22
+ # Public: Creates a new hypervisor zone.
26
23
  #
27
- # ==== Options
24
+ # options - Params for updating the hypervisor zone:
25
+ # :label - Label for the hypervisor zone
28
26
  #
29
- # See #create
30
- def edit(id, options = {})
31
- params.required(:label).validate!(options)
32
- response = request(:put, "/settings/hypervisor_zones/#{id}.json", :query => {:pack => options})
27
+ # Returns a Hash
28
+ def create(options = {})
29
+ request(:post, "/settings/hypervisor_zones.json", query: { pack: options })
33
30
  end
34
31
 
35
- # Creates a new hypervisor zone
36
- #
37
- # ==== Params
32
+ # Public: Updates an existing hypervisor zone.
38
33
  #
39
- # * +options+ - Params for updating the hypervisor zone
34
+ # id - ID of the hypervisor zone
35
+ # options - Params for updating the hypervisor zone, see `#create`
40
36
  #
41
- # ==== Options
42
- #
43
- # * +label*+ - Label for the hypervisor zone
44
- def create(options = {})
45
- params.required(:label).validate!(options)
46
- response = request(:post, "/settings/hypervisor_zones.json", :query => {:pack => options})
37
+ # Returns a Hash.
38
+ def edit(id, options = {})
39
+ request(:put, "/settings/hypervisor_zones/#{id}.json", query: { pack: options })
47
40
  end
48
41
 
49
- # Deletes an existing hypervisor zone
42
+ # Public: Deletes an existing hypervisor zone.
50
43
  #
51
- # ==== Params
44
+ # id - ID of the hypervisor zone
52
45
  #
53
- # * +id*+ - ID of the hypervisor zone
46
+ # Returns a Hash.
54
47
  def delete(id)
55
48
  request(:delete, "/settings/hypervisor_zones/#{id}.json")
56
49
  end
57
50
 
58
- # Get the list of hypervisors attached to a zone
51
+ # Public: List hypervisors attached to a zone.
59
52
  #
60
- # ==== Params
53
+ # id - ID of the hypervisor zone
61
54
  #
62
- # * +id*+ - ID of the hypervisor zone
55
+ # Returns an Array.
63
56
  def hypervisors(id)
64
57
  response = request(:get, "/settings/hypervisor_zones/#{id}/hypervisors.json")
65
58
  response.collect { |hv| hv['hypervisor'] }
66
59
  end
67
60
 
68
- # Get the list of data store joins attached to a hypervisor zone
61
+ # Public: List data store joins attached to a hypervisor zone.
69
62
  #
70
- # ==== Params
63
+ # id - ID of the hypervisor zone
71
64
  #
72
- # * +id*+ - ID of the hypervisor zone
65
+ # Returns an Array.
73
66
  def data_store_joins(id)
74
67
  response = request(:get, "/settings/hypervisor_zones/#{id}/data_store_joins.json")
75
68
  response.collect { |i| i['data_store_join'] }
76
69
  end
77
70
 
78
- # Add a data store to a hypervisor zone
71
+ # Public: Add a data store to a hypervisor zone.
79
72
  #
80
- # ==== Params
73
+ # id - ID of the hypervisor zone
74
+ # data_store_id - ID of the data store
81
75
  #
82
- # * +id*+ - ID of the hypervisor zone
83
- # * +data_store_id*+ - ID of the data store
76
+ # Returns a Hash.
84
77
  def add_data_store_join(id, data_store_id)
85
- request(:post, "/settings/hypervisor_zones/#{id}/data_store_joins.json", :query => {:data_store_id => data_store_id})
78
+ request(:post, "/settings/hypervisor_zones/#{id}/data_store_joins.json", query: { data_store_id: data_store_id })
86
79
  end
87
80
 
88
- # Remove a data store from a hypervisor zone
81
+ # Public: Remove a data store from a hypervisor zone.
89
82
  #
90
- # ==== Params
83
+ # id - ID of the hypervisor zone
84
+ # data_store_join_id - ID of the join record
91
85
  #
92
- # * +id*+ - ID of the hypervisor zone
93
- # * +data_store_join_id*+ - ID of the join record
86
+ # Returns a Hash.
94
87
  def remove_data_store_join(id, data_store_join_id)
95
88
  request(:delete, "/settings/hypervisor_zones/#{id}/data_store_joins/#{data_store_join_id}.json")
96
89
  end
97
90
 
98
- # Get the list of networks attached to a hypervisor zone
91
+ # Public: List networks attached to a hypervisor zone.
99
92
  #
100
- # ==== Params
93
+ # id - ID of the hypervisor zone
101
94
  #
102
- # * +id*+ - ID of the hypervisor zone
95
+ # Returns an Array.
103
96
  def network_joins(id)
104
97
  response = request(:get, "/settings/hypervisor_zones/#{id}/network_joins.json")
105
98
  response.collect { |i| i['network_join'] }
106
99
  end
107
100
 
108
- # Add a network to a hypervisor zone
101
+ # Public: Add a network to a hypervisor zone
109
102
  #
110
- # ==== Params
103
+ # id - ID of the hypervisor zone
104
+ # options - Params for updating the hypervisor zone
105
+ # :network_id - ID of the network to add to the hypervisor zone
106
+ # :interface - Name of the appropriate network interface
111
107
  #
112
- # * +id*+ - ID of the hypervisor zone
113
- # * +options+ - Params for updating the hypervisor zone
114
- #
115
- # ==== Options
116
- #
117
- # * +network_id*+ - The ID of the network to add to the hypervisor zone
118
- # * +interface*+ - The name of the appropriate network interface
119
- def add_network_join(id, options={})
120
- params.required(:network_id, :interface).validate!(options)
121
- request(:post, "/settings/hypervisor_zones/#{id}/network_joins.json", :query => {:network_join => options})
108
+ # Returns a Hash.
109
+ def add_network_join(id, options = {})
110
+ request(:post, "/settings/hypervisor_zones/#{id}/network_joins.json", query: { network_join: options })
122
111
  end
123
112
 
124
- # Remove a network from a hypervisor zone
113
+ # Public: Remove a network from a hypervisor zone.
125
114
  #
126
- # ==== Params
115
+ # id - ID of the hypervisor zone
116
+ # network_join_id - ID of the join record
127
117
  #
128
- # * +id*+ - ID of the hypervisor zone
129
- # * +network_join_id*+ - ID of the join record
118
+ # Returns a Hash.
130
119
  def remove_network_join(id, network_join_id)
131
120
  request(:delete, "/settings/hypervisor_zones/#{id}/network_joins/#{network_join_id}.json")
132
121
  end
133
-
134
122
  end
135
123
  end
@@ -1,58 +1,53 @@
1
1
  module Squall
2
2
  # OnApp IpAddress
3
3
  class IpAddress < Base
4
- # Returns a list of ip addresses for a network
4
+ # Public: Lists IP addresses for a network.
5
5
  #
6
- # ==== Params
6
+ # network_id - ID of the network
7
7
  #
8
- # * +network_id+ - ID of the network
8
+ # Returns an Array.
9
9
  def list(network_id)
10
10
  response = request(:get, "/settings/networks/#{network_id}/ip_addresses.json")
11
11
  response.collect { |ip| ip['ip_address'] }
12
12
  end
13
13
 
14
- # Updates an existing ip address
15
- #
16
- # ==== Params
17
- #
18
- # * +network_id+ - ID of the network
19
- # * +id+ - ID of the ip address
20
- # * +options+ - Params for updating the ip address
21
- #
22
- # ==== Options
23
- #
24
- # See #create
25
- def edit(network_id, id, options = {})
26
- params.accepts(:address, :netmask, :broadcast, :network_address, :gateway, :disallowed_primary).validate!(options)
27
- response = request(:put, "/settings/networks/#{network_id}/ip_addresses/#{id}.json", default_params(options))
14
+ # Public: Creates a new IpAddress
15
+ #
16
+ # network_id - ID of the network
17
+ # options - Params for the new ip address
18
+ # :address - IP address
19
+ # :broadcast - A logical address at which all devices
20
+ # connected to a multiple-access
21
+ # communications network are enabled to
22
+ # receive datagrams
23
+ # :disallowed_primary - Set to '1' to prevent this address
24
+ # being used as primary
25
+ # :gateway - Gateway address
26
+ # :netmask - Network mask
27
+ # :network_address - IP address of network
28
+ #
29
+ # Returns a Hash.
30
+ def create(network_id, options = {})
31
+ request(:post, "/settings/networks/#{network_id}/ip_addresses.json", default_params(options))
28
32
  end
29
33
 
30
- # Creates a new IpAddress
31
- #
32
- # ==== Params
33
- #
34
- # * +network_id+ - ID of the network
35
- # * +options+ - Params for the new ip address
34
+ # Public: Updates an existing ip address.
36
35
  #
37
- # ==== Options
36
+ # network_id - ID of the network
37
+ # id - ID of the ip address
38
+ # options - Params for updating the ip address, see `#create`
38
39
  #
39
- # * +address*+ - IP address
40
- # * +netmask*+ - Network mask
41
- # * +broadcast*+ - A logical address at which all devices connected to a multiple-access communications network are enabled to receive datagrams
42
- # * +network_address*+ - IP address of network
43
- # * +gateway*+ - Gateway address
44
- # * +disallowed_primary+ - Set to '1' to prevent this address being used as primary
45
- def create(network_id, options = {})
46
- params.required(:address, :netmask, :broadcast, :network_address, :gateway).accepts(:disallowed_primary).validate!(options)
47
- response = request(:post, "/settings/networks/#{network_id}/ip_addresses.json", default_params(options))
40
+ # Returns a Hash.
41
+ def edit(network_id, id, options = {})
42
+ request(:put, "/settings/networks/#{network_id}/ip_addresses/#{id}.json", default_params(options))
48
43
  end
49
44
 
50
- # Deletes an existing ip address
45
+ # Public: Deletes an existing ip address.
51
46
  #
52
- # ==== Params
47
+ # network_id - ID of the network
48
+ # id - ID of the ip address
53
49
  #
54
- # * +network_id+ - ID of the network
55
- # * +id+ - ID of the ip address
50
+ # Returns a Hash.
56
51
  def delete(network_id, id)
57
52
  request(:delete, "/settings/networks/#{network_id}/ip_addresses/#{id}.json")
58
53
  end
@@ -1,44 +1,35 @@
1
1
  module Squall
2
2
  # Handles IP assignments for virtual machines
3
3
  class IpAddressJoin < Base
4
-
5
- # Get the list of IP address assignments for a particular virtual machine
4
+ # Public: List IP address assignments for a virtual machine.
6
5
  #
7
- # ==== Params
6
+ # virtual_machine_id - Virtual machine ID to lookup
8
7
  #
9
- # * +virtual_machine_id*+ - Virtual machine ID to lookup
8
+ # Returns an Array.
10
9
  def list(virtual_machine_id)
11
10
  response = request(:get, "/virtual_machines/#{virtual_machine_id}/ip_addresses.json")
12
11
  response.collect { |ip| ip['ip_address_join'] }
13
12
  end
14
13
 
15
- # Assigns an IP address to a VM
16
- #
17
- # ==== Params
18
- #
19
- # * +virtual_machine_id*+ - Virtual machine ID to assign IP to
20
- # * +options+ - Params for IP assignment
14
+ # Public: Assigns an IP address to a VM.
21
15
  #
22
- # ==== Options
16
+ # virtual_machine_id - Virtual machine ID to assign IP to
17
+ # options - Params for IP assignment:
18
+ # :ip_address_id - ID of the IP address
19
+ # :network_interface_id - ID of the network interface
23
20
  #
24
- # * +ip_address_id*+ - ID of the IP address
25
- # * +network_interface_id*+ - ID of the network interface id
21
+ # Returns a Hash.
26
22
  def assign(virtual_machine_id, options = {})
27
- params.required(:ip_address_id, :network_interface_id).validate!(options)
28
23
  response = request(:post, "/virtual_machines/#{virtual_machine_id}/ip_addresses.json", default_params(options))
29
24
  response['ip_address_join']
30
25
  end
31
26
 
32
- # Deletes an IP address assignment from a VM
33
- #
34
- # ==== Params
35
- #
36
- # * +virtual_machine_id+ - Virtual machine ID to remove IP join from
37
- # * +ip_address_id+ - IP Address ID to remove
27
+ # Public: Deletes an IP address assignment from a VM
38
28
  #
39
- # ==== Options
29
+ # virtual_machine_id - Virtual machine ID to remove IP join from
30
+ # ip_address_id - IP Address ID to remove, see `#assign`.
40
31
  #
41
- # See #assign
32
+ # Returns a Hash.
42
33
  def delete(virtual_machine_id, ip_address_id)
43
34
  request(:delete, "/virtual_machines/#{virtual_machine_id}/ip_addresses/#{ip_address_id}.json")
44
35
  end
@@ -1,59 +1,62 @@
1
1
  module Squall
2
2
  # OnApp Network
3
3
  class Network < Base
4
- # Returns a list of Networks
4
+ # Public: Lists all networks.
5
+ #
6
+ # Returns an Array.
5
7
  def list
6
8
  response = request(:get, '/settings/networks.json')
7
9
  response.collect { |network| network['network'] }
8
10
  end
9
11
 
10
- # Edit a Network
12
+ # Public: Create a Network.
11
13
  #
12
- # ==== Params
14
+ # options - Params for creating the Network:
15
+ # :label
16
+ # :vlan
17
+ # :identifier
13
18
  #
14
- # * +id*+ - ID of the network
15
- # * +options+ - Params for editing the Network
19
+ # Example
16
20
  #
17
- # ==== Options
21
+ # create(
22
+ # label: 'mynetwork',
23
+ # network_group_id: 1,
24
+ # vlan: 2,
25
+ # identifier: 'something'
26
+ # )
18
27
  #
19
- # See #create
28
+ # Returns a Hash.
29
+ def create(options = {})
30
+ response = request(:post, '/settings/networks.json', default_params(options))
31
+ response.first[1]
32
+ end
33
+
34
+ # Public: Edit a Network
20
35
  #
21
- # ==== Example
36
+ # id - ID of the network
37
+ # options - Params for editing the Network, see `#create`
22
38
  #
23
- # edit 1, :label => 'mynetwork', :network_group_id => 1, :vlan => 2, :identifier => 'something'
39
+ # Returns a Hash.
24
40
  def edit(id, options = {})
25
- params.accepts(:label, :network_group_id, :vlan, :identifier).validate!(options)
26
- response = request(:put, "/settings/networks/#{id}.json", default_params(options))
41
+ request(:put, "/settings/networks/#{id}.json", default_params(options))
27
42
  end
28
43
 
29
- # Create a Network
30
- #
31
- # ==== Params
32
- #
33
- # * +options+ - Params for creating the Network
34
- #
35
- # ==== Options
44
+ # Public: Delete a network.
36
45
  #
37
- # * +label*+
38
- # * +vlan+
39
- # * +identifier+
46
+ # id - ID of the network
40
47
  #
41
- # ==== Example
42
- #
43
- # create :label => 'mynetwork', :network_group_id => 1, :vlan => 2, :identifier => 'something'
44
- def create(options = {})
45
- params.accepts(:vlan, :identifier).required(:label).validate!(options)
46
- response = request(:post, '/settings/networks.json', default_params(options))
47
- response.first[1]
48
+ # Returns a Hash.
49
+ def delete(id)
50
+ request(:delete, "/settings/networks/#{id}.json")
48
51
  end
49
52
 
50
- # Delete a network
53
+ # Public: Rebuild VM network.
51
54
  #
52
- # ==== Params
55
+ # id - ID of the virtual machine
53
56
  #
54
- # * +id*+ - ID of the network
55
- def delete(id)
56
- request(:delete, "/settings/networks/#{id}.json")
57
+ # Returns a Hash.
58
+ def rebuild(id)
59
+ request(:post, "/virtual_machines/#{id}/rebuild_network.json")
57
60
  end
58
61
  end
59
62
  end