cft_smartcloud 0.1.9 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/CHANGELOG +6 -0
  2. data/VERSION +1 -1
  3. data/cft_smartcloud.gemspec +2 -91
  4. data/lib/mock_smartcloud.rb +4 -2
  5. data/lib/smartcloud.rb +73 -75
  6. metadata +4 -93
  7. data/lib/cli_tools/README.txt +0 -50
  8. data/lib/cli_tools/ic-add-keypair.cmd +0 -29
  9. data/lib/cli_tools/ic-add-keypair.sh +0 -15
  10. data/lib/cli_tools/ic-allocate-address.cmd +0 -29
  11. data/lib/cli_tools/ic-allocate-address.sh +0 -14
  12. data/lib/cli_tools/ic-attach-volume.cmd +0 -27
  13. data/lib/cli_tools/ic-attach-volume.sh +0 -27
  14. data/lib/cli_tools/ic-clone-image.cmd +0 -27
  15. data/lib/cli_tools/ic-clone-image.sh +0 -14
  16. data/lib/cli_tools/ic-clone-volume.cmd +0 -27
  17. data/lib/cli_tools/ic-clone-volume.sh +0 -60
  18. data/lib/cli_tools/ic-cmd.cmd +0 -41
  19. data/lib/cli_tools/ic-cmd.sh +0 -38
  20. data/lib/cli_tools/ic-create-instance.cmd +0 -27
  21. data/lib/cli_tools/ic-create-instance.sh +0 -14
  22. data/lib/cli_tools/ic-create-password.cmd +0 -27
  23. data/lib/cli_tools/ic-create-password.sh +0 -14
  24. data/lib/cli_tools/ic-create-volume.cmd +0 -27
  25. data/lib/cli_tools/ic-create-volume.sh +0 -14
  26. data/lib/cli_tools/ic-delete-image.cmd +0 -27
  27. data/lib/cli_tools/ic-delete-image.sh +0 -14
  28. data/lib/cli_tools/ic-delete-instance.cmd +0 -27
  29. data/lib/cli_tools/ic-delete-instance.sh +0 -14
  30. data/lib/cli_tools/ic-delete-volume.cmd +0 -27
  31. data/lib/cli_tools/ic-delete-volume.sh +0 -14
  32. data/lib/cli_tools/ic-describe-address-offerings.cmd +0 -27
  33. data/lib/cli_tools/ic-describe-address-offerings.sh +0 -14
  34. data/lib/cli_tools/ic-describe-addresses.cmd +0 -27
  35. data/lib/cli_tools/ic-describe-addresses.sh +0 -14
  36. data/lib/cli_tools/ic-describe-image-agreement.cmd +0 -27
  37. data/lib/cli_tools/ic-describe-image-agreement.sh +0 -14
  38. data/lib/cli_tools/ic-describe-image.cmd +0 -27
  39. data/lib/cli_tools/ic-describe-image.sh +0 -14
  40. data/lib/cli_tools/ic-describe-images.cmd +0 -27
  41. data/lib/cli_tools/ic-describe-images.sh +0 -14
  42. data/lib/cli_tools/ic-describe-instance.cmd +0 -27
  43. data/lib/cli_tools/ic-describe-instance.sh +0 -14
  44. data/lib/cli_tools/ic-describe-instances.cmd +0 -27
  45. data/lib/cli_tools/ic-describe-instances.sh +0 -14
  46. data/lib/cli_tools/ic-describe-keypair.cmd +0 -27
  47. data/lib/cli_tools/ic-describe-keypair.sh +0 -14
  48. data/lib/cli_tools/ic-describe-keypairs.cmd +0 -27
  49. data/lib/cli_tools/ic-describe-keypairs.sh +0 -14
  50. data/lib/cli_tools/ic-describe-location.cmd +0 -14
  51. data/lib/cli_tools/ic-describe-location.sh +0 -14
  52. data/lib/cli_tools/ic-describe-locations.cmd +0 -14
  53. data/lib/cli_tools/ic-describe-locations.sh +0 -14
  54. data/lib/cli_tools/ic-describe-request.cmd +0 -27
  55. data/lib/cli_tools/ic-describe-request.sh +0 -14
  56. data/lib/cli_tools/ic-describe-vlans.cmd +0 -27
  57. data/lib/cli_tools/ic-describe-vlans.sh +0 -14
  58. data/lib/cli_tools/ic-describe-volume-offerings.cmd +0 -27
  59. data/lib/cli_tools/ic-describe-volume-offerings.sh +0 -14
  60. data/lib/cli_tools/ic-describe-volume.cmd +0 -27
  61. data/lib/cli_tools/ic-describe-volume.sh +0 -14
  62. data/lib/cli_tools/ic-describe-volumes.cmd +0 -27
  63. data/lib/cli_tools/ic-describe-volumes.sh +0 -14
  64. data/lib/cli_tools/ic-detach-volume.cmd +0 -27
  65. data/lib/cli_tools/ic-detach-volume.sh +0 -27
  66. data/lib/cli_tools/ic-extend-reservation.cmd +0 -27
  67. data/lib/cli_tools/ic-extend-reservation.sh +0 -14
  68. data/lib/cli_tools/ic-generate-keypair.cmd +0 -27
  69. data/lib/cli_tools/ic-generate-keypair.sh +0 -14
  70. data/lib/cli_tools/ic-release-address.cmd +0 -27
  71. data/lib/cli_tools/ic-release-address.sh +0 -14
  72. data/lib/cli_tools/ic-remove-keypair.cmd +0 -27
  73. data/lib/cli_tools/ic-remove-keypair.sh +0 -14
  74. data/lib/cli_tools/ic-restart-instance.cmd +0 -27
  75. data/lib/cli_tools/ic-restart-instance.sh +0 -14
  76. data/lib/cli_tools/ic-save-instance.cmd +0 -27
  77. data/lib/cli_tools/ic-save-instance.sh +0 -14
  78. data/lib/cli_tools/ic-set-default-key.cmd +0 -27
  79. data/lib/cli_tools/ic-set-default-key.sh +0 -14
  80. data/lib/cli_tools/ic-update-instance.cmd +0 -27
  81. data/lib/cli_tools/ic-update-instance.sh +0 -14
  82. data/lib/cli_tools/ic-update-keypair.cmd +0 -27
  83. data/lib/cli_tools/ic-update-keypair.sh +0 -14
  84. data/lib/cli_tools/lib/DeveloperCloud_API_Client_JAR.jar +0 -0
  85. data/lib/cli_tools/lib/DeveloperCloud_CMD_Tool.jar +0 -0
  86. data/lib/cli_tools/lib/commons-beanutils-1.6.1.jar +0 -0
  87. data/lib/cli_tools/lib/commons-cli-1.2.jar +0 -0
  88. data/lib/cli_tools/lib/commons-codec-1.3.jar +0 -0
  89. data/lib/cli_tools/lib/commons-collections-3.2.1.jar +0 -0
  90. data/lib/cli_tools/lib/commons-digester-1.8.jar +0 -0
  91. data/lib/cli_tools/lib/commons-httpclient-3.1.jar +0 -0
  92. data/lib/cli_tools/lib/commons-lang-2.3.jar +0 -0
  93. data/lib/cli_tools/lib/commons-logging-1.1.1.jar +0 -0
  94. data/lib/cli_tools/logging.properties +0 -7
  95. data/lib/cli_tools/manifest.rmd +0 -26
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 2011-09-21 0.2.1:
2
+ * Added sleep/retry logic for intermittent 500 errors returned by cloud
3
+
4
+ 2011-09-13 0.2.0:
5
+ * Clone operation now done using API instead of CLI
6
+
1
7
  2011-08-09 0.1.8:
2
8
  * Updated create_instance to return the Instance object rather
3
9
  than the xml request, for consistency with describe_instance
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.2.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cft_smartcloud}
8
- s.version = "0.1.9"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["yan", "cohesive"]
12
- s.date = %q{2011-08-15}
12
+ s.date = %q{2011-10-17}
13
13
  s.description = %q{CohesiveFT Ruby Interface for IBM SmartCloud and 'smartcloud' command line helper.}
14
14
  s.email = %q{yan.pritzker@cohesiveft.com}
15
15
  s.executables = ["cft_smartcloud", "smartcloud"]
@@ -27,95 +27,6 @@ Gem::Specification.new do |s|
27
27
  "bin/cft_smartcloud",
28
28
  "bin/smartcloud",
29
29
  "cft_smartcloud.gemspec",
30
- "lib/cli_tools/README.txt",
31
- "lib/cli_tools/ic-add-keypair.cmd",
32
- "lib/cli_tools/ic-add-keypair.sh",
33
- "lib/cli_tools/ic-allocate-address.cmd",
34
- "lib/cli_tools/ic-allocate-address.sh",
35
- "lib/cli_tools/ic-attach-volume.cmd",
36
- "lib/cli_tools/ic-attach-volume.sh",
37
- "lib/cli_tools/ic-clone-image.cmd",
38
- "lib/cli_tools/ic-clone-image.sh",
39
- "lib/cli_tools/ic-clone-volume.cmd",
40
- "lib/cli_tools/ic-clone-volume.sh",
41
- "lib/cli_tools/ic-cmd.cmd",
42
- "lib/cli_tools/ic-cmd.sh",
43
- "lib/cli_tools/ic-create-instance.cmd",
44
- "lib/cli_tools/ic-create-instance.sh",
45
- "lib/cli_tools/ic-create-password.cmd",
46
- "lib/cli_tools/ic-create-password.sh",
47
- "lib/cli_tools/ic-create-volume.cmd",
48
- "lib/cli_tools/ic-create-volume.sh",
49
- "lib/cli_tools/ic-delete-image.cmd",
50
- "lib/cli_tools/ic-delete-image.sh",
51
- "lib/cli_tools/ic-delete-instance.cmd",
52
- "lib/cli_tools/ic-delete-instance.sh",
53
- "lib/cli_tools/ic-delete-volume.cmd",
54
- "lib/cli_tools/ic-delete-volume.sh",
55
- "lib/cli_tools/ic-describe-address-offerings.cmd",
56
- "lib/cli_tools/ic-describe-address-offerings.sh",
57
- "lib/cli_tools/ic-describe-addresses.cmd",
58
- "lib/cli_tools/ic-describe-addresses.sh",
59
- "lib/cli_tools/ic-describe-image-agreement.cmd",
60
- "lib/cli_tools/ic-describe-image-agreement.sh",
61
- "lib/cli_tools/ic-describe-image.cmd",
62
- "lib/cli_tools/ic-describe-image.sh",
63
- "lib/cli_tools/ic-describe-images.cmd",
64
- "lib/cli_tools/ic-describe-images.sh",
65
- "lib/cli_tools/ic-describe-instance.cmd",
66
- "lib/cli_tools/ic-describe-instance.sh",
67
- "lib/cli_tools/ic-describe-instances.cmd",
68
- "lib/cli_tools/ic-describe-instances.sh",
69
- "lib/cli_tools/ic-describe-keypair.cmd",
70
- "lib/cli_tools/ic-describe-keypair.sh",
71
- "lib/cli_tools/ic-describe-keypairs.cmd",
72
- "lib/cli_tools/ic-describe-keypairs.sh",
73
- "lib/cli_tools/ic-describe-location.cmd",
74
- "lib/cli_tools/ic-describe-location.sh",
75
- "lib/cli_tools/ic-describe-locations.cmd",
76
- "lib/cli_tools/ic-describe-locations.sh",
77
- "lib/cli_tools/ic-describe-request.cmd",
78
- "lib/cli_tools/ic-describe-request.sh",
79
- "lib/cli_tools/ic-describe-vlans.cmd",
80
- "lib/cli_tools/ic-describe-vlans.sh",
81
- "lib/cli_tools/ic-describe-volume-offerings.cmd",
82
- "lib/cli_tools/ic-describe-volume-offerings.sh",
83
- "lib/cli_tools/ic-describe-volume.cmd",
84
- "lib/cli_tools/ic-describe-volume.sh",
85
- "lib/cli_tools/ic-describe-volumes.cmd",
86
- "lib/cli_tools/ic-describe-volumes.sh",
87
- "lib/cli_tools/ic-detach-volume.cmd",
88
- "lib/cli_tools/ic-detach-volume.sh",
89
- "lib/cli_tools/ic-extend-reservation.cmd",
90
- "lib/cli_tools/ic-extend-reservation.sh",
91
- "lib/cli_tools/ic-generate-keypair.cmd",
92
- "lib/cli_tools/ic-generate-keypair.sh",
93
- "lib/cli_tools/ic-release-address.cmd",
94
- "lib/cli_tools/ic-release-address.sh",
95
- "lib/cli_tools/ic-remove-keypair.cmd",
96
- "lib/cli_tools/ic-remove-keypair.sh",
97
- "lib/cli_tools/ic-restart-instance.cmd",
98
- "lib/cli_tools/ic-restart-instance.sh",
99
- "lib/cli_tools/ic-save-instance.cmd",
100
- "lib/cli_tools/ic-save-instance.sh",
101
- "lib/cli_tools/ic-set-default-key.cmd",
102
- "lib/cli_tools/ic-set-default-key.sh",
103
- "lib/cli_tools/ic-update-instance.cmd",
104
- "lib/cli_tools/ic-update-instance.sh",
105
- "lib/cli_tools/ic-update-keypair.cmd",
106
- "lib/cli_tools/ic-update-keypair.sh",
107
- "lib/cli_tools/lib/DeveloperCloud_API_Client_JAR.jar",
108
- "lib/cli_tools/lib/DeveloperCloud_CMD_Tool.jar",
109
- "lib/cli_tools/lib/commons-beanutils-1.6.1.jar",
110
- "lib/cli_tools/lib/commons-cli-1.2.jar",
111
- "lib/cli_tools/lib/commons-codec-1.3.jar",
112
- "lib/cli_tools/lib/commons-collections-3.2.1.jar",
113
- "lib/cli_tools/lib/commons-digester-1.8.jar",
114
- "lib/cli_tools/lib/commons-httpclient-3.1.jar",
115
- "lib/cli_tools/lib/commons-lang-2.3.jar",
116
- "lib/cli_tools/lib/commons-logging-1.1.1.jar",
117
- "lib/cli_tools/logging.properties",
118
- "lib/cli_tools/manifest.rmd",
119
30
  "lib/config/config.yml",
120
31
  "lib/hash_fix.rb",
121
32
  "lib/mime-types-1.16/History.txt",
@@ -22,6 +22,8 @@ class MockSmartCloud
22
22
  "Price"=>{"Rate"=>"0.21", "PricePerQuantity"=>"1", "UnitOfMeasure"=>"UHR ", "CountryCode"=>"897", "CurrencyCode"=>"USD"}},
23
23
  {"Label"=>"Copper 32 bit", "ID"=>"COP32.1/2048/60",
24
24
  "Price"=>{"Rate"=>"0.21", "PricePerQuantity"=>"1", "UnitOfMeasure"=>"UHR ", "CountryCode"=>"897", "CurrencyCode"=>"USD"}},
25
+ {"Label"=>"Silver 32 bit", "ID"=>"SLV32.2/4096/60*350",
26
+ "Price"=>{"Rate"=>"0.21", "PricePerQuantity"=>"1", "UnitOfMeasure"=>"UHR ", "CountryCode"=>"897", "CurrencyCode"=>"USD"}},
25
27
  ]
26
28
  },
27
29
  "Name"=>"CohesiveFT VPN-Cubed Datacenter Connect V2.0.0 - BYOL (TOR)", "Location"=>"101", "ProductCodes"=>{"ProductCode"=>"caondc13bV97Kg5TLyGNodD9or7gA"}, "Documentation"=>"https://www-147.ibm.com/cloud/enterprise/ram.ws/RAMSecure/artifact/{974E595E-566E-87E3-A483-AC0FC468C4D9}/1.0/GettingStarted.html", "ID"=>"20016530", "Manifest"=>"https://www-147.ibm.com/cloud/enterprise/ram.ws/RAMSecure/artifact/{974E595E-566E-87E3-A483-AC0FC468C4D9}/1.0/parameters.xml", "Description"=>"CohesiveFT VPN-Cubed 2.0.0 UL - for TOR datacenter", "State"=>"AVAILABLE", "Visibility"=>"PUBLIC", "Platform"=>"Red Hat Enterprise Linux/5.4"}
@@ -32,7 +34,7 @@ class MockSmartCloud
32
34
  end
33
35
 
34
36
  def create_volume(*args)
35
- true
37
+ "12345"
36
38
  end
37
39
 
38
40
  def describe_volume(*args)
@@ -40,7 +42,7 @@ class MockSmartCloud
40
42
  end
41
43
 
42
44
  def clone_volume(*args)
43
- true
45
+ "555555"
44
46
  end
45
47
 
46
48
  def restart_instance(*args)
data/lib/smartcloud.rb CHANGED
@@ -31,6 +31,10 @@ class IBMSmartCloud
31
31
  attr_accessor :logger
32
32
 
33
33
  def initialize(username, password, logger=nil, debug=false)
34
+ # For handling errors
35
+ @retries = 120
36
+ @sleep_interval = 30
37
+
34
38
  @username = username
35
39
  @password = password
36
40
  @logger = logger || SmartcloudLogger.new(STDOUT)
@@ -139,9 +143,9 @@ class IBMSmartCloud
139
143
  instance_params.delete("description")
140
144
 
141
145
  # configuration data has to be changed from a string like
142
- # <configuration>{contextmanager:baml-c3-master.cohesiveft.com,clustername:BAML_poc_pk0515,role:[nfs-client-setup|newyork_master_refdata_member|install-luci|rhel-openlikewise-client-setup|join-domain],hostname:r550n107}</configuration>
146
+ # <configuration>{contextmanager:test-c3-master.cohesiveft.com,clustername:TEST_poc_pk0515,role:[nfs-client-setup|newyork_master_refdata_member|install-luci|rhel-openlikewise-client-setup|join-domain],hostname:r550n107}</configuration>
143
147
  # to a standard list of POST params like
144
- # contextmanager=baml-c3-mager&clustername=BAML...
148
+ # contextmanager=test-c3-mager&clustername=TEST...
145
149
  configuration_data = instance_params.delete("configuration") || instance_params.delete("ConfigurationData")
146
150
  if configuration_data
147
151
  if configuration_data =~ /\s+/
@@ -203,17 +207,8 @@ class IBMSmartCloud
203
207
  # TODO: the API call does not work, we have to use the cli for now
204
208
  args :clone_volume, [:name, :source_disk_id]
205
209
  def clone_volume(name, source_disk_id)
206
- # original_disk = describe_volume(source_disk_id)
207
- # logger.info "Looking up volume #{source_disk_id} to prepare for cloning..."
208
- # offering = describe_volume_offerings(original_disk.Location).detect {|offer| offer.ID == original_disk.OfferingID}
209
- # logger.info "Original volume size: #{offering.Name}"
210
- # result = post("/storage", :name => name, :SourceDiskID => source_disk_id, :format => original_disk.Format.upcase, :location => original_disk.Location, :size => offering.Name, :offeringID => original_disk.OfferingID )
211
- # result.Volume.ID
212
-
213
- create_password_file
214
- result = run_ibm_tool("ic-clone-volume.sh -n #{name} -S #{source_disk_id}")
215
- result =~ /ID : (.*)/
216
- return $1 # grab the id of the created volume
210
+ result = post("/storage", :name => name, :sourceDiskID => source_disk_id, :type => 'clone')
211
+ result.Volume.ID
217
212
  end
218
213
 
219
214
  args :attach_volume, [:instance_id, :volume_id]
@@ -244,10 +239,16 @@ class IBMSmartCloud
244
239
  end
245
240
 
246
241
  # generates a keypair and returns the private key
247
- args :generate_keypair, [:name]
248
- def generate_keypair(name)
249
- response = post("/keys", :name => name)
250
- response.PrivateKey.KeyMaterial
242
+ args :generate_keypair, [{:name=>:req}, {:publicKey=>:opt}], %{ If publicKey parameter is given, creates a key with that public key, and returns nothing. If public key is omitted, generates a new key and returns the pirvate key.}
243
+ def generate_keypair(name, publicKey=nil)
244
+ options = {:name => name}
245
+ options[:publicKey] = publicKey if publicKey
246
+ response = post("/keys", options)
247
+ if publicKey
248
+ true
249
+ else
250
+ response.PrivateKey.KeyMaterial
251
+ end
251
252
  end
252
253
 
253
254
  args :remove_keypair, [:name]
@@ -261,6 +262,11 @@ class IBMSmartCloud
261
262
  get("/keys/#{name}").PublicKey
262
263
  end
263
264
 
265
+ args :update_key, [:name, :publicKey]
266
+ def update_key(name, key)
267
+ put("/keys/#{name}", :publicKey => key)
268
+ end
269
+
264
270
  # If address_id is supplied, will return info on that address only
265
271
  args :describe_addresses, [{:address_id=>:opt}]
266
272
  def describe_addresses(address_id=nil)
@@ -518,7 +524,8 @@ class IBMSmartCloud
518
524
  # Also takes an :order param, examples:
519
525
  # display_instances(:order => "Name") or :order => "LaunchTime"
520
526
  #
521
- args :display_instances, [:filters => :opt]
527
+
528
+ args :display_instances, [:filters => :opt], %{example: smartcloud "display_instances(:name=>'matchMe')"}
522
529
  def display_instances(filters={})
523
530
  instances = describe_instances(filters)
524
531
 
@@ -563,41 +570,68 @@ class IBMSmartCloud
563
570
  end
564
571
 
565
572
  def delete(path)
566
- output = RestClient.delete File.join(@api_url, path), :accept => :response
567
- response = XmlSimple.xml_in(output, {'ForceArray' => nil})
568
- rescue => e
569
- raise_restclient_error(e)
573
+ rescue_and_retry_errors do
574
+ output = RestClient.delete File.join(@api_url, path), :accept => :response
575
+ response = XmlSimple.xml_in(output, {'ForceArray' => nil})
576
+ end
570
577
  end
571
578
 
572
579
  def put(path, params={}, param_remap={})
573
- param_string = make_param_string(params, param_remap)
574
- output = RestClient.put File.join(@api_url, path), param_string, :accept => :response
575
- response = XmlSimple.xml_in(output, {'ForceArray' => nil})
576
- rescue => e
577
- raise_restclient_error(e)
580
+ rescue_and_retry_errors do
581
+ param_string = make_param_string(params, param_remap)
582
+ output = RestClient.put File.join(@api_url, path), param_string, :accept => :response
583
+ response = XmlSimple.xml_in(output, {'ForceArray' => nil})
584
+ end
578
585
  end
579
586
 
580
587
  def get(path)
581
- output = RestClient.get File.join(@api_url, path), :accept => :response
582
- response = XmlSimple.xml_in(output, {'ForceArray' => nil})
583
- rescue => e
584
- raise_restclient_error(e)
588
+ rescue_and_retry_errors do
589
+ output = RestClient.get File.join(@api_url, path), :accept => :response
590
+ response = XmlSimple.xml_in(output, {'ForceArray' => nil})
591
+ end
585
592
  end
586
593
 
587
594
  def post(path, params={}, param_remap=nil)
588
- param_string = make_param_string(params, param_remap)
589
- output = RestClient.post File.join(@api_url, path), param_string, :accept => :response
590
- response = XmlSimple.xml_in(output, {'ForceArray' => nil})
591
- response
592
- rescue => e
593
- raise_restclient_error(e)
595
+ rescue_and_retry_errors do
596
+ param_string = make_param_string(params, param_remap)
597
+ output = RestClient.post File.join(@api_url, path), param_string, :accept => :response
598
+ response = XmlSimple.xml_in(output, {'ForceArray' => nil})
599
+ end
594
600
  end
595
601
 
596
602
  private
603
+
604
+ # Custom exception matcher
605
+ def timeouts_and_500s
606
+ m = Module.new
607
+ (class << m; self; end).instance_eval do
608
+ define_method(:===) do |e|
609
+ [RestClient::RequestTimeout, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ETIMEDOUT,
610
+ EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError].include?(e.class)|| e.message =~ /500/
611
+ end
612
+ end
613
+ m
614
+ end
615
+
597
616
  # rest client error details are in the response so we want to
598
617
  # display that as the error, otherwise we lose that info
599
- def raise_restclient_error(e)
600
- if e.respond_to?(:response) && !e.is_a?(RestClient::RequestTimeout)
618
+ def rescue_and_retry_errors(&block)
619
+ block.call
620
+ rescue timeouts_and_500s => e
621
+ is_500 = e.message =~ /500/
622
+
623
+ @retries -= 1
624
+ if @retries >= 0
625
+ logger.warn e.message
626
+ logger.warn "Caught #{is_500 ? "500" : "Timeout"} Error from cloud API server. Server is down or malfunctioning. Will sleep #{@sleep_interval}s and retry. Retries remaining: #{@retries}..."
627
+ sleep(@sleep_interval)
628
+ retry
629
+ else
630
+ logger.warn "Reached maximum retry limit for this error. Aborting."
631
+ raise e
632
+ end
633
+ rescue => e
634
+ if e.respond_to?(:response)
601
635
  raise "#{e.message} - #{e.response}"
602
636
  else
603
637
  raise e
@@ -653,42 +687,6 @@ class IBMSmartCloud
653
687
  array_or_object.is_a?(Array) ? array_or_object : [array_or_object]
654
688
  end
655
689
 
656
- # TODO: all methods below here can be nuked once CLI tools are removed
657
- def run_ibm_tool(command)
658
- FileUtils.mkdir_p(File.join(IBM_TOOLS_HOME, 'logs'))
659
- cmd = "cd #{IBM_TOOLS_HOME} && ./#{command} -u #{@username} -w #{passphrase} -g #{password_file}"
660
- logger.debug cmd
661
- output = if @debug
662
- IBMMockResponseGenerator.respond(command)
663
- else
664
- `#{cmd}`
665
- end
666
-
667
- logger.debug output
668
-
669
- if output =~ /ErrorMessage : (.*)/
670
- raise $1 # raise the error message matched above
671
- else
672
- return output
673
- end
674
- end
675
-
676
- def create_password_file
677
- # if no passphrase or password file is supplied, we'll generate it
678
- run_ibm_tool("ic-create-password.sh -u #{@username} -p #{@password}")
679
- end
680
-
681
- def password_file
682
- @password_file ||= "/tmp/smrtcloud-pwfile-#{Time.now.to_i.to_s}"
683
- end
684
-
685
- def passphrase
686
- @passphrase ||= Time.now.to_i.to_s
687
- end
688
- # End CLI tool helpers
689
-
690
-
691
-
692
690
  end
693
691
 
694
692
  # predefine an instance for convenience
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 9
9
- version: 0.1.9
7
+ - 2
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - yan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-15 00:00:00 -07:00
18
+ date: 2011-10-17 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -39,95 +39,6 @@ files:
39
39
  - bin/cft_smartcloud
40
40
  - bin/smartcloud
41
41
  - cft_smartcloud.gemspec
42
- - lib/cli_tools/README.txt
43
- - lib/cli_tools/ic-add-keypair.cmd
44
- - lib/cli_tools/ic-add-keypair.sh
45
- - lib/cli_tools/ic-allocate-address.cmd
46
- - lib/cli_tools/ic-allocate-address.sh
47
- - lib/cli_tools/ic-attach-volume.cmd
48
- - lib/cli_tools/ic-attach-volume.sh
49
- - lib/cli_tools/ic-clone-image.cmd
50
- - lib/cli_tools/ic-clone-image.sh
51
- - lib/cli_tools/ic-clone-volume.cmd
52
- - lib/cli_tools/ic-clone-volume.sh
53
- - lib/cli_tools/ic-cmd.cmd
54
- - lib/cli_tools/ic-cmd.sh
55
- - lib/cli_tools/ic-create-instance.cmd
56
- - lib/cli_tools/ic-create-instance.sh
57
- - lib/cli_tools/ic-create-password.cmd
58
- - lib/cli_tools/ic-create-password.sh
59
- - lib/cli_tools/ic-create-volume.cmd
60
- - lib/cli_tools/ic-create-volume.sh
61
- - lib/cli_tools/ic-delete-image.cmd
62
- - lib/cli_tools/ic-delete-image.sh
63
- - lib/cli_tools/ic-delete-instance.cmd
64
- - lib/cli_tools/ic-delete-instance.sh
65
- - lib/cli_tools/ic-delete-volume.cmd
66
- - lib/cli_tools/ic-delete-volume.sh
67
- - lib/cli_tools/ic-describe-address-offerings.cmd
68
- - lib/cli_tools/ic-describe-address-offerings.sh
69
- - lib/cli_tools/ic-describe-addresses.cmd
70
- - lib/cli_tools/ic-describe-addresses.sh
71
- - lib/cli_tools/ic-describe-image-agreement.cmd
72
- - lib/cli_tools/ic-describe-image-agreement.sh
73
- - lib/cli_tools/ic-describe-image.cmd
74
- - lib/cli_tools/ic-describe-image.sh
75
- - lib/cli_tools/ic-describe-images.cmd
76
- - lib/cli_tools/ic-describe-images.sh
77
- - lib/cli_tools/ic-describe-instance.cmd
78
- - lib/cli_tools/ic-describe-instance.sh
79
- - lib/cli_tools/ic-describe-instances.cmd
80
- - lib/cli_tools/ic-describe-instances.sh
81
- - lib/cli_tools/ic-describe-keypair.cmd
82
- - lib/cli_tools/ic-describe-keypair.sh
83
- - lib/cli_tools/ic-describe-keypairs.cmd
84
- - lib/cli_tools/ic-describe-keypairs.sh
85
- - lib/cli_tools/ic-describe-location.cmd
86
- - lib/cli_tools/ic-describe-location.sh
87
- - lib/cli_tools/ic-describe-locations.cmd
88
- - lib/cli_tools/ic-describe-locations.sh
89
- - lib/cli_tools/ic-describe-request.cmd
90
- - lib/cli_tools/ic-describe-request.sh
91
- - lib/cli_tools/ic-describe-vlans.cmd
92
- - lib/cli_tools/ic-describe-vlans.sh
93
- - lib/cli_tools/ic-describe-volume-offerings.cmd
94
- - lib/cli_tools/ic-describe-volume-offerings.sh
95
- - lib/cli_tools/ic-describe-volume.cmd
96
- - lib/cli_tools/ic-describe-volume.sh
97
- - lib/cli_tools/ic-describe-volumes.cmd
98
- - lib/cli_tools/ic-describe-volumes.sh
99
- - lib/cli_tools/ic-detach-volume.cmd
100
- - lib/cli_tools/ic-detach-volume.sh
101
- - lib/cli_tools/ic-extend-reservation.cmd
102
- - lib/cli_tools/ic-extend-reservation.sh
103
- - lib/cli_tools/ic-generate-keypair.cmd
104
- - lib/cli_tools/ic-generate-keypair.sh
105
- - lib/cli_tools/ic-release-address.cmd
106
- - lib/cli_tools/ic-release-address.sh
107
- - lib/cli_tools/ic-remove-keypair.cmd
108
- - lib/cli_tools/ic-remove-keypair.sh
109
- - lib/cli_tools/ic-restart-instance.cmd
110
- - lib/cli_tools/ic-restart-instance.sh
111
- - lib/cli_tools/ic-save-instance.cmd
112
- - lib/cli_tools/ic-save-instance.sh
113
- - lib/cli_tools/ic-set-default-key.cmd
114
- - lib/cli_tools/ic-set-default-key.sh
115
- - lib/cli_tools/ic-update-instance.cmd
116
- - lib/cli_tools/ic-update-instance.sh
117
- - lib/cli_tools/ic-update-keypair.cmd
118
- - lib/cli_tools/ic-update-keypair.sh
119
- - lib/cli_tools/lib/DeveloperCloud_API_Client_JAR.jar
120
- - lib/cli_tools/lib/DeveloperCloud_CMD_Tool.jar
121
- - lib/cli_tools/lib/commons-beanutils-1.6.1.jar
122
- - lib/cli_tools/lib/commons-cli-1.2.jar
123
- - lib/cli_tools/lib/commons-codec-1.3.jar
124
- - lib/cli_tools/lib/commons-collections-3.2.1.jar
125
- - lib/cli_tools/lib/commons-digester-1.8.jar
126
- - lib/cli_tools/lib/commons-httpclient-3.1.jar
127
- - lib/cli_tools/lib/commons-lang-2.3.jar
128
- - lib/cli_tools/lib/commons-logging-1.1.1.jar
129
- - lib/cli_tools/logging.properties
130
- - lib/cli_tools/manifest.rmd
131
42
  - lib/config/config.yml
132
43
  - lib/hash_fix.rb
133
44
  - lib/mime-types-1.16/History.txt
@@ -1,50 +0,0 @@
1
- Command Line Tool
2
- ---- IBM Smart Business Development & Test on the IBM Cloud
3
- Version 1.4.1.CC20110505-2046 March 2011
4
- ---------------
5
- Changes:
6
- 1. Add an option in command ic-describe-images, -y --ignoreAdditionalInfo to ignore the additional information. With this
7
- option, it won't download the parameters.xml from RAM.
8
-
9
- Version 1.4.0.CC20110112-2159 January 2011
10
- ---------------
11
- Changes:
12
- 1.Add command ic-update-instance
13
- 2.Add command ic-attach-volume & ic-detach-volume
14
-
15
- Version 1.3.0.CC20101207-1012 November 2010
16
- ---------------
17
- Changes:
18
- 1. Add DataCenterDownException in several commands.
19
-
20
- Version 1.2.0.20101019-0015 October 2010
21
- ---------------
22
- Changes:
23
- 1. Add command ic-clone-volume
24
- 2. Add parameter -e/--isMiniEphemeral for ic-create-instance to support provision an instance with minimal ephemeral storage
25
- 3. Support multiple addresses attached in one instance
26
-
27
- Version 1.1.3.20101012-0333 October 2010
28
- ---------------
29
- Changes:
30
- 1. Increase the value of the so_timeout
31
-
32
- Version 1.1.2.20100906-0202 September 2010
33
- ---------------
34
- Changes:
35
- 1. Update DeveloperCloud_API_Client_JAR.jar.
36
- Correct the business logic in createInstance.
37
-
38
- Version 1.1.1.20100829-2101 August 2010
39
- ---------------
40
- Changes:
41
- 1. Update DeveloperCloud_API_Client_JAR-javadoc.jar.
42
-
43
- Version 1.1.0.20100623-1406 June 2010
44
- ---------------
45
- Changes:
46
- 1. Add command and parameters to support Vlan
47
- 1) ic-describe-vlans
48
- 2) ic-allocate-address
49
- 3) ic-create-instance
50
- 2. Add commands ic-describe-image-agreement.
@@ -1,29 +0,0 @@
1
- @echo off
2
-
3
- REM ###########################################################################
4
-
5
- REM #
6
-
7
- REM # Licensed Materials - Property of IBM
8
-
9
- REM #
10
-
11
- REM # (C) COPYRIGHT International Business Machines Corp. 2009
12
-
13
- REM #
14
-
15
- REM # All Rights Reserved.
16
-
17
- REM #
18
-
19
- REM # US Government Users Restricted Rights - Use, duplication or
20
-
21
- REM # disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
22
-
23
- REM #
24
-
25
- REM #############################################################################
26
-
27
-
28
-
29
- ic-cmd.cmd -action AddKeyPair %*
@@ -1,15 +0,0 @@
1
- #!/bin/sh
2
- ############################################################################
3
- #
4
- # Licensed Materials - Property of IBM
5
- #
6
- # (C) COPYRIGHT International Business Machines Corp. 2009
7
- #
8
- # All Rights Reserved.
9
- #
10
- # US Government Users Restricted Rights - Use, duplication or
11
- # disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
12
- #
13
- #############################################################################
14
-
15
- ./ic-cmd.sh -action AddKeyPair $*
@@ -1,29 +0,0 @@
1
- @echo off
2
-
3
- REM ###########################################################################
4
-
5
- REM #
6
-
7
- REM # Licensed Materials - Property of IBM
8
-
9
- REM #
10
-
11
- REM # (C) COPYRIGHT International Business Machines Corp. 2009
12
-
13
- REM #
14
-
15
- REM # All Rights Reserved.
16
-
17
- REM #
18
-
19
- REM # US Government Users Restricted Rights - Use, duplication or
20
-
21
- REM # disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
22
-
23
- REM #
24
-
25
- REM #############################################################################
26
-
27
-
28
-
29
- ic-cmd.cmd -action AllocateAddress %*
@@ -1,14 +0,0 @@
1
- #!/bin/sh
2
- ############################################################################
3
- #
4
- # Licensed Materials - Property of IBM
5
- #
6
- # (C) COPYRIGHT International Business Machines Corp. 2009
7
- #
8
- # All Rights Reserved.
9
- #
10
- # US Government Users Restricted Rights - Use, duplication or
11
- # disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
12
- #
13
- #############################################################################
14
- ./ic-cmd.sh -action AllocateAddress $*
@@ -1,27 +0,0 @@
1
- @echo off
2
-
3
- REM ###########################################################################
4
-
5
- REM #
6
-
7
- REM # Licensed Materials - Property of IBM
8
-
9
- REM #
10
-
11
- REM # (C) COPYRIGHT International Business Machines Corp. 2009
12
-
13
- REM #
14
-
15
- REM # All Rights Reserved.
16
-
17
- REM #
18
-
19
- REM # US Government Users Restricted Rights - Use, duplication or
20
-
21
- REM # disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
22
-
23
- REM #
24
-
25
- REM #############################################################################
26
-
27
- ic-cmd.cmd -action AttachVolume %*