1and1 1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ module OneAndOne
3
3
 
4
4
  class Server
5
5
 
6
-
6
+
7
7
  attr_accessor :id
8
8
  attr_accessor :first_ip
9
9
  attr_accessor :first_password
@@ -45,9 +45,40 @@ module OneAndOne
45
45
 
46
46
  # Perform request
47
47
  response = @connection.request(:method => :get,
48
- :path => path,
49
- :headers => $header,
50
- :query => params)
48
+ :path => path,
49
+ :headers => $header,
50
+ :query => params)
51
+
52
+ # Check response status
53
+ OneAndOne.check_response(response.body, response.status)
54
+
55
+ #JSON-ify the response string
56
+ JSON.parse(response.body)
57
+
58
+ end
59
+
60
+ def list_baremetal_models(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)
61
+
62
+ # Build hash for query parameters
63
+ keyword_args = {
64
+ :page => page,
65
+ :per_page => per_page,
66
+ :sort => sort,
67
+ :q => q,
68
+ :fields => fields
69
+ }
70
+
71
+ # Clean out null query parameters
72
+ params = OneAndOne.clean_hash(keyword_args)
73
+
74
+ # Build URL
75
+ path = OneAndOne.build_url('/servers/baremetal_models')
76
+
77
+ # Perform request
78
+ response = @connection.request(:method => :get,
79
+ :path => path,
80
+ :headers => $header,
81
+ :query => params)
51
82
 
52
83
  # Check response status
53
84
  OneAndOne.check_response(response.body, response.status)
@@ -62,7 +93,10 @@ module OneAndOne
62
93
  vcore: nil, cores_per_processor: nil, ram: nil, appliance_id: nil,
63
94
  datacenter_id: nil, hdds: nil, password: nil, power_on: nil,
64
95
  firewall_id: nil, ip_id: nil, load_balancer_id: nil,
65
- monitoring_policy_id: nil)
96
+ monitoring_policy_id: nil, public_key: nil, server_type: nil,
97
+ baremetal_model_id: nil)
98
+
99
+ server_type = 'cloud' if server_type.nil?
66
100
 
67
101
  # Build hardware hash
68
102
  hardware_params = {
@@ -73,6 +107,8 @@ module OneAndOne
73
107
  'hdds' => hdds
74
108
  }
75
109
 
110
+ hardware_params['baremetal_model_id'] = baremetal_model_id if server_type == 'baremetal'
111
+
76
112
  # Clean out null keys in hardware hash
77
113
  hardware = OneAndOne.clean_hash(hardware_params)
78
114
 
@@ -89,7 +125,9 @@ module OneAndOne
89
125
  'firewall_policy_id' => firewall_id,
90
126
  'ip_id' => ip_id,
91
127
  'load_balancer_id' => load_balancer_id,
92
- 'monitoring_policy_id' => monitoring_policy_id
128
+ 'monitoring_policy_id' => monitoring_policy_id,
129
+ 'public_key' => public_key,
130
+ 'server_type' => server_type
93
131
  }
94
132
 
95
133
  # Clean out null keys in POST body
@@ -103,9 +141,9 @@ module OneAndOne
103
141
 
104
142
  # Perform request
105
143
  response = @connection.request(:method => :post,
106
- :path => path,
107
- :headers => $header,
108
- :body => string_body)
144
+ :path => path,
145
+ :headers => $header,
146
+ :body => string_body)
109
147
 
110
148
  # Check response status
111
149
  OneAndOne.check_response(response.body, response.status)
@@ -131,8 +169,8 @@ module OneAndOne
131
169
 
132
170
  # Perform request
133
171
  response = @connection.request(:method => :get,
134
- :path => path,
135
- :headers => $header)
172
+ :path => path,
173
+ :headers => $header)
136
174
 
137
175
  # Check response status
138
176
  OneAndOne.check_response(response.body, response.status)
@@ -150,8 +188,8 @@ module OneAndOne
150
188
 
151
189
  # Perform request
152
190
  response = @connection.request(:method => :get,
153
- :path => path,
154
- :headers => $header)
191
+ :path => path,
192
+ :headers => $header)
155
193
 
156
194
  # Check response status
157
195
  OneAndOne.check_response(response.body, response.status)
@@ -172,8 +210,35 @@ module OneAndOne
172
210
 
173
211
  # Perform request
174
212
  response = @connection.request(:method => :get,
175
- :path => path,
176
- :headers => $header)
213
+ :path => path,
214
+ :headers => $header)
215
+
216
+ # Check response status
217
+ OneAndOne.check_response(response.body, response.status)
218
+
219
+ #JSON-ify the response string
220
+ json = JSON.parse(response.body)
221
+
222
+ # Reload specs attribute
223
+ @specs = json
224
+
225
+ # If all good, return JSON
226
+ json
227
+
228
+ end
229
+
230
+ def get_baremetal(baremetal_id: @id)
231
+
232
+ # If user passed in baremetal ID, reassign
233
+ @id = baremetal_id
234
+
235
+ # Build URL
236
+ path = OneAndOne.build_url("/servers/baremetal_models/#{@id}")
237
+
238
+ # Perform request
239
+ response = @connection.request(:method => :get,
240
+ :path => path,
241
+ :headers => $header)
177
242
 
178
243
  # Check response status
179
244
  OneAndOne.check_response(response.body, response.status)
@@ -212,9 +277,9 @@ module OneAndOne
212
277
 
213
278
  # Perform Request
214
279
  response = @connection.request(:method => :put,
215
- :path => path,
216
- :headers => $header,
217
- :body => string_body)
280
+ :path => path,
281
+ :headers => $header,
282
+ :body => string_body)
218
283
 
219
284
  # Check response status
220
285
  OneAndOne.check_response(response.body, response.status)
@@ -243,9 +308,9 @@ module OneAndOne
243
308
 
244
309
  # Perform request
245
310
  response = @connection.request(:method => :delete,
246
- :path => path,
247
- :headers => $header,
248
- :query => params)
311
+ :path => path,
312
+ :headers => $header,
313
+ :query => params)
249
314
 
250
315
  # Check response status
251
316
  OneAndOne.check_response(response.body, response.status)
@@ -266,8 +331,8 @@ module OneAndOne
266
331
 
267
332
  # Perform request
268
333
  response = @connection.request(:method => :get,
269
- :path => path,
270
- :headers => $header)
334
+ :path => path,
335
+ :headers => $header)
271
336
 
272
337
  # Check response status
273
338
  OneAndOne.check_response(response.body, response.status)
@@ -279,7 +344,7 @@ module OneAndOne
279
344
 
280
345
 
281
346
  def modify_hardware(server_id: @id, fixed_instance_id: nil, vcore: nil,
282
- cores_per_processor: nil, ram: nil)
347
+ cores_per_processor: nil, ram: nil)
283
348
 
284
349
  # If user passed in server ID, reassign
285
350
  @id = server_id
@@ -303,9 +368,9 @@ module OneAndOne
303
368
 
304
369
  # Perform Request
305
370
  response = @connection.request(:method => :put,
306
- :path => path,
307
- :headers => $header,
308
- :body => string_body)
371
+ :path => path,
372
+ :headers => $header,
373
+ :body => string_body)
309
374
 
310
375
  # Check response status
311
376
  OneAndOne.check_response(response.body, response.status)
@@ -326,8 +391,8 @@ module OneAndOne
326
391
 
327
392
  # Perform request
328
393
  response = @connection.request(:method => :get,
329
- :path => path,
330
- :headers => $header)
394
+ :path => path,
395
+ :headers => $header)
331
396
 
332
397
  # Check response status
333
398
  OneAndOne.check_response(response.body, response.status)
@@ -356,9 +421,9 @@ module OneAndOne
356
421
 
357
422
  # Perform request
358
423
  response = @connection.request(:method => :post,
359
- :path => path,
360
- :headers => $header,
361
- :body => string_body)
424
+ :path => path,
425
+ :headers => $header,
426
+ :body => string_body)
362
427
 
363
428
  # Check response status
364
429
  OneAndOne.check_response(response.body, response.status)
@@ -379,8 +444,8 @@ module OneAndOne
379
444
 
380
445
  # Perform request
381
446
  response = @connection.request(:method => :get,
382
- :path => path,
383
- :headers => $header)
447
+ :path => path,
448
+ :headers => $header)
384
449
 
385
450
  # Check response status
386
451
  OneAndOne.check_response(response.body, response.status)
@@ -412,9 +477,9 @@ module OneAndOne
412
477
 
413
478
  # Perform Request
414
479
  response = @connection.request(:method => :put,
415
- :path => path,
416
- :headers => $header,
417
- :body => string_body)
480
+ :path => path,
481
+ :headers => $header,
482
+ :body => string_body)
418
483
 
419
484
  # Check response status
420
485
  OneAndOne.check_response(response.body, response.status)
@@ -435,8 +500,8 @@ module OneAndOne
435
500
 
436
501
  # Perform request
437
502
  response = @connection.request(:method => :delete,
438
- :path => path,
439
- :headers => $header)
503
+ :path => path,
504
+ :headers => $header)
440
505
 
441
506
  # Check response status
442
507
  OneAndOne.check_response(response.body, response.status)
@@ -457,8 +522,8 @@ module OneAndOne
457
522
 
458
523
  # Perform request
459
524
  response = @connection.request(:method => :get,
460
- :path => path,
461
- :headers => $header)
525
+ :path => path,
526
+ :headers => $header)
462
527
 
463
528
  # Check response status
464
529
  OneAndOne.check_response(response.body, response.status)
@@ -470,7 +535,7 @@ module OneAndOne
470
535
 
471
536
 
472
537
  def install_image(server_id: @id, image_id: nil, password: nil,
473
- firewall_id: nil)
538
+ firewall_id: nil)
474
539
 
475
540
  # If user passed in server ID, reassign
476
541
  @id = server_id
@@ -495,9 +560,9 @@ module OneAndOne
495
560
 
496
561
  # Perform Request
497
562
  response = @connection.request(:method => :put,
498
- :path => path,
499
- :headers => $header,
500
- :body => string_body)
563
+ :path => path,
564
+ :headers => $header,
565
+ :body => string_body)
501
566
 
502
567
  # Check response status
503
568
  OneAndOne.check_response(response.body, response.status)
@@ -518,8 +583,8 @@ module OneAndOne
518
583
 
519
584
  # Perform request
520
585
  response = @connection.request(:method => :get,
521
- :path => path,
522
- :headers => $header)
586
+ :path => path,
587
+ :headers => $header)
523
588
 
524
589
  # Check response status
525
590
  OneAndOne.check_response(response.body, response.status)
@@ -551,9 +616,9 @@ module OneAndOne
551
616
 
552
617
  # Perform Request
553
618
  response = @connection.request(:method => :post,
554
- :path => path,
555
- :headers => $header,
556
- :body => string_body)
619
+ :path => path,
620
+ :headers => $header,
621
+ :body => string_body)
557
622
 
558
623
  # Check response status
559
624
  OneAndOne.check_response(response.body, response.status)
@@ -574,8 +639,8 @@ module OneAndOne
574
639
 
575
640
  # Perform request
576
641
  response = @connection.request(:method => :get,
577
- :path => path,
578
- :headers => $header)
642
+ :path => path,
643
+ :headers => $header)
579
644
 
580
645
  # Check response status
581
646
  OneAndOne.check_response(response.body, response.status)
@@ -606,9 +671,9 @@ module OneAndOne
606
671
 
607
672
  # Perform request
608
673
  response = @connection.request(:method => :delete,
609
- :path => path,
610
- :headers => $header,
611
- :body => string_body)
674
+ :path => path,
675
+ :headers => $header,
676
+ :body => string_body)
612
677
 
613
678
  # Check response status
614
679
  OneAndOne.check_response(response.body, response.status)
@@ -640,9 +705,9 @@ module OneAndOne
640
705
 
641
706
  # Perform request
642
707
  response = @connection.request(:method => :put,
643
- :path => path,
644
- :headers => $header,
645
- :body => string_body)
708
+ :path => path,
709
+ :headers => $header,
710
+ :body => string_body)
646
711
 
647
712
  # Check response status
648
713
  OneAndOne.check_response(response.body, response.status)
@@ -663,8 +728,8 @@ module OneAndOne
663
728
 
664
729
  # Perform request
665
730
  response = @connection.request(:method => :get,
666
- :path => path,
667
- :headers => $header)
731
+ :path => path,
732
+ :headers => $header)
668
733
 
669
734
  # Check response status
670
735
  OneAndOne.check_response(response.body, response.status)
@@ -685,8 +750,8 @@ module OneAndOne
685
750
 
686
751
  # Perform request
687
752
  response = @connection.request(:method => :delete,
688
- :path => path,
689
- :headers => $header)
753
+ :path => path,
754
+ :headers => $header)
690
755
 
691
756
  # Check response status
692
757
  OneAndOne.check_response(response.body, response.status)
@@ -707,8 +772,8 @@ module OneAndOne
707
772
 
708
773
  # Perform request
709
774
  response = @connection.request(:method => :get,
710
- :path => path,
711
- :headers => $header)
775
+ :path => path,
776
+ :headers => $header)
712
777
 
713
778
  # Check response status
714
779
  OneAndOne.check_response(response.body, response.status)
@@ -740,9 +805,9 @@ module OneAndOne
740
805
 
741
806
  # Perform request
742
807
  response = @connection.request(:method => :post,
743
- :path => path,
744
- :headers => $header,
745
- :body => string_body)
808
+ :path => path,
809
+ :headers => $header,
810
+ :body => string_body)
746
811
 
747
812
  # Check response status
748
813
  OneAndOne.check_response(response.body, response.status)
@@ -763,8 +828,8 @@ module OneAndOne
763
828
 
764
829
  # Perform request
765
830
  response = @connection.request(:method => :delete,
766
- :path => path,
767
- :headers => $header)
831
+ :path => path,
832
+ :headers => $header)
768
833
 
769
834
  # Check response status
770
835
  OneAndOne.check_response(response.body, response.status)
@@ -785,8 +850,8 @@ module OneAndOne
785
850
 
786
851
  # Perform request
787
852
  response = @connection.request(:method => :get,
788
- :path => path,
789
- :headers => $header)
853
+ :path => path,
854
+ :headers => $header)
790
855
 
791
856
  # Check response status
792
857
  OneAndOne.check_response(response.body, response.status)
@@ -797,7 +862,7 @@ module OneAndOne
797
862
  end
798
863
 
799
864
 
800
- def change_status(server_id: @id, action: nil, method: nil)
865
+ def change_status(server_id: @id, action: nil, method: nil, recovery_mode: nil, recovery_image_id: nil)
801
866
 
802
867
  # If user passed in server ID, reassign
803
868
  @id = server_id
@@ -808,6 +873,9 @@ module OneAndOne
808
873
  'method' => method
809
874
  }
810
875
 
876
+ status_specs['recovery_mode'] = recovery_mode unless recovery_mode.nil?
877
+ status_specs['recovery_image_id'] = recovery_image_id unless recovery_image_id.nil?
878
+
811
879
  # Clean out null keys in PUT body
812
880
  body = OneAndOne.clean_hash(status_specs)
813
881
 
@@ -819,9 +887,9 @@ module OneAndOne
819
887
 
820
888
  # Perform request
821
889
  response = @connection.request(:method => :put,
822
- :path => path,
823
- :headers => $header,
824
- :body => string_body)
890
+ :path => path,
891
+ :headers => $header,
892
+ :body => string_body)
825
893
 
826
894
  # Check response status
827
895
  OneAndOne.check_response(response.body, response.status)
@@ -842,8 +910,8 @@ module OneAndOne
842
910
 
843
911
  # Perform request
844
912
  response = @connection.request(:method => :get,
845
- :path => path,
846
- :headers => $header)
913
+ :path => path,
914
+ :headers => $header)
847
915
 
848
916
  # Check response status
849
917
  OneAndOne.check_response(response.body, response.status)
@@ -875,9 +943,9 @@ module OneAndOne
875
943
 
876
944
  # Perform request
877
945
  response = @connection.request(:method => :put,
878
- :path => path,
879
- :headers => $header,
880
- :body => string_body)
946
+ :path => path,
947
+ :headers => $header,
948
+ :body => string_body)
881
949
 
882
950
  # Check response status
883
951
  OneAndOne.check_response(response.body, response.status)
@@ -898,8 +966,8 @@ module OneAndOne
898
966
 
899
967
  # Perform request
900
968
  response = @connection.request(:method => :delete,
901
- :path => path,
902
- :headers => $header)
969
+ :path => path,
970
+ :headers => $header)
903
971
 
904
972
  # Check response status
905
973
  OneAndOne.check_response(response.body, response.status)
@@ -920,8 +988,8 @@ module OneAndOne
920
988
 
921
989
  # Perform request
922
990
  response = @connection.request(:method => :get,
923
- :path => path,
924
- :headers => $header)
991
+ :path => path,
992
+ :headers => $header)
925
993
 
926
994
  # Check response status
927
995
  OneAndOne.check_response(response.body, response.status)
@@ -942,8 +1010,8 @@ module OneAndOne
942
1010
 
943
1011
  # Perform request
944
1012
  response = @connection.request(:method => :get,
945
- :path => path,
946
- :headers => $header)
1013
+ :path => path,
1014
+ :headers => $header)
947
1015
 
948
1016
  # Check response status
949
1017
  OneAndOne.check_response(response.body, response.status)
@@ -964,8 +1032,8 @@ module OneAndOne
964
1032
 
965
1033
  # Perform request
966
1034
  response = @connection.request(:method => :delete,
967
- :path => path,
968
- :headers => $header)
1035
+ :path => path,
1036
+ :headers => $header)
969
1037
 
970
1038
  # Check response status
971
1039
  OneAndOne.check_response(response.body, response.status)
@@ -997,9 +1065,9 @@ module OneAndOne
997
1065
 
998
1066
  # Perform request
999
1067
  response = @connection.request(:method => :post,
1000
- :path => path,
1001
- :headers => $header,
1002
- :body => string_body)
1068
+ :path => path,
1069
+ :headers => $header,
1070
+ :body => string_body)
1003
1071
 
1004
1072
  # Check response status
1005
1073
  OneAndOne.check_response(response.body, response.status)
@@ -1020,8 +1088,8 @@ module OneAndOne
1020
1088
 
1021
1089
  # Perform request
1022
1090
  response = @connection.request(:method => :post,
1023
- :path => path,
1024
- :headers => $header)
1091
+ :path => path,
1092
+ :headers => $header)
1025
1093
 
1026
1094
  # Check response status
1027
1095
  OneAndOne.check_response(response.body, response.status)
@@ -1042,8 +1110,8 @@ module OneAndOne
1042
1110
 
1043
1111
  # Perform request
1044
1112
  response = @connection.request(:method => :get,
1045
- :path => path,
1046
- :headers => $header)
1113
+ :path => path,
1114
+ :headers => $header)
1047
1115
 
1048
1116
  # Check response status
1049
1117
  OneAndOne.check_response(response.body, response.status)
@@ -1064,8 +1132,8 @@ module OneAndOne
1064
1132
 
1065
1133
  # Perform request
1066
1134
  response = @connection.request(:method => :put,
1067
- :path => path,
1068
- :headers => $header)
1135
+ :path => path,
1136
+ :headers => $header)
1069
1137
 
1070
1138
  # Check response status
1071
1139
  OneAndOne.check_response(response.body, response.status)
@@ -1086,8 +1154,8 @@ module OneAndOne
1086
1154
 
1087
1155
  # Perform request
1088
1156
  response = @connection.request(:method => :delete,
1089
- :path => path,
1090
- :headers => $header)
1157
+ :path => path,
1158
+ :headers => $header)
1091
1159
 
1092
1160
  # Check response status
1093
1161
  OneAndOne.check_response(response.body, response.status)
@@ -1120,9 +1188,9 @@ module OneAndOne
1120
1188
 
1121
1189
  # Perform request
1122
1190
  response = @connection.request(:method => :post,
1123
- :path => path,
1124
- :headers => $header,
1125
- :body => string_body)
1191
+ :path => path,
1192
+ :headers => $header,
1193
+ :body => string_body)
1126
1194
 
1127
1195
  # Check response status
1128
1196
  OneAndOne.check_response(response.body, response.status)