Class: OneAndOne::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/1and1/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test: false) ⇒ Server

Returns a new instance of Server.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/1and1/server.rb', line 13

def initialize(test: false)
  @id = nil
  @first_ip = nil
  @first_password = nil
  @specs = nil

  # Check if hitting mock api or live api
  if test
    @connection = Excon.new($base_url, :mock => true)
  else
    @connection = Excon.new($base_url)
  end

end

Instance Attribute Details

#first_ipObject

Returns the value of attribute first_ip.



8
9
10
# File 'lib/1and1/server.rb', line 8

def first_ip
  @first_ip
end

#first_passwordObject

Returns the value of attribute first_password.



9
10
11
# File 'lib/1and1/server.rb', line 9

def first_password
  @first_password
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/1and1/server.rb', line 7

def id
  @id
end

#specsObject

Returns the value of attribute specs.



10
11
12
# File 'lib/1and1/server.rb', line 10

def specs
  @specs
end

Instance Method Details

#add_firewall(server_id: @id, ip_id: nil, firewall_id: nil) ⇒ Object



622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
# File 'lib/1and1/server.rb', line 622

def add_firewall(server_id: @id, ip_id: nil, firewall_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  firewall_specs = {
    'id' => firewall_id
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(firewall_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/firewall_policy")

  # Perform request
  response = @connection.request(:method => :put,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#add_hdds(server_id: @id, hdds: nil) ⇒ Object



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
# File 'lib/1and1/server.rb', line 341

def add_hdds(server_id: @id, hdds: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build POST body
  new_hdds = {
    'hdds' => hdds
  }

  # Stringify the POST body
  string_body = new_hdds.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds")

  # Perform request
  response = @connection.request(:method => :post,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#add_ip(server_id: @id, ip_type: nil) ⇒ Object



533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/1and1/server.rb', line 533

def add_ip(server_id: @id, ip_type: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  ip_specs = {
    'type' => ip_type
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(ip_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/ips")

  # Perform Request
  response = @connection.request(:method => :post,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#add_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil) ⇒ Object



722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
# File 'lib/1and1/server.rb', line 722

def add_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  load_balancer_specs = {
    'load_balancer_id' => load_balancer_id
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(load_balancer_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/load_balancers")

  # Perform request
  response = @connection.request(:method => :post,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#add_private_network(server_id: @id, private_network_id: nil) ⇒ Object



979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
# File 'lib/1and1/server.rb', line 979

def add_private_network(server_id: @id, private_network_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  private_network_specs = {
    'id' => private_network_id
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(private_network_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/private_networks")

  # Perform request
  response = @connection.request(:method => :post,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#change_status(server_id: @id, action: nil, method: nil) ⇒ Object



800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
# File 'lib/1and1/server.rb', line 800

def change_status(server_id: @id, action: nil, method: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  status_specs = {
    'action' => action,
    'method' => method
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(status_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/status/action")

  # Perform request
  response = @connection.request(:method => :put,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#check_state(response) ⇒ Object



1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
# File 'lib/1and1/server.rb', line 1144

def check_state(response)

  # Parse out server state and percent from response
  state = response['status']['state']
  percent = response['status']['percent']

  # This is the ideal server state we are looking for
  ($good_states.include? state) && (percent == nil)

end

#clone(server_id: @id, name: nil, datacenter_id: nil) ⇒ Object



1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
# File 'lib/1and1/server.rb', line 1101

def clone(server_id: @id, name: nil, datacenter_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  clone_specs = {
    'name' => name,
    'datacenter_id' => datacenter_id
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(clone_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/clone")

  # Perform request
  response = @connection.request(:method => :post,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#create(name: nil, description: nil, rsa_key: nil, fixed_instance_id: nil, vcore: nil, cores_per_processor: nil, ram: nil, appliance_id: nil, datacenter_id: nil, hdds: nil, password: nil, power_on: nil, firewall_id: nil, ip_id: nil, load_balancer_id: nil, monitoring_policy_id: nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/1and1/server.rb', line 61

def create(name: nil, description: nil, rsa_key: nil, fixed_instance_id: nil,
  vcore: nil, cores_per_processor: nil, ram: nil, appliance_id: nil,
  datacenter_id: nil, hdds: nil, password: nil, power_on: nil,
  firewall_id: nil, ip_id: nil, load_balancer_id: nil,
  monitoring_policy_id: nil)

  # Build hardware hash
  hardware_params = {
    'fixed_instance_size_id' => fixed_instance_id,
    'vcore' => vcore,
    'cores_per_processor' => cores_per_processor,
    'ram' => ram,
    'hdds' => hdds
  }

  # Clean out null keys in hardware hash
  hardware = OneAndOne.clean_hash(hardware_params)

  # Build POST body
  new_server = {
    'name' => name,
    'description' => description,
    'hardware' => hardware,
    'appliance_id' => appliance_id,
    'datacenter_id' => datacenter_id,
    'rsa_key' => rsa_key,
    'password' => password,
    'power_on' => power_on,
    'firewall_policy_id' => firewall_id,
    'ip_id' => ip_id,
    'load_balancer_id' => load_balancer_id,
    'monitoring_policy_id' => monitoring_policy_id
  }

  # Clean out null keys in POST body
  body = OneAndOne.clean_hash(new_server)

  # Stringify the POST body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url('/servers')

  # Perform request
  response = @connection.request(:method => :post,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  json = JSON.parse(response.body)

  # Save new server ID to Server instance
  @specs = json
  @id = json['id']
  @first_password = json['first_password']

  # If all good, return JSON
  json

end

#create_snapshot(server_id: @id) ⇒ Object



1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
# File 'lib/1and1/server.rb', line 1013

def create_snapshot(server_id: @id)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/snapshots")

  # Perform request
  response = @connection.request(:method => :post,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#delete(server_id: @id, keep_ips: nil) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/1and1/server.rb', line 228

def delete(server_id: @id, keep_ips: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build hash for query parameters
  keyword_args = {
    'keep_ips' => keep_ips
  }

  # Clean out null query parameters
  params = OneAndOne.clean_hash(keyword_args)

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}")

  # Perform request
  response = @connection.request(:method => :delete,
    :path => path,
    :headers => $header,
    :query => params)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#delete_hdd(server_id: @id, hdd_id: nil) ⇒ Object



428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/1and1/server.rb', line 428

def delete_hdd(server_id: @id, hdd_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds/#{hdd_id}")

  # Perform request
  response = @connection.request(:method => :delete,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#delete_snapshot(server_id: @id, snapshot_id: nil) ⇒ Object



1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
# File 'lib/1and1/server.rb', line 1079

def delete_snapshot(server_id: @id, snapshot_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/snapshots/#{snapshot_id}")

  # Perform request
  response = @connection.request(:method => :delete,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#dvd(server_id: @id) ⇒ Object



835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
# File 'lib/1and1/server.rb', line 835

def dvd(server_id: @id)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/dvd")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#eject_dvd(server_id: @id) ⇒ Object



891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
# File 'lib/1and1/server.rb', line 891

def eject_dvd(server_id: @id)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/dvd")

  # Perform request
  response = @connection.request(:method => :delete,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#firewall(server_id: @id, ip_id: nil) ⇒ Object



656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'lib/1and1/server.rb', line 656

def firewall(server_id: @id, ip_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/firewall_policy")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#get(server_id: @id) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/1and1/server.rb', line 165

def get(server_id: @id)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  json = JSON.parse(response.body)

  # Reload specs attribute
  @specs = json

  # If all good, return JSON
  json

end

#get_fixed(fixed_instance_id: nil) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/1and1/server.rb', line 146

def get_fixed(fixed_instance_id: nil)

  # Build URL
  path = OneAndOne.build_url("/servers/fixed_instance_sizes/#{fixed_instance_id}")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#get_hdd(server_id: @id, hdd_id: nil) ⇒ Object



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/1and1/server.rb', line 372

def get_hdd(server_id: @id, hdd_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds/#{hdd_id}")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#hardware(server_id: @id) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/1and1/server.rb', line 259

def hardware(server_id: @id)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/hardware")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#hdds(server_id: @id) ⇒ Object



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/1and1/server.rb', line 319

def hdds(server_id: @id)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#image(server_id: @id) ⇒ Object



450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/1and1/server.rb', line 450

def image(server_id: @id)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/image")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#install_image(server_id: @id, image_id: nil, password: nil, firewall_id: nil) ⇒ Object



472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'lib/1and1/server.rb', line 472

def install_image(server_id: @id, image_id: nil, password: nil,
  firewall_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  image_specs = {
    'id' => image_id,
    'password' => password,
    'firewall_policy' => {
      'id' => firewall_id
    }
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(image_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/image")

  # Perform Request
  response = @connection.request(:method => :put,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#ip(server_id: @id, ip_id: nil) ⇒ Object



567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'lib/1and1/server.rb', line 567

def ip(server_id: @id, ip_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#ips(server_id: @id) ⇒ Object



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'lib/1and1/server.rb', line 511

def ips(server_id: @id)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/ips")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/1and1/server.rb', line 29

def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)

  # Build hash for query parameters
  keyword_args = {
    :page => page,
    :per_page => per_page,
    :sort => sort,
    :q => q,
    :fields => fields
  }

  # Clean out null query parameters
  params = OneAndOne.clean_hash(keyword_args)

  # Build URL
  path = OneAndOne.build_url('/servers')

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header,
    :query => params)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#list_fixedObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/1and1/server.rb', line 127

def list_fixed

  # Build URL
  path = OneAndOne.build_url('/servers/fixed_instance_sizes')

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#load_balancers(server_id: @id, ip_id: nil) ⇒ Object



700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
# File 'lib/1and1/server.rb', line 700

def load_balancers(server_id: @id, ip_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/load_balancers")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#load_dvd(server_id: @id, dvd_id: nil) ⇒ Object



857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
# File 'lib/1and1/server.rb', line 857

def load_dvd(server_id: @id, dvd_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  dvd_specs = {
    'id' => dvd_id
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(dvd_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/dvd")

  # Perform request
  response = @connection.request(:method => :put,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#modify(server_id: @id, name: nil, description: nil) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/1and1/server.rb', line 193

def modify(server_id: @id, name: nil, description: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  server_specs = {
    'name' => name,
    'description' => description
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(server_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}")

  # Perform Request
  response = @connection.request(:method => :put,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#modify_hardware(server_id: @id, fixed_instance_id: nil, vcore: nil, cores_per_processor: nil, ram: nil) ⇒ Object



281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/1and1/server.rb', line 281

def modify_hardware(server_id: @id, fixed_instance_id: nil, vcore: nil,
  cores_per_processor: nil, ram: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  hardware_specs = {
    'fixed_instance_size_id' => fixed_instance_id,
    'vcore' => vcore,
    'cores_per_processor' => cores_per_processor,
    'ram' => ram
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(hardware_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/hardware")

  # Perform Request
  response = @connection.request(:method => :put,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#modify_hdd(server_id: @id, hdd_id: nil, size: nil) ⇒ Object



394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/1and1/server.rb', line 394

def modify_hdd(server_id: @id, hdd_id: nil, size: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  hdd_specs = {
    'size' => size
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(hdd_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds/#{hdd_id}")

  # Perform Request
  response = @connection.request(:method => :put,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#parser(response) ⇒ Object



1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
# File 'lib/1and1/server.rb', line 1156

def parser(response)

  # Check for first IP
  ips = response['ips']

  if ips.length == 1
    @first_ip = ips[0]
  end

end

#private_network(server_id: @id, private_network_id: nil) ⇒ Object



935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
# File 'lib/1and1/server.rb', line 935

def private_network(server_id: @id, private_network_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/private_networks/#{private_network_id}")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#private_networks(server_id: @id) ⇒ Object



913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
# File 'lib/1and1/server.rb', line 913

def private_networks(server_id: @id)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/private_networks")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#release_ip(server_id: @id, ip_id: nil, keep_ip: nil) ⇒ Object



588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/1and1/server.rb', line 588

def release_ip(server_id: @id, ip_id: nil, keep_ip: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build PUT body
  ip_specs = {
    'keep_ip' => keep_ip
  }

  # Clean out null keys in PUT body
  body = OneAndOne.clean_hash(ip_specs)

  # Stringify the PUT body
  string_body = body.to_json

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}")

  # Perform request
  response = @connection.request(:method => :delete,
    :path => path,
    :headers => $header,
    :body => string_body)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#reloadObject



1136
1137
1138
1139
1140
1141
# File 'lib/1and1/server.rb', line 1136

def reload

  # This reload fx is just a wrapper for the get fx
  get

end

#remove_firewall(server_id: @id, ip_id: nil) ⇒ Object



678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
# File 'lib/1and1/server.rb', line 678

def remove_firewall(server_id: @id, ip_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/firewall_policy")

  # Perform request
  response = @connection.request(:method => :delete,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#remove_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil) ⇒ Object



756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
# File 'lib/1and1/server.rb', line 756

def remove_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/load_balancers/#{load_balancer_id}")

  # Perform request
  response = @connection.request(:method => :delete,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#remove_private_network(server_id: @id, private_network_id: nil) ⇒ Object



957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
# File 'lib/1and1/server.rb', line 957

def remove_private_network(server_id: @id, private_network_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/private_networks/#{private_network_id}")

  # Perform request
  response = @connection.request(:method => :delete,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#restore_snapshot(server_id: @id, snapshot_id: nil) ⇒ Object



1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
# File 'lib/1and1/server.rb', line 1057

def restore_snapshot(server_id: @id, snapshot_id: nil)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/snapshots/#{snapshot_id}")

  # Perform request
  response = @connection.request(:method => :put,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#snapshot(server_id: @id) ⇒ Object



1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
# File 'lib/1and1/server.rb', line 1035

def snapshot(server_id: @id)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/snapshots")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#status(server_id: @id) ⇒ Object



778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
# File 'lib/1and1/server.rb', line 778

def status(server_id: @id)

  # If user passed in server ID, reassign
  @id = server_id

  # Build URL
  path = OneAndOne.build_url("/servers/#{@id}/status")

  # Perform request
  response = @connection.request(:method => :get,
    :path => path,
    :headers => $header)

  # Check response status
  OneAndOne.check_response(response.body, response.status)

  #JSON-ify the response string
  JSON.parse(response.body)

end

#wait_for(timeout: 25, interval: 15) ⇒ Object



1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
# File 'lib/1and1/server.rb', line 1168

def wait_for(timeout: 25, interval: 15)

  # Capture start time
  start = Time.now

  # Poll server and check initial state
  initial_response = get
  server_state = check_state(initial_response)

  # Keep polling the server's state until good
  until server_state

    # Wait 15 seconds before polling again
    sleep interval

    # Check server state and percent again
    current_response = get
    server_state = check_state(current_response)

    # Calculate current duration and check for timeout
    duration = (Time.now - start) / 60
    if duration > timeout
      puts "The operation timed out after #{timeout} minutes.\n"
      return
    end

    # Parse for first IP
    parser(current_response)

  end

  # Return Duration
  {:duration => duration}

end