1and1 1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,227 @@
1
+ module OneAndOne
2
+
3
+
4
+ class SshKey
5
+
6
+
7
+ attr_accessor :id
8
+ attr_accessor :specs
9
+
10
+
11
+ def initialize(test: false)
12
+ @id = nil
13
+ @specs = nil
14
+
15
+ # Check if hitting mock api or live api
16
+ if test
17
+ @connection = Excon.new($base_url, :mock => true)
18
+ else
19
+ @connection = Excon.new($base_url)
20
+ end
21
+
22
+ end
23
+
24
+
25
+ def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)
26
+
27
+ # Build hash for query parameters
28
+ keyword_args = {
29
+ :page => page,
30
+ :per_page => per_page,
31
+ :sort => sort,
32
+ :q => q,
33
+ :fields => fields
34
+ }
35
+
36
+ # Clean out null query parameters
37
+ params = OneAndOne.clean_hash(keyword_args)
38
+
39
+ # Build URL
40
+ path = OneAndOne.build_url('/ssh_keys')
41
+
42
+ # Perform request
43
+ response = @connection.request(:method => :get,
44
+ :path => path,
45
+ :headers => $header,
46
+ :query => params)
47
+
48
+ # Check response status
49
+ OneAndOne.check_response(response.body, response.status)
50
+
51
+ #JSON-ify the response string
52
+ JSON.parse(response.body)
53
+
54
+ end
55
+
56
+
57
+ def create(name: nil, description: nil, public_key: nil)
58
+
59
+ # Build POST body
60
+ new_storage = {
61
+ 'name' => name,
62
+ 'description' => description,
63
+ 'public_key' => public_key
64
+ }
65
+
66
+ # Clean out null keys in POST body
67
+ body = OneAndOne.clean_hash(new_storage)
68
+
69
+ # Stringify the POST body
70
+ string_body = body.to_json
71
+
72
+ # Build URL
73
+ path = OneAndOne.build_url('/ssh_keys')
74
+
75
+ # Perform request
76
+ response = @connection.request(:method => :post,
77
+ :path => path,
78
+ :headers => $header,
79
+ :body => string_body)
80
+
81
+ # Check response status
82
+ OneAndOne.check_response(response.body, response.status)
83
+
84
+ #JSON-ify the response string
85
+ json = JSON.parse(response.body)
86
+
87
+ # Save new ssh key ID to SshKey instance
88
+ @id = json['id']
89
+ @specs = json
90
+
91
+ # If all good, return JSON
92
+ json
93
+
94
+ end
95
+
96
+
97
+ def get(ssh_key_id: @id)
98
+
99
+ # If user passed in ssh_key ID, reassign
100
+ @id = ssh_key_id
101
+
102
+ # Build URL
103
+ path = OneAndOne.build_url("/ssh_keys/#{@id}")
104
+
105
+ # Perform request
106
+ response = @connection.request(:method => :get,
107
+ :path => path,
108
+ :headers => $header)
109
+
110
+ # Check response status
111
+ OneAndOne.check_response(response.body, response.status)
112
+
113
+ #JSON-ify the response string
114
+ json = JSON.parse(response.body)
115
+
116
+ # Reload specs attribute
117
+ @specs = json
118
+
119
+ # If all good, return JSON
120
+ json
121
+
122
+ end
123
+
124
+
125
+ def modify(ssh_key_id: @id, name: nil, description: nil)
126
+
127
+ # If user passed in ssh_key ID, reassign
128
+ @id = ssh_key_id
129
+
130
+ # Build PUT body
131
+ new_storage = {
132
+ 'name' => name,
133
+ 'description' => description
134
+ }
135
+
136
+ # Clean out null keys in POST body
137
+ body = OneAndOne.clean_hash(new_storage)
138
+
139
+ # Stringify the POST body
140
+ string_body = body.to_json
141
+
142
+ # Build URL
143
+ path = OneAndOne.build_url("/ssh_keys/#{@id}")
144
+
145
+ # Perform request
146
+ response = @connection.request(:method => :put,
147
+ :path => path,
148
+ :headers => $header,
149
+ :body => string_body)
150
+
151
+ # Check response status
152
+ OneAndOne.check_response(response.body, response.status)
153
+
154
+ #JSON-ify the response string
155
+ JSON.parse(response.body)
156
+
157
+ end
158
+
159
+
160
+ def delete(ssh_key_id: @id)
161
+
162
+ # If user passed in ssh_key ID, reassign
163
+ @id = ssh_key_id
164
+
165
+ # Build URL
166
+ path = OneAndOne.build_url("/ssh_keys/#{@id}")
167
+
168
+ # Perform request
169
+ response = @connection.request(:method => :delete,
170
+ :path => path,
171
+ :headers => $header)
172
+
173
+ # Check response status
174
+ OneAndOne.check_response(response.body, response.status)
175
+
176
+ #JSON-ify the response string
177
+ JSON.parse(response.body)
178
+
179
+ end
180
+
181
+
182
+ def reload
183
+
184
+ # This reload fx is just a wrapper for the get fx
185
+ get
186
+
187
+ end
188
+
189
+
190
+ def wait_for(timeout: 25, interval: 5)
191
+
192
+ # Capture start time
193
+ start = Time.now
194
+
195
+ # Poll ssh key and check initial state
196
+ initial_response = get
197
+ ssh_key_state = initial_response['state']
198
+
199
+ # Keep polling the ssh key's state until good
200
+ until $good_states.include? ssh_key_state
201
+
202
+ # Wait 5 seconds before polling again
203
+ sleep interval
204
+
205
+ # Check ssh key state again
206
+ current_response = get
207
+ ssh_key_state = current_response['state']
208
+
209
+ # Calculate current duration and check for timeout
210
+ duration = (Time.now - start) / 60
211
+ if duration > timeout
212
+ puts "The operation timed out after #{timeout} minutes.\n"
213
+ return
214
+ end
215
+
216
+ end
217
+
218
+ # Return Duration
219
+ {:duration => duration}
220
+
221
+ end
222
+
223
+
224
+ end
225
+
226
+
227
+ end
@@ -24,4 +24,7 @@ module OneAndOne
24
24
  require_relative '1and1/ping_auth'
25
25
  require_relative '1and1/vpn'
26
26
  require_relative '1and1/role'
27
+ require_relative '1and1/block_storage'
28
+ require_relative '1and1/ssh_keys'
29
+ require_relative '1and1/recovery_appliance'
27
30
  end
@@ -0,0 +1,42 @@
1
+ Recovery Appliances
2
+ *****************
3
+
4
+ .. rb:class:: OneAndOne::RecoveryAppliance()
5
+
6
+ The :rb:class:`RecoveryAppliance` class allows a user to perform actions against the 1and1 API.
7
+
8
+
9
+ .. rb:method:: list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)
10
+
11
+ List all images available for recovering purposes.
12
+
13
+ :param page: Allows the use of pagination. Indicate which page to start on.
14
+ :type page: ``int``
15
+
16
+ :param per_page: Number of items per page.
17
+ :type per_page: ``int``
18
+
19
+ :param sort: ``sort: 'name'`` retrieves a list of elements sorted
20
+ alphabetically. ``sort: 'creation_date'`` retrieves a list of elements
21
+ sorted by their creation date in descending order.
22
+ :type sort: ``str``
23
+
24
+ :param q: ``q`` is for query. Use this parameter to return only the items
25
+ that match your search query.
26
+ :type q: ``str``
27
+
28
+ :param fields: Returns only the parameters requested.
29
+ (i.e. fields: 'id, name, description, hardware.ram')
30
+ :type fields: ``str``
31
+
32
+ :rtype: JSON
33
+
34
+
35
+ .. rb:method:: get(appliance_id: nil)
36
+
37
+ Returns information about a recovery appliance.
38
+
39
+ :param appliance_id: the unique identifier for the appliance.
40
+ :type appliance_id: ``str``
41
+
42
+ :rtype: JSON
@@ -0,0 +1,18 @@
1
+ {
2
+ "id": "6AD2F180B7B666539EF75A02FE227084",
3
+ "size": 200,
4
+ "state": "ACTIVE",
5
+ "description": "My block storage for containers",
6
+ "datacenter": {
7
+ "id": "D0F6D8C8ED29D3036F94C27BBB7BAD36",
8
+ "location": "USA",
9
+ "country_code": "US"
10
+ },
11
+ "name": "My block storage 1",
12
+ "creation_date": "2015-05-06T08:33:25+00:00",
13
+ "server":
14
+ {
15
+ "id": "638ED28205B1AFD7ADEF569C725DD85F",
16
+ "name": "My server 1"
17
+ }
18
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "id": "6AD2F180B7B666539EF75A02FE227084",
3
+ "size": 200,
4
+ "state": "CONFIGURING",
5
+ "description": "My block storage description",
6
+ "datacenter": {
7
+ "id": "D0F6D8C8ED29D3036F94C27BBB7BAD36",
8
+ "location": "USA",
9
+ "country_code": "US"
10
+ },
11
+ "name": "My block storage 4",
12
+ "creation_date": "2015-05-06T08:33:25+00:00",
13
+ "server": null
14
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "39AA65F5D5B02FA02D58173094EBAF95",
3
+ "name": "My SSH key 1",
4
+ "description": "My SSH key description",
5
+ "state": "ACTIVE",
6
+ "servers": [],
7
+ "md5": "5df9f63916ebf8528697b629022993e8",
8
+ "public_key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQAB",
9
+ "creation_date": "30-06-2015T 14:52:35+00.00"
10
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "id": "6AD2F180B7B666539EF75A02FE227084",
3
+ "size": 200,
4
+ "state": "REMOVING",
5
+ "description": "My block storage for containers",
6
+ "datacenter": {
7
+ "id": "D0F6D8C8ED29D3036F94C27BBB7BAD36",
8
+ "location": "USA",
9
+ "country_code": "US"
10
+ },
11
+ "name": "My block storage 1",
12
+ "creation_date": "2015-05-06T08:33:25+00:00",
13
+ "server":
14
+ {
15
+ "id": "638ED28205B1AFD7ADEF569C725DD85F",
16
+ "name": "My server 1"
17
+ }
18
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "39AA65F5D5B02FA02D58173094EBAF95",
3
+ "name": "My SSH key 1",
4
+ "description": "My SSH key description",
5
+ "state": "DELETING",
6
+ "servers": [
7
+ {"id": "D0F6D8C8ED29D3036F94C27BBB789536","name": "Server 1"},
8
+ {"id": "E0F6D8C8ED29D3036F94C27BBB789537","name": "Server 2"}
9
+ ],
10
+ "md5": "5df9f63916ebf8528697b629022993e8",
11
+ "public_key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQAB",
12
+ "creation_date": "30-06-2015T 14:52:35+00.00"
13
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "id": "6AD2F180B7B666539EF75A02FE227084",
3
+ "size": 200,
4
+ "state": "CONFIGURING",
5
+ "description": "My block storage for containers",
6
+ "datacenter": {
7
+ "id": "D0F6D8C8ED29D3036F94C27BBB7BAD36",
8
+ "location": "USA",
9
+ "country_code": "US"
10
+ },
11
+ "name": "My block storage 1",
12
+ "creation_date": "2015-05-06T08:33:25+00:00",
13
+ "server": null
14
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "id": "6AD2F180B7B666539EF75A02FE227084",
3
+ "size": 200,
4
+ "state": "ACTIVE",
5
+ "description": "My block storage for containers",
6
+ "datacenter": {
7
+ "id": "D0F6D8C8ED29D3036F94C27BBB7BAD36",
8
+ "location": "USA",
9
+ "country_code": "US"
10
+ },
11
+ "name": "My block storage 1",
12
+ "creation_date": "2015-05-06T08:33:25+00:00",
13
+ "server":
14
+ {
15
+ "id": "638ED28205B1AFD7ADEF569C725DD85F",
16
+ "name": "My server 1"
17
+ }
18
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "148CE80B09ED769373921F31CEE85E9E",
3
+ "name": "Windows 64-bit Rescue-System",
4
+ "os": "Other Windows",
5
+ "os_family": "Windows",
6
+ "os_version": "WindowsDatacenter",
7
+ "architecture": 64,
8
+ "available_datacenters": [
9
+ "908DC2072407C94C8054610AD5A53C2D",
10
+ "4EFAD5836CE43ACA502FD5B99BEE48GH",
11
+ "908DC2072407C94C8054610AD5A53C4D"
12
+ ]
13
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "id": "39AA65F5D5B02FA02D58173094EBAF95",
3
+ "name": "My SSH key 1",
4
+ "description": "My SSH key description",
5
+ "state": "ACTIVE",
6
+ "servers": [
7
+ {"id": "D0F6D8C8ED29D3036F94C27BBB789536","name": "Server 1"},
8
+ {"id": "E0F6D8C8ED29D3036F94C27BBB789537","name": "Server 2"}
9
+ ],
10
+ "md5": "5df9f63916ebf8528697b629022993e8",
11
+ "public_key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQAB",
12
+ "creation_date": "30-06-2015T 14:52:35+00.00"
13
+ }
@@ -0,0 +1,52 @@
1
+ [
2
+ {
3
+ "id": "6AD2F180B7B666539EF75A02FE227084",
4
+ "size": 200,
5
+ "state": "ACTIVE",
6
+ "description": "My block storage for containers",
7
+ "datacenter": {
8
+ "id": "D0F6D8C8ED29D3036F94C27BBB7BAD36",
9
+ "location": "USA",
10
+ "country_code": "US"
11
+ },
12
+ "name": "My block storage 1",
13
+ "creation_date": "2015-05-06T08:33:25+00:00",
14
+ "server":
15
+ {
16
+ "id": "638ED28205B1AFD7ADEF569C725DD85F",
17
+ "name": "My server 1"
18
+ }
19
+ },
20
+ {
21
+ "id": "4406CE4723BB441C7956E25C51CE8C1B",
22
+ "size": 50,
23
+ "state": "ACTIVE",
24
+ "description": "My block storage description",
25
+ "datacenter": {
26
+ "id": "D0F6D8C8ED29D3036F94C27BBB7BAD36",
27
+ "location": "USA",
28
+ "country_code": "US"
29
+ },
30
+ "name": "My block storage 3",
31
+ "creation_date": "2015-03-17T11:57:48+00:00",
32
+ "server": null
33
+ },
34
+ {
35
+ "id": "1A5418172DD3BD39F8010A6633F1018A",
36
+ "size": 250,
37
+ "state": "ACTIVE",
38
+ "description": "",
39
+ "datacenter": {
40
+ "id": "D0F6D8C8ED29D3036F94C27BBB7BAD36",
41
+ "location": "USA",
42
+ "country_code": "US"
43
+ },
44
+ "name": "My block storage 2",
45
+ "creation_date": "2015-05-05T09:36:31+00:00",
46
+ "server":
47
+ {
48
+ "id": "748ED28205B1AFD7ADEF569C725DD85E",
49
+ "name": "My server 2"
50
+ }
51
+ }
52
+ ]