ocs 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/ocs.rb +20 -0
- data/lib/ocs/client.rb +60 -0
- data/lib/ocs/request.rb +85 -0
- data/lib/ocs/resources.rb +24 -0
- data/lib/ocs/resources/account.rb +7 -0
- data/lib/ocs/resources/address.rb +6 -0
- data/lib/ocs/resources/affinity_group.rb +6 -0
- data/lib/ocs/resources/async_job.rb +8 -0
- data/lib/ocs/resources/base.rb +190 -0
- data/lib/ocs/resources/disk_offering.rb +7 -0
- data/lib/ocs/resources/domain.rb +7 -0
- data/lib/ocs/resources/group.rb +7 -0
- data/lib/ocs/resources/host.rb +7 -0
- data/lib/ocs/resources/iso.rb +8 -0
- data/lib/ocs/resources/nic.rb +17 -0
- data/lib/ocs/resources/os_type.rb +9 -0
- data/lib/ocs/resources/security_group.rb +6 -0
- data/lib/ocs/resources/service_offering.rb +34 -0
- data/lib/ocs/resources/ssh_key_pair.rb +7 -0
- data/lib/ocs/resources/tag.rb +22 -0
- data/lib/ocs/resources/template.rb +53 -0
- data/lib/ocs/resources/virtual_machine.rb +90 -0
- data/lib/ocs/resources/zone.rb +34 -0
- data/lib/ocs/response.rb +17 -0
- data/lib/ocs/version.rb +3 -0
- data/ocs.gemspec +29 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 577b3c6848ab14e6b0955816682d593cac6dd8ec
|
4
|
+
data.tar.gz: 95055bd21dac7c1cfbfb993685322cf12c17866d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0783b506af579edc04433a27020c802e0d8b57fa15aab815e658d4dfe0416af632963f72fc075bcac3f008c5d2e31724afb713875e11fbde38344ead96ddf526
|
7
|
+
data.tar.gz: 967915519022b16e200e4a7497956ed21233e30f7c111a12151900edf7c556ce8a02076e54624dd5d2af0913aa8fa41cf35481658c9f85f81ef6bf5b56e8f086
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 nownabe
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Ocs
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ocs`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ocs'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ocs
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Direct
|
26
|
+
```ruby
|
27
|
+
require "ocs"
|
28
|
+
|
29
|
+
clinet = Ocs::Clinet.new(
|
30
|
+
host: "your-cloudstack.host",
|
31
|
+
api_key: YOUR_API_KEY,
|
32
|
+
secret_key: YOUR_SECRET_KEY
|
33
|
+
)
|
34
|
+
|
35
|
+
response = client.call("listVirtualMachines")
|
36
|
+
p response
|
37
|
+
response[:virtualmachine].each { |vm| puts vm[:displayname] }
|
38
|
+
|
39
|
+
response = client.call("listTemplates", templatefilter: "featured")
|
40
|
+
p response
|
41
|
+
```
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
46
|
+
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/[my-github-username]/ocs/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ocs"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/ocs.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "base64"
|
2
|
+
require "openssl"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
require "active_support/core_ext/class/attribute"
|
6
|
+
require "active_support/core_ext/hash/indifferent_access"
|
7
|
+
require "active_support/core_ext/object/blank"
|
8
|
+
require "active_support/core_ext/string/inflections"
|
9
|
+
require "faraday"
|
10
|
+
require "faraday_middleware"
|
11
|
+
|
12
|
+
module Ocs
|
13
|
+
class OcsError < StandardError; end
|
14
|
+
end
|
15
|
+
|
16
|
+
require "ocs/client"
|
17
|
+
require "ocs/request"
|
18
|
+
require "ocs/resources"
|
19
|
+
require "ocs/response"
|
20
|
+
require "ocs/version"
|
data/lib/ocs/client.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module Ocs
|
2
|
+
class Client
|
3
|
+
attr_reader :api_key, :host, :path, :secret_key, :logger
|
4
|
+
|
5
|
+
def initialize(host:, api_key:, secret_key:, path: "/client/api", logger: nil)
|
6
|
+
@host = host
|
7
|
+
@api_key = api_key
|
8
|
+
@secret_key = secret_key
|
9
|
+
@path = path
|
10
|
+
@logger = logger
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(name, options = {})
|
14
|
+
send(name, options)
|
15
|
+
.body["#{name.downcase.pluralize}response"]
|
16
|
+
end
|
17
|
+
|
18
|
+
def connection
|
19
|
+
@connection ||=
|
20
|
+
Faraday.new(url: url_prefix) do |connection|
|
21
|
+
connection.response :json
|
22
|
+
connection.adapter Faraday.default_adapter
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def new(resource_name, options = {})
|
27
|
+
resource_class(resource_name).new(self, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def send(name, options = {})
|
31
|
+
Request.new(
|
32
|
+
name: name,
|
33
|
+
options: options,
|
34
|
+
client: self
|
35
|
+
).send
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def resource_class(resource_name)
|
41
|
+
"ocs/resources/#{resource_name}".camelize.constantize
|
42
|
+
end
|
43
|
+
|
44
|
+
def url_prefix
|
45
|
+
"https://#{host}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def method_missing(method, *args)
|
49
|
+
return super unless args.first.to_s =~ /^[a-zA-Z]/
|
50
|
+
|
51
|
+
raw_resource_name, *arguments = args
|
52
|
+
resource_name = raw_resource_name.to_s.singularize
|
53
|
+
if Resources.const_defined?(resource_name.camelize)
|
54
|
+
return resource_class(resource_name).public_send(method, self, *arguments)
|
55
|
+
end
|
56
|
+
|
57
|
+
super
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/ocs/request.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
module Ocs
|
2
|
+
class Request
|
3
|
+
attr_reader :name, :options, :client
|
4
|
+
|
5
|
+
def initialize(name:, options: {}, client:)
|
6
|
+
@name = name
|
7
|
+
@options = options
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
def send
|
12
|
+
Response.new(connection.get(path, escaped_parameters, headers))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def api_key
|
18
|
+
client.api_key
|
19
|
+
end
|
20
|
+
|
21
|
+
def connection
|
22
|
+
client.connection
|
23
|
+
end
|
24
|
+
|
25
|
+
def escape(string)
|
26
|
+
URI.escape(string)
|
27
|
+
end
|
28
|
+
|
29
|
+
def escaped_parameters
|
30
|
+
escaped_parameters_without_signature.merge(
|
31
|
+
signature: escaped_signature
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def escaped_parameters_without_signature
|
36
|
+
@escaped_parameters_without_signature ||=
|
37
|
+
parameters_without_signature.inject({}) do |escaped_hash, (key, value)|
|
38
|
+
escaped_hash[key] = escape(value)
|
39
|
+
escaped_hash
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def escaped_signature
|
44
|
+
escape(signature)
|
45
|
+
end
|
46
|
+
|
47
|
+
def headers
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def parameters_without_signature
|
52
|
+
options.merge(
|
53
|
+
command: name,
|
54
|
+
apikey: api_key,
|
55
|
+
response: "json"
|
56
|
+
)
|
57
|
+
end
|
58
|
+
|
59
|
+
def path
|
60
|
+
client.path
|
61
|
+
end
|
62
|
+
|
63
|
+
def secret_key
|
64
|
+
client.secret_key
|
65
|
+
end
|
66
|
+
|
67
|
+
def signature
|
68
|
+
Base64.encode64(
|
69
|
+
OpenSSL::HMAC::digest(
|
70
|
+
OpenSSL::Digest::SHA1.new,
|
71
|
+
secret_key,
|
72
|
+
signature_seed
|
73
|
+
)
|
74
|
+
).chomp
|
75
|
+
end
|
76
|
+
|
77
|
+
def signature_seed
|
78
|
+
sorted_parameters =
|
79
|
+
escaped_parameters_without_signature.to_a.sort do |a, b|
|
80
|
+
a[0].to_s <=> b[0].to_s
|
81
|
+
end
|
82
|
+
sorted_parameters.map { |param| param.join("=") }.join("&").downcase
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Ocs
|
2
|
+
module Resources
|
3
|
+
autoload :Account, "ocs/resources/account"
|
4
|
+
autoload :Address, "ocs/resources/address"
|
5
|
+
autoload :AffinityGroup, "ocs/resources/affinity_group"
|
6
|
+
autoload :AsyncJob, "ocs/resources/async_job"
|
7
|
+
autoload :Base, "ocs/resources/base"
|
8
|
+
autoload :DiskOffering, "ocs/resources/disk_offering"
|
9
|
+
autoload :Domain, "ocs/resources/domain"
|
10
|
+
autoload :Group, "ocs/resources/group"
|
11
|
+
autoload :Host, "ocs/resources/host"
|
12
|
+
autoload :Iso, "ocs/resources/iso"
|
13
|
+
autoload :Nic, "ocs/resources/nic"
|
14
|
+
autoload :OsType, "ocs/resources/os_type"
|
15
|
+
autoload :ResourceDetail, "ocs/resources/resource_detail"
|
16
|
+
autoload :SecurityGroup, "ocs/resources/security_group"
|
17
|
+
autoload :ServiceOffering, "ocs/resources/service_offering"
|
18
|
+
autoload :SshKeyPair, "ocs/resources/ssh_key_pair"
|
19
|
+
autoload :Tag, "ocs/resources/tag"
|
20
|
+
autoload :Template, "ocs/resources/template"
|
21
|
+
autoload :VirtualMachine, "ocs/resources/virtual_machine"
|
22
|
+
autoload :Zone, "ocs/resources/zone"
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
module Ocs
|
2
|
+
module Resources
|
3
|
+
class AttributeTypeError < OcsError; end
|
4
|
+
class AttributeClassError < OcsError; end
|
5
|
+
class MissingKeyError < OcsError; end
|
6
|
+
|
7
|
+
class Base
|
8
|
+
BOOLEAN = [TrueClass, FalseClass].freeze
|
9
|
+
|
10
|
+
class_attribute :delegations, instance_writer: false
|
11
|
+
self.delegations = {}
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def all(client)
|
15
|
+
list(client)
|
16
|
+
end
|
17
|
+
|
18
|
+
def downcased_name
|
19
|
+
name.downcase
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
to_s.split(/::/).last
|
24
|
+
end
|
25
|
+
|
26
|
+
def pluralized_name
|
27
|
+
name.pluralize
|
28
|
+
end
|
29
|
+
|
30
|
+
def underscored_name
|
31
|
+
name.underscore
|
32
|
+
end
|
33
|
+
|
34
|
+
def list(client, parameters = {})
|
35
|
+
client.call("list#{pluralized_name}", parameters)[downcased_name].map do |attributes|
|
36
|
+
new(client, attributes)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def where(client, conditions = {}, parameters = {})
|
41
|
+
list(client, parameters).select do |instance|
|
42
|
+
conditions.all? do |attribute, condition|
|
43
|
+
value = instance.public_send(attribute)
|
44
|
+
case condition
|
45
|
+
when Regexp
|
46
|
+
condition =~ value
|
47
|
+
when Range
|
48
|
+
condition.include?(value)
|
49
|
+
else
|
50
|
+
condition == value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Dynamic Definitions
|
57
|
+
|
58
|
+
def alias_attribute(new_name, original_name)
|
59
|
+
alias_method new_name, original_name
|
60
|
+
alias_method :"#{new_name}=", :"#{original_name}="
|
61
|
+
end
|
62
|
+
|
63
|
+
def define_action(action_name, required: [], optional: [], api_name: nil)
|
64
|
+
define_method(action_name) do
|
65
|
+
api = api_name || "#{action_name}#{self.class.name}"
|
66
|
+
parameters = action_parameters(required, optional)
|
67
|
+
client.call(api, parameters)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def define_attribute(attribute_name, type:)
|
72
|
+
define_method(:"#{attribute_name}=") do |value|
|
73
|
+
unless [*type].any? { |type| value.is_a?(type) }
|
74
|
+
raise AttributeTypeError.new(
|
75
|
+
"#{attribute_name} needs to be a #{[*type].join(" or ")}"
|
76
|
+
)
|
77
|
+
end
|
78
|
+
instance_variable_set(:"@#{attribute_name}", value)
|
79
|
+
end
|
80
|
+
|
81
|
+
attr_reader attribute_name
|
82
|
+
end
|
83
|
+
|
84
|
+
def delegate_attribute(attribute_name, to:, as:)
|
85
|
+
writer_method_name = :"#{to}_#{as}="
|
86
|
+
define_method(writer_method_name) do |value|
|
87
|
+
instance =
|
88
|
+
public_send(to) ||
|
89
|
+
public_send(:"#{to}=", resource_class(to).new(client))
|
90
|
+
instance.public_send(:"#{as}=", value)
|
91
|
+
end
|
92
|
+
delegations[attribute_name] = writer_method_name
|
93
|
+
|
94
|
+
define_method(:"#{to}_#{as}") do
|
95
|
+
instance = public_send(to)
|
96
|
+
instance && instance.public_send(as)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def delegate_attributes(attribute_name, to:)
|
101
|
+
delegations[attribute_name] = :"#{to}="
|
102
|
+
end
|
103
|
+
|
104
|
+
def has_one(attribute_name)
|
105
|
+
define_method(:"#{attribute_name}=") do |value|
|
106
|
+
klass = resource_class(attribute_name)
|
107
|
+
unless value.instance_of?(klass)
|
108
|
+
raise AttributeClassError.new(
|
109
|
+
"#{attribute_name} needs to be an instance of #{klass}"
|
110
|
+
)
|
111
|
+
end
|
112
|
+
instance_variable_set(:"@#{attribute_name}", value)
|
113
|
+
end
|
114
|
+
|
115
|
+
attr_reader attribute_name
|
116
|
+
end
|
117
|
+
|
118
|
+
def has_many(attribute_name)
|
119
|
+
define_method(:"#{attribute_name}=") do |values|
|
120
|
+
unless values.is_a?(Array)
|
121
|
+
raise AttributeTypeError.new("#{attribute_name} needs to be a Array")
|
122
|
+
end
|
123
|
+
|
124
|
+
klass = resource_class(attribute_name.to_s.singularize)
|
125
|
+
instances = values.map do |value|
|
126
|
+
case value
|
127
|
+
when klass
|
128
|
+
value
|
129
|
+
when Hash
|
130
|
+
klass.new(client, value)
|
131
|
+
else
|
132
|
+
raise AttributeClassError.new(
|
133
|
+
"elements of #{attribute_name} need to be instances of #{klass}"
|
134
|
+
)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
instance_variable_set(:"@#{attribute_name}", instances)
|
138
|
+
end
|
139
|
+
|
140
|
+
attr_reader attribute_name
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
define_attribute :id, type: String
|
145
|
+
|
146
|
+
attr_reader :client
|
147
|
+
|
148
|
+
def initialize(client, raw_hash = {})
|
149
|
+
@client = client
|
150
|
+
@raw_hash = raw_hash
|
151
|
+
update_attributes(raw_hash)
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def action_parameters(required_keys, optional_keys)
|
157
|
+
check_required_keys(required_keys)
|
158
|
+
parameters(required_keys + optional_keys)
|
159
|
+
end
|
160
|
+
|
161
|
+
def check_required_keys(required_keys)
|
162
|
+
required_keys.each do |key|
|
163
|
+
raise MissingKeyError.new("#{key} key is required") if public_send(key).nil?
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def parameters(keys)
|
168
|
+
keys.inject({}) do |params, key|
|
169
|
+
value = public_send(key)
|
170
|
+
params[key.to_s.delete("_")] = value if value
|
171
|
+
params
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def resource_class(class_name)
|
176
|
+
"ocs/resources/#{class_name}".camelize.constantize
|
177
|
+
end
|
178
|
+
|
179
|
+
def update_attributes(hash)
|
180
|
+
hash.each do |key, value|
|
181
|
+
if delegations.has_key?(key.to_sym)
|
182
|
+
public_send(delegations[key.to_sym], value)
|
183
|
+
else
|
184
|
+
public_send(:"#{key}=", value)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Ocs
|
2
|
+
module Resources
|
3
|
+
class Nic < Base
|
4
|
+
define_attribute :broadcasturi, type: String
|
5
|
+
define_attribute :gateway, type: String
|
6
|
+
define_attribute :ipaddress, type: String
|
7
|
+
define_attribute :isdefault, type: [TrueClass, FalseClass]
|
8
|
+
define_attribute :isolationuri, type: String
|
9
|
+
define_attribute :macaddress, type: String
|
10
|
+
define_attribute :netmask, type: String
|
11
|
+
define_attribute :networkid, type: String
|
12
|
+
define_attribute :networkname, type: String
|
13
|
+
define_attribute :traffictype, type: String
|
14
|
+
define_attribute :type, type: String
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Ocs
|
2
|
+
module Resources
|
3
|
+
class ServiceOffering < Base
|
4
|
+
has_one :domain
|
5
|
+
|
6
|
+
define_attribute :cpunumber, type: Integer
|
7
|
+
define_attribute :cpuspeed, type: Integer
|
8
|
+
define_attribute :created, type: String
|
9
|
+
define_attribute :defaultuse, type: BOOLEAN
|
10
|
+
define_attribute :deploymentplanner, type: String
|
11
|
+
define_attribute :diskBytesReadRate, type: Integer
|
12
|
+
define_attribute :diskBytesWriteRate, type: Integer
|
13
|
+
define_attribute :diskIopsReadRate, type: Integer
|
14
|
+
define_attribute :diskIopsWriteRate, type: Integer
|
15
|
+
define_attribute :displaytext, type: String
|
16
|
+
define_attribute :hosttags, type: String
|
17
|
+
define_attribute :iscustomized, type: BOOLEAN
|
18
|
+
define_attribute :issystem, type: BOOLEAN
|
19
|
+
define_attribute :isvolatile, type: BOOLEAN
|
20
|
+
define_attribute :limitcpuuse, type: BOOLEAN
|
21
|
+
define_attribute :memory, type: Integer
|
22
|
+
define_attribute :name, type: String
|
23
|
+
define_attribute :networkrate, type: Integer
|
24
|
+
define_attribute :offerha, type: BOOLEAN
|
25
|
+
define_attribute :serviceofferingdetails, type: Hash
|
26
|
+
define_attribute :storagetype, type: String
|
27
|
+
define_attribute :systemvmtype, type: String
|
28
|
+
define_attribute :tags, type: String
|
29
|
+
|
30
|
+
delegate_attribute :domain, to: :domain, as: :name
|
31
|
+
delegate_attribute :domainid, to: :domain, as: :id
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Ocs
|
2
|
+
module Resources
|
3
|
+
class Tag < Base
|
4
|
+
has_one :account
|
5
|
+
has_one :domain
|
6
|
+
has_one :project
|
7
|
+
has_one :resource_detail
|
8
|
+
|
9
|
+
define_attribute :key, type: String
|
10
|
+
define_attribute :value, type: String
|
11
|
+
define_attribute :resourcetype, type: String
|
12
|
+
|
13
|
+
delegate_attribute :acount, to: :account, as: :name
|
14
|
+
delegate_attribute :domain, to: :domain, as: :name
|
15
|
+
delegate_attribute :domainid, to: :domain, as: :id
|
16
|
+
delegate_attribute :project, to: :project, as: :id
|
17
|
+
delegate_attribute :projectid, to: :project, as: :id
|
18
|
+
delegate_attribute :resourceid, to: :resource_detail, as: :id
|
19
|
+
delegate_attribute :resourcetype, to: :resource_detail, as: :type
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Ocs
|
2
|
+
module Resources
|
3
|
+
class Template < Base
|
4
|
+
has_one :account
|
5
|
+
has_one :domain
|
6
|
+
has_one :host
|
7
|
+
has_one :os_type
|
8
|
+
has_one :project
|
9
|
+
has_one :template
|
10
|
+
has_one :zone
|
11
|
+
|
12
|
+
has_many :tags
|
13
|
+
|
14
|
+
define_attribute :bootable, type: BOOLEAN
|
15
|
+
define_attribute :checksum, type: String
|
16
|
+
define_attribute :created, type: String
|
17
|
+
define_attribute :crossZones, type: BOOLEAN
|
18
|
+
define_attribute :details, type: Hash
|
19
|
+
define_attribute :displaytext, type: String
|
20
|
+
define_attribute :format, type: String
|
21
|
+
define_attribute :hypervisor, type: String
|
22
|
+
define_attribute :isdynamicallyscalable, type: BOOLEAN
|
23
|
+
define_attribute :isextractable, type: BOOLEAN
|
24
|
+
define_attribute :isfeatured, type: BOOLEAN
|
25
|
+
define_attribute :ispublic, type: BOOLEAN
|
26
|
+
define_attribute :isready, type: BOOLEAN
|
27
|
+
define_attribute :name, type: String
|
28
|
+
define_attribute :passwordenabled, type: BOOLEAN
|
29
|
+
define_attribute :removed, type: BOOLEAN
|
30
|
+
define_attribute :size, type: Integer
|
31
|
+
define_attribute :sshkeyenabled, type: BOOLEAN
|
32
|
+
define_attribute :status, type: String
|
33
|
+
define_attribute :templatetag, type: String
|
34
|
+
define_attribute :templatetype, type: String
|
35
|
+
|
36
|
+
delegate_attribute :account, to: :account, as: :name
|
37
|
+
delegate_attribute :accountid, to: :account, as: :id
|
38
|
+
delegate_attribute :domain, to: :domain, as: :name
|
39
|
+
delegate_attribute :domainid, to: :domain, as: :id
|
40
|
+
delegate_attribute :hostid, to: :host, as: :id
|
41
|
+
delegate_attribute :hostname, to: :host, as: :name
|
42
|
+
delegate_attribute :ostypeid, to: :os_type, as: :id
|
43
|
+
delegate_attribute :ostypename, to: :os_type, as: :name
|
44
|
+
delegate_attribute :project, to: :project, as: :name
|
45
|
+
delegate_attribute :projectid, to: :project, as: :id
|
46
|
+
delegate_attribute :sourcetemplateid, to: :template, as: :id
|
47
|
+
delegate_attribute :zoneid, to: :zone, as: :id
|
48
|
+
delegate_attribute :zonename, to: :zone, as: :name
|
49
|
+
|
50
|
+
delegate_attributes :tags, to: :tags
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Ocs
|
2
|
+
module Resources
|
3
|
+
class VirtualMachine < Base
|
4
|
+
has_one :account
|
5
|
+
has_one :address
|
6
|
+
has_one :disk_offering
|
7
|
+
has_one :domain
|
8
|
+
has_one :group
|
9
|
+
has_one :host
|
10
|
+
has_one :iso
|
11
|
+
has_one :os_type
|
12
|
+
has_one :project
|
13
|
+
has_one :service_offering
|
14
|
+
has_one :template
|
15
|
+
has_one :ssh_key_pair
|
16
|
+
has_one :zone
|
17
|
+
|
18
|
+
has_many :affinity_groups
|
19
|
+
has_many :nics
|
20
|
+
has_many :security_groups
|
21
|
+
has_many :tags
|
22
|
+
|
23
|
+
define_attribute :cpunumber, type: Integer
|
24
|
+
define_attribute :cpuspeed, type: Integer
|
25
|
+
define_attribute :cpuused, type: String
|
26
|
+
define_attribute :created, type: String
|
27
|
+
#define_attribute :details
|
28
|
+
#define_attribute :diskioread
|
29
|
+
#define_attribute :diskiowrite
|
30
|
+
#define_attribute :diskkbsread
|
31
|
+
#define_attribute :diskkbswrite
|
32
|
+
define_attribute :displayname, type: String
|
33
|
+
define_attribute :displayvm, type: BOOLEAN
|
34
|
+
#define_attribute :forvirtualnetwork
|
35
|
+
define_attribute :haenable, type: BOOLEAN
|
36
|
+
define_attribute :hypervisor, type: String
|
37
|
+
#define_attribute :instancename
|
38
|
+
define_attribute :isdynamicallyscalable, type: BOOLEAN
|
39
|
+
define_attribute :memory, type: Integer
|
40
|
+
define_attribute :name, type: String
|
41
|
+
define_attribute :networkkbsread, type: Integer
|
42
|
+
define_attribute :networkkbswrite, type: Integer
|
43
|
+
#define_attribute :password
|
44
|
+
define_attribute :passwordenabled, type: BOOLEAN
|
45
|
+
define_attribute :rootdeviceid, type: Integer
|
46
|
+
define_attribute :rootdevicetype, type: String
|
47
|
+
#define_attribute :servicestate
|
48
|
+
define_attribute :state, type: String
|
49
|
+
#define_attribute :vgpu
|
50
|
+
|
51
|
+
delegate_attribute :account, to: :account, as: :name
|
52
|
+
delegate_attribute :diskofferingid, to: :disk_offering, as: :id
|
53
|
+
delegate_attribute :diskofferingname, to: :disk_offering, as: :name
|
54
|
+
delegate_attribute :domain, to: :domain, as: :name
|
55
|
+
delegate_attribute :domainid, to: :domain, as: :id
|
56
|
+
delegate_attribute :group, to: :group, as: :name
|
57
|
+
delegate_attribute :groupid, to: :group, as: :id
|
58
|
+
delegate_attribute :guestosid, to: :os_type, as: :id
|
59
|
+
delegate_attribute :hostid, to: :host, as: :id
|
60
|
+
delegate_attribute :hostname, to: :host, as: :name
|
61
|
+
delegate_attribute :isodisplaytext, to: :iso, as: :displaytext
|
62
|
+
delegate_attribute :isoid, to: :iso, as: :id
|
63
|
+
delegate_attribute :isoname, to: :iso, as: :name
|
64
|
+
delegate_attribute :jobid, to: :async_job, as: :jobid
|
65
|
+
delegate_attribute :jobstatus, to: :async_job, as: :jobstatus
|
66
|
+
delegate_attribute :keypair, to: :ssh_key_pair, as: :name
|
67
|
+
delegate_attribute :ostypeid, to: :os_type, as: :id
|
68
|
+
#delegate_attribute :project, to: :project, as: :name
|
69
|
+
#delegate_attribute :projectid, to: :project, as: :id
|
70
|
+
delegate_attribute :publicip, to: :address, as: :id
|
71
|
+
delegate_attribute :publicipid, to: :address, as: :id
|
72
|
+
delegate_attribute :serviceofferingid, to: :service_offering, as: :id
|
73
|
+
delegate_attribute :serviceofferingname, to: :service_offering, as: :name
|
74
|
+
delegate_attribute :templatedisplaytext, to: :template, as: :displaytext
|
75
|
+
delegate_attribute :templateid, to: :template, as: :id
|
76
|
+
delegate_attribute :templatename, to: :template, as: :name
|
77
|
+
delegate_attribute :zoneid, to: :zone, as: :id
|
78
|
+
delegate_attribute :zonename, to: :zone, as: :name
|
79
|
+
|
80
|
+
delegate_attributes :affinitygroup, to: :affinity_groups
|
81
|
+
delegate_attributes :nic, to: :nics
|
82
|
+
delegate_attributes :securitygroup, to: :security_groups
|
83
|
+
delegate_attributes :tags, to: :tags
|
84
|
+
|
85
|
+
define_action :deploy,
|
86
|
+
required: %i(service_offering_id template_id zone_id),
|
87
|
+
optional: %i(displayname group_name name)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Ocs
|
2
|
+
module Resources
|
3
|
+
class Zone < Base
|
4
|
+
has_one :domain
|
5
|
+
|
6
|
+
has_many :tags
|
7
|
+
|
8
|
+
define_attribute :allocationstate, type: String
|
9
|
+
define_attribute :capacity, type: Hash
|
10
|
+
define_attribute :description, type: String
|
11
|
+
define_attribute :dhcpprovider, type: String
|
12
|
+
define_attribute :displaytext, type: String
|
13
|
+
define_attribute :dns1, type: String
|
14
|
+
define_attribute :dns2, type: String
|
15
|
+
define_attribute :guestcidraddress, type: String
|
16
|
+
define_attribute :internaldns1, type: String
|
17
|
+
define_attribute :internaldns2, type: String
|
18
|
+
define_attribute :ip6dns1, type: String
|
19
|
+
define_attribute :ip6dns2, type: String
|
20
|
+
define_attribute :localstorageenabled, type: BOOLEAN
|
21
|
+
define_attribute :name, type: String
|
22
|
+
define_attribute :networktype, type: String
|
23
|
+
define_attribute :resourcedetails, type: Hash
|
24
|
+
define_attribute :securitygroupsenabled, type: BOOLEAN
|
25
|
+
define_attribute :vlan, type: String
|
26
|
+
define_attribute :zonetoken, type: String
|
27
|
+
|
28
|
+
delegate_attribute :domain, to: :domain, as: :name
|
29
|
+
delegate_attribute :domainid, to: :domain, as: :id
|
30
|
+
|
31
|
+
delegate_attributes :tags, to: :tags
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/ocs/response.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Ocs
|
2
|
+
class Response
|
3
|
+
def initialize(faraday_response)
|
4
|
+
@raw_body = faraday_response.body
|
5
|
+
@raw_headers = faraday_response.headers
|
6
|
+
@raw_status = faraday_response.status
|
7
|
+
end
|
8
|
+
|
9
|
+
def body
|
10
|
+
@body ||= @raw_body.with_indifferent_access
|
11
|
+
end
|
12
|
+
|
13
|
+
def status
|
14
|
+
@raw_status
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/ocs/version.rb
ADDED
data/ocs.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ocs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ocs"
|
8
|
+
spec.version = Ocs::VERSION
|
9
|
+
spec.authors = ["nownabe"]
|
10
|
+
spec.email = ["nownabe@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ocs is an objective CloudStack API client.}
|
13
|
+
spec.homepage = "https://github.com/nownabe/ocs"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport"
|
22
|
+
spec.add_dependency "faraday"
|
23
|
+
spec.add_dependency "faraday_middleware"
|
24
|
+
spec.add_dependency "memoist"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "pry"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ocs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nownabe
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: memoist
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.9'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- nownabe@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/console
|
126
|
+
- bin/setup
|
127
|
+
- lib/ocs.rb
|
128
|
+
- lib/ocs/client.rb
|
129
|
+
- lib/ocs/request.rb
|
130
|
+
- lib/ocs/resources.rb
|
131
|
+
- lib/ocs/resources/account.rb
|
132
|
+
- lib/ocs/resources/address.rb
|
133
|
+
- lib/ocs/resources/affinity_group.rb
|
134
|
+
- lib/ocs/resources/async_job.rb
|
135
|
+
- lib/ocs/resources/base.rb
|
136
|
+
- lib/ocs/resources/disk_offering.rb
|
137
|
+
- lib/ocs/resources/domain.rb
|
138
|
+
- lib/ocs/resources/group.rb
|
139
|
+
- lib/ocs/resources/host.rb
|
140
|
+
- lib/ocs/resources/iso.rb
|
141
|
+
- lib/ocs/resources/nic.rb
|
142
|
+
- lib/ocs/resources/os_type.rb
|
143
|
+
- lib/ocs/resources/security_group.rb
|
144
|
+
- lib/ocs/resources/service_offering.rb
|
145
|
+
- lib/ocs/resources/ssh_key_pair.rb
|
146
|
+
- lib/ocs/resources/tag.rb
|
147
|
+
- lib/ocs/resources/template.rb
|
148
|
+
- lib/ocs/resources/virtual_machine.rb
|
149
|
+
- lib/ocs/resources/zone.rb
|
150
|
+
- lib/ocs/response.rb
|
151
|
+
- lib/ocs/version.rb
|
152
|
+
- ocs.gemspec
|
153
|
+
homepage: https://github.com/nownabe/ocs
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.4.5
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: Ocs is an objective CloudStack API client.
|
177
|
+
test_files: []
|