studio_api 3.2.0 → 3.2.1

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.
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "http://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  group :test do
6
+ gem 'rake'
6
7
  gem 'fakeweb'
7
8
  gem 'mocha'
8
9
  end
@@ -0,0 +1,99 @@
1
+ Studio API: Wrapper to STUDIO API
2
+ =================================
3
+
4
+ Synopsis
5
+ --------
6
+
7
+ Studio API library is intended to easier access to Studio API from ruby,
8
+ but keep it easily extensible and easy maintanable, so it not need rewritting
9
+ when new attributes introduced to Studio. It leads also that user need to know
10
+ API documentation, which specify what options you need to use (see http://susestudio.com/help/api/v2 ).
11
+ It has also feature which allows using in multiuser system (like server).
12
+
13
+ Example
14
+ -------
15
+
16
+ Example usage ( more in class documentation ). Example show how to clone appliance,
17
+ upload own rpm, select it, find new software and add it, run new build and then print information about appliance.
18
+ Note: All error handling is for simplicity removed. It is same as for ActiveResource so if you want see him, search
19
+ for ActiveResource error handling.
20
+
21
+ ```ruby
22
+ require 'rubygems'
23
+ # If you want use it from git adapt LOAD_PATH
24
+ # you can load just required parts if you need, but Util loaded all classes to properly set it
25
+ require 'studio_api'
26
+
27
+ # Fill up Studio credentials (user name, API key, API URL)
28
+ # See https://susestudio.com/user/show_api_key if you are using SUSE Studio online
29
+ connection = StudioApi::Connection.new('user', 'pwd', 'https://susestudio.com/api/v2/user')
30
+ # Setup the connection for all ActiveResource based class
31
+ StudioApi::Util.configure_studio_connection connection
32
+
33
+ # Find template with KDE4 for SLE11SP1
34
+ templates = StudioApi::TemplateSet.find(:all).find {|s| s.name == "default" }.template
35
+ template = templates.find { |t| t.name == "SLED 11 SP1, KDE 4 desktop" }
36
+ # clone template to new appliance
37
+ appliance = StudioApi::Appliance.clone template.appliance_id, :name => "New cool appliance", :arch => "i686"
38
+ puts "Created appliance #{appliance.inspect}"
39
+
40
+ #add own rpm built agains SLED11_SP1
41
+ File.open("/home/jreidinger/rpms/kezboard-1.0-1.60.noarch.rpm") do |file|
42
+ StudioApi::Rpm.upload file, "SLED11_SP1"
43
+ end
44
+ # and choose it in appliance ( and of course add repository with own rpms)
45
+ appliance.add_user_repository
46
+ appliance.add_package "kezboard", :version => "1.0-1.60"
47
+
48
+ # find samba package and if it is not found in repositories in appliance, try it in all repos
49
+ result = appliance.search_software("samba").find { |s| s.name == "samba" }
50
+ unless result #it is not found in available repos
51
+ result = appliance.search_software("samba", :all_repos => "true").find { |s| s.name == "samba" }
52
+ # add repo which contain samba
53
+ appliance.add_repository result.repository_id
54
+ end
55
+ appliance.add_package "samba"
56
+
57
+ #check if appliance is OK
58
+ if appliance.status.state != "ok"
59
+ raise "appliance is not OK - #{appliance.status.issues.inspect}"
60
+ end
61
+ debugger
62
+ build = StudioApi::RunningBuild.new(:appliance_id => appliance.id, :image_type => "xen")
63
+ build.save
64
+ build.reload
65
+ while build.state != "finished"
66
+ puts "building (#{build.state}) - #{build.percent}%"
67
+ sleep 5
68
+ build.reload
69
+ end
70
+
71
+ final_build = StudioApi::Build.find build.id
72
+ puts final_build.inspect
73
+
74
+ # to clear after playing with appliance if you keep same name, clean remove appliances with:
75
+ # appliances = StudioApi::Appliance.find :all
76
+ # appliances.select{ |a| a.name =~ /cool/i }.each{ |a| a.destroy }
77
+ ```
78
+
79
+ Second example contain how to easy mock calling studio stuff without mock server. Using mocha
80
+
81
+ ```ruby
82
+ require 'mocha'
83
+ require 'studio_api'
84
+
85
+ APPLIANCE_UUID = "68c91080-ccca-4270-a1d3-10e714ddd1c6"
86
+ APPLIANCE_VERSION = "0.0.1"
87
+ APPLIANCE_STUDIO_ID = "97216"
88
+ BUILD_ID = "180420"
89
+ APPLIANCE_1 = StudioApi::Appliance.new :id => APPLIANCE_STUDIO_ID, :name => "Test", :arch => 'i386',
90
+ :last_edited => "2010-10-08 14:46:07 UTC", :estimated_raw_size => "390 MB", :estimated_compressed_size => "140 MB",
91
+ :edit_url => "http://susestudio.com/appliance/edit/266657", :icon_url => "http://susestudio.com/api/v2/user/appliance_icon/266657",
92
+ :basesystem => "SLES11_SP1", :uuid => APPLIANCE_UUID, :parent => {:id => "202443", :name => "SLES 11 SP1, Just enough OS (JeOS)"},
93
+ :builds => [{:id =>BUILD_ID,:version => APPLIANCE_VERSION, :image_type => "vmx", :image_size => "695",
94
+ :compressed_image_size => "121",
95
+ :download_url => "http://susestudio.com/download/a0f0217f0645099c9e41c42e9bf89976/josefs_SLES_11_SP1_git_test.i686-0.0.1.vmx.tar.gz"}]
96
+
97
+ #real mocking
98
+ StudioApi::Appliance.stubs(:find).with(APPLIANCE_STUDIO_ID).returns(APPLIANCE_1)
99
+ ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.0
1
+ 3.2.1
@@ -4,11 +4,11 @@ require "studio_api/util"
4
4
  require "studio_api/studio_resource"
5
5
 
6
6
  module StudioApi
7
- # Adds ability to ActiveResource::Base (short as ARes) to easy set connection to studio in
7
+ # Adds ability to ActiveResource::Base (short as ARes) to easy set connection to studio in
8
8
  # dynamic way, which is not so easy as ARes is designed for static values.
9
9
  # Also modify a few expectation of ActiveResource to fit studio API ( like
10
10
  # missing xml suffix in calls ).
11
- #
11
+ #
12
12
  # @example Add new Studio Resource
13
13
  # # enclose it in module allows to automatic settings with Util
14
14
  # module StudioApi
@@ -18,6 +18,7 @@ module StudioApi
18
18
  # end
19
19
 
20
20
  module StudioResource
21
+
21
22
  # Gets studio connection. Mostly useful internally.
22
23
  # @return (StudioApi::Connection,nil) object of studio connection or nil if not
23
24
  # yet set
@@ -29,6 +30,15 @@ module StudioApi
29
30
  # @param (ActiveResource::Base) extended class
30
31
  def self.extended(base)
31
32
  base.format = :xml #fix ARes 3.1 default ( json )
33
+ # ensure that dasherize is not called as studio use in some keys '-'
34
+ # need to extend it after inclusion
35
+ base.class_eval do
36
+ alias_method :original_encode, :encode
37
+ def encode(options={})
38
+ options[:dasherize] = false
39
+ original_encode options
40
+ end
41
+ end
32
42
  end
33
43
 
34
44
  # Takes information from connection and sets it to ActiveResource::Base.
@@ -62,6 +72,7 @@ module StudioApi
62
72
  # We need to overwrite the paths methods because susestudio doesn't use the
63
73
  # standard .xml filename extension which is expected by ActiveResource.
64
74
  def element_path(id, prefix_options = {}, query_options = nil)
75
+ inspect_connection
65
76
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
66
77
  "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
67
78
  end
@@ -69,8 +80,18 @@ module StudioApi
69
80
  # We need to overwrite the paths methods because susestudio doesn't use the
70
81
  # standard .xml filename extension which is expected by ActiveResource.
71
82
  def collection_path(prefix_options = {}, query_options = nil)
83
+ inspect_connection
72
84
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
73
85
  "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
74
86
  end
87
+
88
+ private
89
+
90
+ def inspect_connection
91
+ unless @studio_connection
92
+ raise RuntimeError, 'Connection to Studio is not set
93
+ Try: StudioApi::Util.studio_connection = StudioApi::Connection.new username, api_key, api_uri'
94
+ end
95
+ end
75
96
  end
76
97
  end
@@ -1,3 +1,10 @@
1
+ -------------------------------------------------------------------
2
+ Wed Oct 3 16:09:18 UTC 2012 - jreidinger@suse.com
3
+
4
+ - fix dasherizing of keys so all keys should be properly passed to
5
+ API
6
+ - 3.2.1
7
+
1
8
  -------------------------------------------------------------------
2
9
  Tue Feb 21 16:48:12 UTC 2012 - jreidinger@suse.com
3
10
 
@@ -39,3 +39,22 @@ class ResourceTest < Test::Unit::TestCase
39
39
  end
40
40
 
41
41
  end
42
+
43
+ class NoConnectionTest < Test::Unit::TestCase
44
+ def test_find
45
+ assert_raise RuntimeError do
46
+ MyTest.find rand 1000
47
+ end
48
+
49
+ assert_raise RuntimeError do
50
+ MyTest2.find rand 100
51
+ end
52
+ end
53
+
54
+ def test_message
55
+ MyTest.find rand 100
56
+ rescue RuntimeError => e
57
+ assert_match /Connection to Studio is not set/, e.message
58
+ end
59
+
60
+ end
@@ -1,8 +1,8 @@
1
1
  require File.expand_path('../../lib/studio_api',__FILE__)
2
2
 
3
3
  require 'fakeweb'
4
- require 'mocha'
5
4
  require 'test/unit'
5
+ require 'mocha'
6
6
 
7
7
  class Test::Unit::TestCase
8
8
  @@username = "foo"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: studio_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 2
9
- - 0
10
- version: 3.2.0
9
+ - 1
10
+ version: 3.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josef Reidinger
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-21 00:00:00 +00:00
19
- default_executable:
18
+ date: 2012-10-29 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: activeresource
@@ -77,11 +76,11 @@ executables: []
77
76
  extensions: []
78
77
 
79
78
  extra_rdoc_files:
80
- - README
79
+ - README.md
81
80
  files:
82
81
  - .gitignore
83
82
  - Gemfile
84
- - README
83
+ - README.md
85
84
  - Rakefile
86
85
  - VERSION
87
86
  - lib/studio_api.rb
@@ -149,11 +148,10 @@ files:
149
148
  - test/template_set_test.rb
150
149
  - test/test_helper.rb
151
150
  - test/testdrive_test.rb
152
- has_rdoc: true
153
151
  homepage: http://github.com/jreidinger/studio_api
154
152
  licenses:
155
- - - GPLv2
156
- - The Ruby License
153
+ - GPLv2
154
+ - The Ruby License
157
155
  post_install_message:
158
156
  rdoc_options:
159
157
  - --line-numbers
@@ -184,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
182
  requirements: []
185
183
 
186
184
  rubyforge_project: studio_api
187
- rubygems_version: 1.5.2
185
+ rubygems_version: 1.8.15
188
186
  signing_key:
189
187
  specification_version: 3
190
188
  summary: Intuitive ruby bindings to Studio Api Interface.
@@ -235,3 +233,4 @@ test_files:
235
233
  - test/template_set_test.rb
236
234
  - test/test_helper.rb
237
235
  - test/testdrive_test.rb
236
+ has_rdoc: true
data/README DELETED
@@ -1,95 +0,0 @@
1
- Studio API: Wrapper to STUDIO API
2
- ====================================
3
-
4
- Synopsis
5
- --------
6
-
7
- Studio API library is intended to easier access to Studio API from ruby,
8
- but keep it easily extensible and easy maintanable, so it not need rewritting
9
- when new attributes introduced to Studio. It leads also that user need to know
10
- API documentation, which specify what options you need to use (see http://susestudio.com/help/api/v1 ).
11
- It has also feature which allows using in multiuser system (like server).
12
-
13
- Example
14
- -------
15
-
16
- Example usage ( more in class documentation ). Example show how to clone appliance,
17
- upload own rpm, select it, find new software and add it, run new build and then print information about appliance.
18
- Note: All error handling is for simplicity removed. It is same as for ActiveResource so if you want see him, search
19
- for ActiveResource error handling.
20
-
21
- require 'rubygems'
22
- # If you want use it from git adapt LOAD_PATH
23
- # you can load just required parts if you need, but Util loaded all classes to properly set it
24
- require 'studio_api'
25
-
26
- # Fill up Studio credentials (user name, API key, API URL)
27
- # See https://susestudio.com/user/show_api_key if you are using SUSE Studio online
28
- connection = StudioApi::Connection.new('user', 'pwd', 'https://susestudio.com/api/v1/user')
29
- # Setup the connection for all ActiveResource based class
30
- StudioApi::Util.configure_studio_connection connection
31
-
32
- # Find template with KDE4 for SLE11SP1
33
- templates = StudioApi::TemplateSet.find(:all).find {|s| s.name == "default" }.template
34
- template = templates.find { |t| t.name == "SLED 11 SP1, KDE 4 desktop" }
35
- # clone template to new appliance
36
- appliance = StudioApi::Appliance.clone template.appliance_id, :name => "New cool appliance", :arch => "i686"
37
- puts "Created appliance #{appliance.inspect}"
38
-
39
- #add own rpm built agains SLED11_SP1
40
- File.open("/home/jreidinger/rpms/kezboard-1.0-1.60.noarch.rpm") do |file|
41
- StudioApi::Rpm.upload file, "SLED11_SP1"
42
- end
43
- # and choose it in appliance ( and of course add repository with own rpms)
44
- appliance.add_user_repository
45
- appliance.add_package "kezboard", :version => "1.0-1.60"
46
-
47
- # find samba package and if it is not found in repositories in appliance, try it in all repos
48
- result = appliance.search_software("samba").find { |s| s.name == "samba" }
49
- unless result #it is not found in available repos
50
- result = appliance.search_software("samba", :all_repos => "true").find { |s| s.name == "samba" }
51
- # add repo which contain samba
52
- appliance.add_repository result.repository_id
53
- end
54
- appliance.add_package "samba"
55
-
56
- #check if appliance is OK
57
- if appliance.status.state != "ok"
58
- raise "appliance is not OK - #{appliance.status.issues.inspect}"
59
- end
60
- debugger
61
- build = StudioApi::RunningBuild.new(:appliance_id => appliance.id, :image_type => "xen")
62
- build.save
63
- build.reload
64
- while build.state != "finished"
65
- puts "building (#{build.state}) - #{build.percent}%"
66
- sleep 5
67
- build.reload
68
- end
69
-
70
- final_build = StudioApi::Build.find build.id
71
- puts final_build.inspect
72
-
73
- # to clear after playing with appliance if you keep same name, clean remove appliances with:
74
- # appliances = StudioApi::Appliance.find :all
75
- # appliances.select{ |a| a.name =~ /cool/i }.each{ |a| a.destroy }
76
-
77
- Second example contain how to easy mock calling studio stuff without mock server. Using mocha
78
-
79
- require 'mocha'
80
- require 'studio_api'
81
-
82
- APPLIANCE_UUID = "68c91080-ccca-4270-a1d3-10e714ddd1c6"
83
- APPLIANCE_VERSION = "0.0.1"
84
- APPLIANCE_STUDIO_ID = "97216"
85
- BUILD_ID = "180420"
86
- APPLIANCE_1 = StudioApi::Appliance.new :id => APPLIANCE_STUDIO_ID, :name => "Test", :arch => 'i386',
87
- :last_edited => "2010-10-08 14:46:07 UTC", :estimated_raw_size => "390 MB", :estimated_compressed_size => "140 MB",
88
- :edit_url => "http://susestudio.com/appliance/edit/266657", :icon_url => "http://susestudio.com/api/v1/user/appliance_icon/266657",
89
- :basesystem => "SLES11_SP1", :uuid => APPLIANCE_UUID, :parent => {:id => "202443", :name => "SLES 11 SP1, Just enough OS (JeOS)"},
90
- :builds => [{:id =>BUILD_ID,:version => APPLIANCE_VERSION, :image_type => "vmx", :image_size => "695",
91
- :compressed_image_size => "121",
92
- :download_url => "http://susestudio.com/download/a0f0217f0645099c9e41c42e9bf89976/josefs_SLES_11_SP1_git_test.i686-0.0.1.vmx.tar.gz"}]
93
-
94
- #real mocking
95
- StudioApi::Appliance.stubs(:find).with(APPLIANCE_STUDIO_ID).returns(APPLIANCE_1)