ruby-hijiki 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/Gemfile +3 -0
  2. data/Rakefile +25 -0
  3. data/lib/hijiki/dcmgr_resource/11.12/account.rb +5 -0
  4. data/lib/hijiki/dcmgr_resource/11.12/base.rb +31 -0
  5. data/lib/hijiki/dcmgr_resource/11.12/host_node.rb +13 -0
  6. data/lib/hijiki/dcmgr_resource/11.12/image.rb +22 -0
  7. data/lib/hijiki/dcmgr_resource/11.12/instance.rb +8 -0
  8. data/lib/hijiki/dcmgr_resource/11.12/instance_spec.rb +7 -0
  9. data/lib/hijiki/dcmgr_resource/11.12/network.rb +7 -0
  10. data/lib/hijiki/dcmgr_resource/11.12/security_group.rb +8 -0
  11. data/lib/hijiki/dcmgr_resource/11.12/ssh_key_pair.rb +8 -0
  12. data/lib/hijiki/dcmgr_resource/11.12/storage_node.rb +7 -0
  13. data/lib/hijiki/dcmgr_resource/11.12/volume.rb +8 -0
  14. data/lib/hijiki/dcmgr_resource/11.12/volume_snapshot.rb +14 -0
  15. data/lib/hijiki/dcmgr_resource/12.03/account.rb +5 -0
  16. data/lib/hijiki/dcmgr_resource/12.03/base.rb +18 -0
  17. data/lib/hijiki/dcmgr_resource/12.03/host_node.rb +6 -0
  18. data/lib/hijiki/dcmgr_resource/12.03/image.rb +6 -0
  19. data/lib/hijiki/dcmgr_resource/12.03/instance.rb +56 -0
  20. data/lib/hijiki/dcmgr_resource/12.03/instance_spec.rb +6 -0
  21. data/lib/hijiki/dcmgr_resource/12.03/network.rb +6 -0
  22. data/lib/hijiki/dcmgr_resource/12.03/security_group.rb +41 -0
  23. data/lib/hijiki/dcmgr_resource/12.03/ssh_key_pair.rb +26 -0
  24. data/lib/hijiki/dcmgr_resource/12.03/storage_node.rb +6 -0
  25. data/lib/hijiki/dcmgr_resource/12.03/volume.rb +52 -0
  26. data/lib/hijiki/dcmgr_resource/12.03/volume_snapshot.rb +54 -0
  27. data/lib/hijiki/dcmgr_resource/base.rb +95 -0
  28. data/lib/hijiki.rb +49 -0
  29. data/ruby-hijiki.gemspec +21 -0
  30. data/test/api/ts_base.rb +14 -0
  31. data/test/api/ts_host_node.rb +27 -0
  32. data/test/api/ts_image.rb +24 -0
  33. data/test/api/ts_instance.rb +21 -0
  34. data/test/api/ts_network.rb +24 -0
  35. data/test/api/ts_ssh_key_pair.rb +21 -0
  36. data/test/api/ts_storage_node.rb +35 -0
  37. data/test/api/ts_volume.rb +30 -0
  38. data/test/api/ts_volume_snapshot.rb +35 -0
  39. data/test/ts_all.rb +19 -0
  40. metadata +85 -0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gem "activeresource", "~> 3.2.3"
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'rubygems/package_task'
3
+
4
+ spec = Gem::Specification.load('ruby-hijiki.gemspec')
5
+
6
+ desc "Build ruby-hijiki, then run tests."
7
+ task :default => [:package]
8
+
9
+ desc 'Generate documentation'
10
+ begin
11
+ require 'yard'
12
+ YARD::Rake::YardocTask.new do |t|
13
+ t.files = ['lib/**/*.rb', '-', 'docs/*.md']
14
+ end
15
+ rescue LoadError
16
+ task :yard do puts "Please install yard first!"; end
17
+ end
18
+
19
+ task :test do
20
+ sh %{cd test && ruby ts_all.rb}
21
+ end
22
+
23
+ Gem::PackageTask.new(spec) do |pkg|
24
+ pkg.need_tar = true
25
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1112
3
+ class Account < Base
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1112
3
+
4
+ @debug = false
5
+
6
+ class << self
7
+ attr_accessor :debug
8
+ end
9
+
10
+ class Base < Hijiki::DcmgrResource::Base
11
+
12
+ self.prefix = '/api/11.12/'
13
+
14
+ def total
15
+ attributes['total']
16
+ end
17
+ end
18
+
19
+ module ListTranslateMethods
20
+ def self.included(base)
21
+ base.extend(ClassMethods)
22
+ end
23
+
24
+ module ClassMethods
25
+ def instantiate_record(record, prefix_options = {})
26
+ record['total'] = record.delete('owner_total')
27
+ super(record, prefix_options)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1112
3
+ class HostNode < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ include ListTranslateMethods
6
+ end
7
+
8
+ HostNode.preload_resource('Result', Module.new {
9
+ def node_id
10
+ nil
11
+ end
12
+ })
13
+ end
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'yaml'
4
+
5
+ module Hijiki::DcmgrResource::V1112
6
+ class Image < Base
7
+ include Hijiki::DcmgrResource::ListMethods
8
+ include ListTranslateMethods
9
+ end
10
+
11
+ Image.preload_resource('Result', Module.new {
12
+ def source
13
+ find_or_create_resource_for('source').new(YAML::load(attributes['source']))
14
+ end
15
+
16
+ def features
17
+ find_or_create_resource_for('features').new(YAML::load(attributes['features']))
18
+ end
19
+ })
20
+
21
+ end
22
+
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1112
3
+ class Instance < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ include ListTranslateMethods
6
+ include Hijiki::DcmgrResource::V1203::InstanceMethods
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1112
3
+ class InstanceSpec < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ include ListTranslateMethods
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1112
3
+ class Network < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ include ListTranslateMethods
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1112
3
+ class SecurityGroup < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ include ListTranslateMethods
6
+ include Hijiki::DcmgrResource::V1203::SecurityGroupMethods
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1112
3
+ class SshKeyPair < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ include ListTranslateMethods
6
+ include Hijiki::DcmgrResource::V1203::SshKeyPairMethods
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1112
3
+ class StorageNode < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ include ListTranslateMethods
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1112
3
+ class Volume < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ include ListTranslateMethods
6
+ include Hijiki::DcmgrResource::V1203::VolumeMethods
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1112
3
+ class VolumeSnapshot < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ include ListTranslateMethods
6
+ include Hijiki::DcmgrResource::V1203::VolumeSnapshotMethods
7
+ end
8
+
9
+ VolumeSnapshot.preload_resource('Result', Module.new {
10
+ def storage_node
11
+ nil
12
+ end
13
+ })
14
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+ class Account < Base
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+
4
+ @debug = false
5
+
6
+ class << self
7
+ attr_accessor :debug
8
+ end
9
+
10
+ class Base < Hijiki::DcmgrResource::Base
11
+
12
+ self.prefix = '/api/12.03/'
13
+
14
+ def total
15
+ attributes['total']
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+ class HostNode < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+ class Image < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ end
6
+ end
@@ -0,0 +1,56 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+ module InstanceMethods
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def create(params)
10
+ instance = self.new
11
+ instance.image_id = params[:image_id]
12
+ instance.instance_spec_id = params[:instance_spec_id]
13
+ instance.host_pool_id = params[:host_pool_id]
14
+ instance.host_name = params[:host_name]
15
+ instance.user_data = params[:user_data]
16
+ instance.security_groups = params[:security_groups]
17
+ instance.ssh_key_id = params[:ssh_key]
18
+ instance.save
19
+ instance
20
+ end
21
+
22
+ def destroy(instance_id)
23
+ self.delete(instance_id).body
24
+ end
25
+
26
+ def reboot(instance_id)
27
+ @collection ||= self.collection_name
28
+ self.collection_name = File.join(@collection,instance_id)
29
+ result = self.put(:reboot)
30
+ self.collection_name = @collection
31
+ result.body
32
+ end
33
+
34
+ def start(instance_id)
35
+ @collection ||= self.collection_name
36
+ self.collection_name = File.join(@collection,instance_id)
37
+ result = self.put(:start)
38
+ self.collection_name = @collection
39
+ result.body
40
+ end
41
+
42
+ def stop(instance_id)
43
+ @collection ||= self.collection_name
44
+ self.collection_name = File.join(@collection,instance_id)
45
+ result = self.put(:stop)
46
+ self.collection_name = @collection
47
+ result.body
48
+ end
49
+ end
50
+ end
51
+
52
+ class Instance < Base
53
+ include Hijiki::DcmgrResource::ListMethods
54
+ include InstanceMethods
55
+ end
56
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+ class InstanceSpec < Hijiki::DcmgrResource::V1112::Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+ class Network < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ end
6
+ end
@@ -0,0 +1,41 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+ module SecurityGroupMethods
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def create(params)
10
+ security_group = self.new
11
+ security_group.description = params[:description]
12
+ security_group.rule = params[:rule]
13
+ security_group.save
14
+ security_group
15
+ end
16
+
17
+ def update(uuid,params)
18
+ self.put(uuid,params).body
19
+ end
20
+
21
+ def destroy(uuid)
22
+ self.delete(uuid).body
23
+ end
24
+ end
25
+
26
+ # workaround for the bug:
27
+ # the value of the key "rule" is encoded to JSON wrongly by
28
+ # ActiveSupport::JSON encoder.
29
+ # "{\"security_group\":{\"description\":\"\",\"rule\":[[null,[],null]]}}"
30
+ # So it has to use the encoder from JSON library.
31
+ def to_json(options={})
32
+ require 'json'
33
+ {'security_group'=>@attributes}.to_json
34
+ end
35
+ end
36
+
37
+ class SecurityGroup < Base
38
+ include Hijiki::DcmgrResource::ListMethods
39
+ include SecurityGroupMethods
40
+ end
41
+ end
@@ -0,0 +1,26 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+ module SshKeyPairMethods
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def create(params)
10
+ ssh_key_pair = self.new
11
+ ssh_key_pair.download_once = params[:download_once]
12
+ ssh_key_pair.save
13
+ ssh_key_pair
14
+ end
15
+
16
+ def destroy(uuid)
17
+ self.delete(uuid).body
18
+ end
19
+ end
20
+ end
21
+
22
+ class SshKeyPair < Base
23
+ include Hijiki::DcmgrResource::ListMethods
24
+ include SshKeyPairMethods
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+ class StorageNode < Base
4
+ include Hijiki::DcmgrResource::ListMethods
5
+ end
6
+ end
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+ module VolumeMethods
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def create(params)
10
+ volume = self.new
11
+ volume.volume_size = params[:volume_size]
12
+ volume.snapshot_id = params[:snapshot_id]
13
+ volume.storage_pool_id = params[:storage_pool_id]
14
+ volume.save
15
+ volume
16
+ end
17
+
18
+ def destroy(volume_id)
19
+ self.delete(volume_id).body
20
+ end
21
+
22
+ def attach(volume_id, instance_id)
23
+ @collection ||= self.collection_name
24
+ self.collection_name = File.join(@collection,volume_id)
25
+ result = self.put(:attach, {:volume_id => volume_id,:instance_id => instance_id})
26
+ self.collection_name = @collection
27
+ result.body
28
+ end
29
+
30
+ def detach(volume_id)
31
+ @collection ||= self.collection_name
32
+ self.collection_name = File.join(@collection,volume_id)
33
+ result = self.put(:detach, {:volume_id => volume_id})
34
+ self.collection_name = @collection
35
+ result.body
36
+ end
37
+
38
+ def status(account_id)
39
+ @collection ||= self.collection_name
40
+ self.collection_name = File.join(@collection,account_id)
41
+ result = self.get(:status)
42
+ self.collection_name = @collection
43
+ result
44
+ end
45
+ end
46
+ end
47
+
48
+ class Volume < Base
49
+ include Hijiki::DcmgrResource::ListMethods
50
+ include VolumeMethods
51
+ end
52
+ end
@@ -0,0 +1,54 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource::V1203
3
+ module VolumeSnapshotMethods
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def list(params = {})
10
+ data = self.find(:all, :params => params)
11
+ results = []
12
+ data.each { |row|
13
+ results << row.attributes
14
+ }
15
+ end
16
+
17
+ def create(params)
18
+ snapshot = self.new
19
+ snapshot.volume_id = params[:volume_id]
20
+ snapshot.destination = params[:destination]
21
+ snapshot.save
22
+ snapshot
23
+ end
24
+
25
+ def destroy(snapshot_id)
26
+ self.delete(snapshot_id).body
27
+ end
28
+
29
+ def status(account_id)
30
+ @collection ||= self.collection_name
31
+ self.collection_name = File.join(@collection,account_id)
32
+ result = self.get(:status)
33
+ self.collection_name = @collection
34
+ result
35
+ end
36
+
37
+ def upload_destination
38
+ result = self.get(:upload_destination)
39
+ result
40
+ end
41
+ end
42
+ end
43
+
44
+ class VolumeSnapshot < Base
45
+ include Hijiki::DcmgrResource::ListMethods
46
+ include VolumeSnapshotMethods
47
+ end
48
+
49
+ VolumeSnapshot.preload_resource('Result', Module.new {
50
+ def storage_node
51
+ attributes['storage_node'] ||= StorageNode.find(attributes['storage_node_id'])
52
+ end
53
+ })
54
+ end
@@ -0,0 +1,95 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Hijiki::DcmgrResource
3
+
4
+ @debug = false
5
+
6
+ class << self
7
+ attr_accessor :debug
8
+ end
9
+
10
+ class Base < ActiveResource::Base
11
+
12
+ # self.site = 'http://your.dcmgr.api.server'
13
+ self.timeout = 30
14
+ self.format = :json
15
+
16
+ class << self
17
+
18
+ def total_resource
19
+ result = self.find(:first,:params => {:start => 0,:limit => 1})
20
+ result.total
21
+ end
22
+
23
+ def get_resource_state_count(resources, state)
24
+ resource_count = 0
25
+ unless resources.empty?
26
+ resources.each do |item|
27
+ if item.state == state
28
+ resource_count += 1;
29
+ end
30
+ end
31
+ end
32
+ resource_count
33
+ end
34
+
35
+ def preload_resource(resource_name, compatibility_module)
36
+ resource = self.const_set(resource_name, Class.new(Hijiki::DcmgrResource::Base))
37
+ resource.prefix = self.prefix
38
+ resource.site = self.site
39
+
40
+ resource.class_eval do
41
+ include compatibility_module
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+
48
+ module ListMethods
49
+ def self.included(base)
50
+ base.extend(ClassMethods)
51
+ end
52
+
53
+ module ClassMethods
54
+ def list(params = {})
55
+ self.find(:all,:params => params)
56
+ end
57
+
58
+ def show(uuid)
59
+ self.get(uuid)
60
+ end
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ ActiveResource::Connection.class_eval do
67
+
68
+ class << self
69
+ def set_vdc_account_uuid(uuid)
70
+ class_variable_set(:@@vdc_account_uuid,uuid)
71
+ end
72
+ end
73
+
74
+ private
75
+ def default_header
76
+ @default_header = {
77
+ 'X-VDC-ACCOUNT-UUID' => self.class.send(:class_variable_get,:@@vdc_account_uuid)
78
+ }
79
+ end
80
+
81
+ def configure_http(http)
82
+ http = apply_ssl_options(http)
83
+
84
+ #add debug
85
+ http.set_debug_output($stderr) if Hijiki::DcmgrResource.debug
86
+
87
+ # Net::HTTP timeouts default to 60 seconds.
88
+ if @timeout
89
+ http.open_timeout = @timeout
90
+ http.read_timeout = @timeout
91
+ end
92
+
93
+ http
94
+ end
95
+ end
data/lib/hijiki.rb ADDED
@@ -0,0 +1,49 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'active_resource'
4
+
5
+ module Hijiki
6
+ module DcmgrResource
7
+
8
+ require 'hijiki/dcmgr_resource/base'
9
+
10
+ module V1112
11
+ require 'hijiki/dcmgr_resource/11.12/base'
12
+
13
+ autoload :Account, 'hijiki/dcmgr_resource/11.12/account'
14
+ autoload :HostNode, 'hijiki/dcmgr_resource/11.12/host_node'
15
+ autoload :Image, 'hijiki/dcmgr_resource/11.12/image'
16
+ autoload :Instance, 'hijiki/dcmgr_resource/11.12/instance'
17
+ autoload :InstanceSpec, 'hijiki/dcmgr_resource/11.12/instance_spec'
18
+ autoload :Network, 'hijiki/dcmgr_resource/11.12/network'
19
+ autoload :SecurityGroup, 'hijiki/dcmgr_resource/11.12/security_group'
20
+ autoload :SshKeyPair, 'hijiki/dcmgr_resource/11.12/ssh_key_pair'
21
+ autoload :StorageNode, 'hijiki/dcmgr_resource/11.12/storage_node'
22
+ autoload :Volume, 'hijiki/dcmgr_resource/11.12/volume'
23
+ autoload :VolumeSnapshot, 'hijiki/dcmgr_resource/11.12/volume_snapshot'
24
+ end
25
+
26
+ module V1203
27
+ require 'hijiki/dcmgr_resource/12.03/base'
28
+
29
+ autoload :Account, 'hijiki/dcmgr_resource/12.03/account'
30
+ autoload :HostNode, 'hijiki/dcmgr_resource/12.03/host_node'
31
+ autoload :Image, 'hijiki/dcmgr_resource/12.03/image'
32
+ autoload :Instance, 'hijiki/dcmgr_resource/12.03/instance'
33
+ autoload :InstanceSpec, 'hijiki/dcmgr_resource/12.03/instance_spec'
34
+ autoload :Network, 'hijiki/dcmgr_resource/12.03/network'
35
+ autoload :SecurityGroup, 'hijiki/dcmgr_resource/12.03/security_group'
36
+ autoload :SshKeyPair, 'hijiki/dcmgr_resource/12.03/ssh_key_pair'
37
+ autoload :StorageNode, 'hijiki/dcmgr_resource/12.03/storage_node'
38
+ autoload :Volume, 'hijiki/dcmgr_resource/12.03/volume'
39
+ autoload :VolumeSnapshot, 'hijiki/dcmgr_resource/12.03/volume_snapshot'
40
+
41
+ autoload :InstanceMethods, 'hijiki/dcmgr_resource/12.03/instance'
42
+ autoload :SecurityGroupMethods, 'hijiki/dcmgr_resource/12.03/security_group'
43
+ autoload :SshKeyPairMethods, 'hijiki/dcmgr_resource/12.03/ssh_key_pair'
44
+ autoload :VolumeMethods, 'hijiki/dcmgr_resource/12.03/volume'
45
+ autoload :VolumeSnapshotMethods, 'hijiki/dcmgr_resource/12.03/volume_snapshot'
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{ruby-hijiki}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = [%q{axsh Ltd.}]
9
+ s.date = %q{2012-06-01}
10
+ s.description = %q{Datacenter Hypervisor API Library}
11
+ s.email = [%q{dev@axsh.net}]
12
+
13
+ s.homepage = %q{http://wakame.jp/}
14
+ s.require_paths = [%q{lib}]
15
+ s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
16
+ s.rubygems_version = %q{1.8.6}
17
+ s.summary = %q{Wakame-VDC: API library}
18
+
19
+ s.files = [%q{Gemfile}, %q{Rakefile}, %q{lib/hijiki.rb}, %q{lib/hijiki/dcmgr_resource/11.12/account.rb}, %q{lib/hijiki/dcmgr_resource/11.12/base.rb}, %q{lib/hijiki/dcmgr_resource/11.12/host_node.rb}, %q{lib/hijiki/dcmgr_resource/11.12/image.rb}, %q{lib/hijiki/dcmgr_resource/11.12/instance.rb}, %q{lib/hijiki/dcmgr_resource/11.12/instance_spec.rb}, %q{lib/hijiki/dcmgr_resource/11.12/network.rb}, %q{lib/hijiki/dcmgr_resource/11.12/security_group.rb}, %q{lib/hijiki/dcmgr_resource/11.12/ssh_key_pair.rb}, %q{lib/hijiki/dcmgr_resource/11.12/storage_node.rb}, %q{lib/hijiki/dcmgr_resource/11.12/volume.rb}, %q{lib/hijiki/dcmgr_resource/11.12/volume_snapshot.rb}, %q{lib/hijiki/dcmgr_resource/12.03/account.rb}, %q{lib/hijiki/dcmgr_resource/12.03/base.rb}, %q{lib/hijiki/dcmgr_resource/12.03/host_node.rb}, %q{lib/hijiki/dcmgr_resource/12.03/image.rb}, %q{lib/hijiki/dcmgr_resource/12.03/instance.rb}, %q{lib/hijiki/dcmgr_resource/12.03/instance_spec.rb}, %q{lib/hijiki/dcmgr_resource/12.03/network.rb}, %q{lib/hijiki/dcmgr_resource/12.03/security_group.rb}, %q{lib/hijiki/dcmgr_resource/12.03/ssh_key_pair.rb}, %q{lib/hijiki/dcmgr_resource/12.03/storage_node.rb}, %q{lib/hijiki/dcmgr_resource/12.03/volume.rb}, %q{lib/hijiki/dcmgr_resource/12.03/volume_snapshot.rb}, %q{lib/hijiki/dcmgr_resource/base.rb}, %q{ruby-hijiki.gemspec}, %q{test/api/ts_base.rb}, %q{test/api/ts_host_node.rb}, %q{test/api/ts_image.rb}, %q{test/api/ts_instance.rb}, %q{test/api/ts_network.rb}, %q{test/api/ts_ssh_key_pair.rb}, %q{test/api/ts_storage_node.rb}, %q{test/api/ts_volume.rb}, %q{test/api/ts_volume_snapshot.rb}, %q{test/ts_all.rb}]
20
+
21
+ end
@@ -0,0 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'test/unit'
4
+
5
+ module TestBaseMethods
6
+ def test_basic_1112
7
+ [:v1112, :v1203].each { |api_ver|
8
+ object = api_class(api_ver).find(:first,:params => {:start => 0,:limit => 1})
9
+
10
+ assert_not_nil(object.total)
11
+ assert_raise(NoMethodError) { object.owner_total }
12
+ }
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class TestHostNode < Test::Unit::TestCase
4
+ def api_class(version)
5
+ case version
6
+ when :v1112 then Hijiki::DcmgrResource::V1112::HostNode
7
+ when :v1203 then Hijiki::DcmgrResource::V1203::HostNode
8
+ end
9
+ end
10
+
11
+ include TestBaseMethods
12
+
13
+ def test_host_node
14
+ [:v1112, :v1203].each { |api_ver|
15
+ assert_nothing_raised() {
16
+ host_node = api_class(api_ver).find(:first).results.first
17
+
18
+ if api_ver == :v1112
19
+ assert_equal(nil, host_node.node_id)
20
+ else
21
+ assert_not_equal(nil, host_node.node_id)
22
+ end
23
+ }
24
+ }
25
+ end
26
+
27
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class TestImage < Test::Unit::TestCase
4
+ def api_class(version)
5
+ case version
6
+ when :v1112 then Hijiki::DcmgrResource::V1112::Image
7
+ when :v1203 then Hijiki::DcmgrResource::V1203::Image
8
+ end
9
+ end
10
+
11
+ include TestBaseMethods
12
+
13
+ def test_image
14
+ [:v1112, :v1203].each { |api_ver|
15
+ assert_nothing_raised() {
16
+ image = api_class(api_ver).find(:first).results.first
17
+
18
+ assert_not_nil(image.source.uri)
19
+ assert_not_nil(image.features)
20
+ }
21
+ }
22
+ end
23
+
24
+ end
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class TestInstance < Test::Unit::TestCase
4
+ def api_class(version)
5
+ case version
6
+ when :v1112 then Hijiki::DcmgrResource::V1112::Instance
7
+ when :v1203 then Hijiki::DcmgrResource::V1203::Instance
8
+ end
9
+ end
10
+
11
+ include TestBaseMethods
12
+
13
+ def test_instance
14
+ [:v1112, :v1203].each { |api_ver|
15
+ assert_nothing_raised() {
16
+ instance = api_class(api_ver).find(:first).results.first
17
+ }
18
+ }
19
+ end
20
+
21
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class TestNetwork < Test::Unit::TestCase
4
+ def api_class(version)
5
+ case version
6
+ when :v1112 then Hijiki::DcmgrResource::V1112::Network
7
+ when :v1203 then Hijiki::DcmgrResource::V1203::Network
8
+ end
9
+ end
10
+
11
+ include TestBaseMethods
12
+
13
+ def test_network
14
+ [:v1112, :v1203].each { |api_ver|
15
+ assert_nothing_raised() {
16
+ object = api_class(api_ver).find(:first).results.first
17
+
18
+ assert(object.uuid =~ /^nw-[0-9a-z]*$/)
19
+ assert_not_nil(object.account_id)
20
+ }
21
+ }
22
+ end
23
+
24
+ end
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class TestSshKeyPair < Test::Unit::TestCase
4
+ def api_class(version)
5
+ case version
6
+ when :v1112 then Hijiki::DcmgrResource::V1112::SshKeyPair
7
+ when :v1203 then Hijiki::DcmgrResource::V1203::SshKeyPair
8
+ end
9
+ end
10
+
11
+ include TestBaseMethods
12
+
13
+ def test_ssh_key_pair
14
+ [:v1112, :v1203].each { |api_ver|
15
+ assert_nothing_raised() {
16
+ ssh_key_pair = api_class(api_ver).find(:first).results.first
17
+ }
18
+ }
19
+ end
20
+
21
+ end
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class TestStorageNode < Test::Unit::TestCase
4
+ def api_class(version)
5
+ case version
6
+ when :v1112 then Hijiki::DcmgrResource::V1112::StorageNode
7
+ when :v1203 then Hijiki::DcmgrResource::V1203::StorageNode
8
+ end
9
+ end
10
+
11
+ include TestBaseMethods
12
+
13
+ def test_storage_node
14
+ [:v1112, :v1203].each { |api_ver|
15
+ assert_nothing_raised() {
16
+ storage_node = api_class(api_ver).find(:first).results.first
17
+
18
+ if api_ver == :v1112
19
+ assert_raise(NoMethodError) { storage_node.node_id }
20
+ else
21
+ assert_not_nil(storage_node.node_id)
22
+ end
23
+ }
24
+ }
25
+ end
26
+
27
+ def test_list_1203
28
+ [:v1112, :v1203].each { |api_ver|
29
+ assert_nothing_raised() {
30
+ list = api_class(api_ver).list
31
+ }
32
+ }
33
+ end
34
+
35
+ end
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class TestVolume < Test::Unit::TestCase
4
+ def api_class(version)
5
+ case version
6
+ when :v1112 then Hijiki::DcmgrResource::V1112::Volume
7
+ when :v1203 then Hijiki::DcmgrResource::V1203::Volume
8
+ end
9
+ end
10
+
11
+ include TestBaseMethods
12
+
13
+ def test_volume
14
+ [:v1112, :v1203].each { |api_ver|
15
+ assert_nothing_raised() {
16
+ object = api_class(api_ver).find(:first).results.first
17
+
18
+ if api_ver == :v1112
19
+ assert_raise(NoMethodError) { object.account_id }
20
+ assert_equal(String, object.instance_id.class)
21
+ assert(object.instance_id =~ /^i-[0-9]*/)
22
+ else
23
+ assert_not_nil(object.account_id)
24
+ assert_equal(Fixnum, object.instance_id.class)
25
+ end
26
+ }
27
+ }
28
+ end
29
+
30
+ end
@@ -0,0 +1,35 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ class TestVolumeSnapshot < Test::Unit::TestCase
4
+ def api_class(version)
5
+ case version
6
+ when :v1112 then Hijiki::DcmgrResource::V1112::VolumeSnapshot
7
+ when :v1203 then Hijiki::DcmgrResource::V1203::VolumeSnapshot
8
+ end
9
+ end
10
+
11
+ include TestBaseMethods
12
+
13
+ def test_volume_snapshot
14
+ [:v1112, :v1203].each { |api_ver|
15
+ assert_nothing_raised() {
16
+ object = api_class(api_ver).find(:first).results.first
17
+
18
+ assert(object.origin_volume_id =~ /^vol-[0-9a-z]*$/)
19
+
20
+ if api_ver == :v1112
21
+ assert_raise(NoMethodError) { object.account_id }
22
+ assert_raise(NoMethodError) { object.storage_node_id }
23
+
24
+ assert_equal(nil, object.storage_node)
25
+ else
26
+ assert_not_nil(object.account_id)
27
+ assert(object.storage_node_id =~ /^sn-[0-9a-z]*$/)
28
+
29
+ assert_equal(Hijiki::DcmgrResource::V1203::StorageNode, object.storage_node.class)
30
+ end
31
+ }
32
+ }
33
+ end
34
+
35
+ end
data/test/ts_all.rb ADDED
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
4
+
5
+ require 'hijiki'
6
+
7
+ ActiveResource::Base.class_eval do
8
+ self.site = 'http://localhost:9001'
9
+ end
10
+
11
+ ActiveResource::Connection.set_vdc_account_uuid('a-shpoolxx')
12
+
13
+ require File.join(File.dirname(__FILE__) + '/api/ts_base.rb')
14
+
15
+ ['api'].each do |l|
16
+ Dir.glob(File.join(File.dirname(__FILE__) + "/#{l}", '*.rb')).each do |f|
17
+ require f
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-hijiki
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - axsh Ltd.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Datacenter Hypervisor API Library
15
+ email:
16
+ - dev@axsh.net
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - Gemfile
22
+ - Rakefile
23
+ - lib/hijiki.rb
24
+ - lib/hijiki/dcmgr_resource/11.12/account.rb
25
+ - lib/hijiki/dcmgr_resource/11.12/base.rb
26
+ - lib/hijiki/dcmgr_resource/11.12/host_node.rb
27
+ - lib/hijiki/dcmgr_resource/11.12/image.rb
28
+ - lib/hijiki/dcmgr_resource/11.12/instance.rb
29
+ - lib/hijiki/dcmgr_resource/11.12/instance_spec.rb
30
+ - lib/hijiki/dcmgr_resource/11.12/network.rb
31
+ - lib/hijiki/dcmgr_resource/11.12/security_group.rb
32
+ - lib/hijiki/dcmgr_resource/11.12/ssh_key_pair.rb
33
+ - lib/hijiki/dcmgr_resource/11.12/storage_node.rb
34
+ - lib/hijiki/dcmgr_resource/11.12/volume.rb
35
+ - lib/hijiki/dcmgr_resource/11.12/volume_snapshot.rb
36
+ - lib/hijiki/dcmgr_resource/12.03/account.rb
37
+ - lib/hijiki/dcmgr_resource/12.03/base.rb
38
+ - lib/hijiki/dcmgr_resource/12.03/host_node.rb
39
+ - lib/hijiki/dcmgr_resource/12.03/image.rb
40
+ - lib/hijiki/dcmgr_resource/12.03/instance.rb
41
+ - lib/hijiki/dcmgr_resource/12.03/instance_spec.rb
42
+ - lib/hijiki/dcmgr_resource/12.03/network.rb
43
+ - lib/hijiki/dcmgr_resource/12.03/security_group.rb
44
+ - lib/hijiki/dcmgr_resource/12.03/ssh_key_pair.rb
45
+ - lib/hijiki/dcmgr_resource/12.03/storage_node.rb
46
+ - lib/hijiki/dcmgr_resource/12.03/volume.rb
47
+ - lib/hijiki/dcmgr_resource/12.03/volume_snapshot.rb
48
+ - lib/hijiki/dcmgr_resource/base.rb
49
+ - ruby-hijiki.gemspec
50
+ - test/api/ts_base.rb
51
+ - test/api/ts_host_node.rb
52
+ - test/api/ts_image.rb
53
+ - test/api/ts_instance.rb
54
+ - test/api/ts_network.rb
55
+ - test/api/ts_ssh_key_pair.rb
56
+ - test/api/ts_storage_node.rb
57
+ - test/api/ts_volume.rb
58
+ - test/api/ts_volume_snapshot.rb
59
+ - test/ts_all.rb
60
+ homepage: http://wakame.jp/
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: 1.8.7
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.23
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: ! 'Wakame-VDC: API library'
84
+ test_files: []
85
+ has_rdoc: