clink_cloud 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +11 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/clink_cloud.gemspec +31 -0
- data/lib/clink_cloud.rb +43 -0
- data/lib/clink_cloud/client.rb +95 -0
- data/lib/clink_cloud/errors.rb +6 -0
- data/lib/clink_cloud/mappings/data_center_mapping.rb +13 -0
- data/lib/clink_cloud/mappings/firewall_policy_mapping.rb +18 -0
- data/lib/clink_cloud/mappings/group_mapping.rb +21 -0
- data/lib/clink_cloud/mappings/network_mapping.rb +19 -0
- data/lib/clink_cloud/mappings/operation_mapping.rb +14 -0
- data/lib/clink_cloud/mappings/server_mapping.rb +26 -0
- data/lib/clink_cloud/models/base.rb +11 -0
- data/lib/clink_cloud/models/data_center.rb +15 -0
- data/lib/clink_cloud/models/firewall_policy.rb +11 -0
- data/lib/clink_cloud/models/group.rb +38 -0
- data/lib/clink_cloud/models/ip_address.rb +7 -0
- data/lib/clink_cloud/models/network.rb +12 -0
- data/lib/clink_cloud/models/operation.rb +7 -0
- data/lib/clink_cloud/models/server.rb +21 -0
- data/lib/clink_cloud/models/status.rb +5 -0
- data/lib/clink_cloud/resources/base_resource.rb +20 -0
- data/lib/clink_cloud/resources/data_center_resource.rb +43 -0
- data/lib/clink_cloud/resources/firewall_policy_resource.rb +4 -0
- data/lib/clink_cloud/resources/group_resource.rb +43 -0
- data/lib/clink_cloud/resources/ip_address_resource.rb +34 -0
- data/lib/clink_cloud/resources/network_resource.rb +41 -0
- data/lib/clink_cloud/resources/operation_resource.rb +21 -0
- data/lib/clink_cloud/resources/server_resource.rb +73 -0
- data/lib/clink_cloud/resources/status_resource.rb +18 -0
- data/lib/clink_cloud/version.rb +3 -0
- metadata +195 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3da130670377734428bd37ae8421cf3a47ec0c0a
|
4
|
+
data.tar.gz: c38dcfd5a4aec32514d853da127655968a01d1e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 231c42f5bc0d303a88bd6dbb00e421b082da1ab709636040b18b33acb6bf9eac282fe471d126f35c7dec0b8636c8c3cce916607aa75118b0fca66a355815b044
|
7
|
+
data.tar.gz: ba8cff1bf4fcc1092e64e2fc846b0a579ce41e68bc27d38cf819d47dbbd65918eea6a793835138b2653cf5bb82e7a948abf5e5405a7ccb183df0b070c50b0cb6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Connor Atherton
|
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,11 @@
|
|
1
|
+
# ClinkCloud
|
2
|
+
|
3
|
+
A ruby client for the CenturyLink cloud API.
|
4
|
+
|
5
|
+
## Contributing
|
6
|
+
|
7
|
+
1. Fork it ( https://github.com/[my-github-username]/clink_cloud/fork )
|
8
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
9
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
10
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
11
|
+
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 "clink_cloud"
|
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/clink_cloud.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'clink_cloud/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "clink_cloud"
|
8
|
+
spec.version = ClinkCloud::VERSION
|
9
|
+
spec.authors = ["Connor Atherton"]
|
10
|
+
spec.email = ["c.liam.atherton@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{CenturyLink cloud client library.}
|
13
|
+
spec.description = %q{CenturyLink cloud client library.}
|
14
|
+
spec.homepage = "https://github.com/ConnorAtherton/clink_cloud"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
|
26
|
+
spec.add_dependency "faraday"
|
27
|
+
spec.add_dependency "faraday_middleware"
|
28
|
+
spec.add_dependency 'kartograph'
|
29
|
+
spec.add_dependency 'virtus'
|
30
|
+
spec.add_dependency 'resource_kit'
|
31
|
+
end
|
data/lib/clink_cloud.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'clink_cloud/version'
|
2
|
+
require 'kartograph'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Autload each module/class only
|
6
|
+
# when they are accessed. The resources are
|
7
|
+
# the most commonly used entity and are
|
8
|
+
# exposed through method_missing in the client
|
9
|
+
# class.
|
10
|
+
#
|
11
|
+
module ClinkCloud
|
12
|
+
# client
|
13
|
+
autoload :Client, 'clink_cloud/client'
|
14
|
+
|
15
|
+
# models
|
16
|
+
autoload :Base, 'clink_cloud/models/base'
|
17
|
+
autoload :Server, 'clink_cloud/models/server'
|
18
|
+
autoload :DataCenter, 'clink_cloud/models/data_center'
|
19
|
+
autoload :Group, 'clink_cloud/models/group'
|
20
|
+
autoload :IpAddress, 'clink_cloud/models/ip_address'
|
21
|
+
autoload :Network, 'clink_cloud/models/network'
|
22
|
+
autoload :Operation, 'clink_cloud/models/operation'
|
23
|
+
autoload :Status, 'clink_cloud/models/status'
|
24
|
+
|
25
|
+
# mappings
|
26
|
+
autoload :ServerMapping, 'clink_cloud/mappings/server_mapping'
|
27
|
+
autoload :NetworkMapping, 'clink_cloud/mappings/network_mapping'
|
28
|
+
autoload :GroupMapping, 'clink_cloud/mappings/group_mapping'
|
29
|
+
autoload :DataCenterMapping, 'clink_cloud/mappings/data_center_mapping'
|
30
|
+
autoload :OperationMapping, 'clink_cloud/mappings/operation_mapping'
|
31
|
+
autoload :FirewallPolicyMapping, 'clink_cloud/mappings/firewall_policy_mapping'
|
32
|
+
|
33
|
+
# resources
|
34
|
+
autoload :BaseResource, 'clink_cloud/resources/base_resource'
|
35
|
+
autoload :ServerResource, 'clink_cloud/resources/server_resource'
|
36
|
+
autoload :DataCenterResource, 'clink_cloud/resources/data_center_resource'
|
37
|
+
autoload :FirewallPolicyResource, 'clink_cloud/resources/firewall_policy_resource'
|
38
|
+
autoload :IpAddressResource, 'clink_cloud/resources/ip_address_resource'
|
39
|
+
autoload :NetworkResource, 'clink_cloud/resources/network_resource'
|
40
|
+
autoload :GroupResource, 'clink_cloud/resources/group_resource'
|
41
|
+
autoload :OperationResource, 'clink_cloud/resources/operation_resource'
|
42
|
+
autoload :StatusResource, 'clink_cloud/resources/status_resource'
|
43
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'pry'
|
4
|
+
require 'clink_cloud/errors'
|
5
|
+
|
6
|
+
module ClinkCloud
|
7
|
+
class Client
|
8
|
+
API_VERSION = 'v2'
|
9
|
+
API_URL = 'https://api.ctl.io'
|
10
|
+
|
11
|
+
attr_reader :auth_token, :alias, :roles, :primary_location
|
12
|
+
|
13
|
+
def initialize(options)
|
14
|
+
@username = options[:username]
|
15
|
+
@password = options[:password]
|
16
|
+
|
17
|
+
authenticate unless auth_token
|
18
|
+
end
|
19
|
+
|
20
|
+
def connection
|
21
|
+
Faraday.new(connection_options) do |faraday|
|
22
|
+
# json encode both requests and responses
|
23
|
+
faraday.response :json, content_type: 'application/json'
|
24
|
+
faraday.request :json
|
25
|
+
faraday.adapter :net_http
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# This is used to lazy-load resources.
|
30
|
+
# It is stored in the @resources instance
|
31
|
+
# variable when a caller requests the resource.
|
32
|
+
def self.resources
|
33
|
+
{
|
34
|
+
servers: ServerResource,
|
35
|
+
data_centers: DataCenterResource,
|
36
|
+
firewall_policies: FirewallPolicyResource,
|
37
|
+
networks: NetworkResource,
|
38
|
+
operations: OperationResource,
|
39
|
+
statuses: StatusResource,
|
40
|
+
groups: GroupResource,
|
41
|
+
ip_addresses: IpAddressResource
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def resources
|
46
|
+
@resources ||= {}
|
47
|
+
end
|
48
|
+
|
49
|
+
# This attaches resources to the client
|
50
|
+
# Resources map to a specific model
|
51
|
+
def method_missing(name, *args, &block)
|
52
|
+
if self.class.resources.keys.include?(name)
|
53
|
+
unless auth_token
|
54
|
+
raise 'Authenticate before using these methods'
|
55
|
+
end
|
56
|
+
|
57
|
+
resources[name] ||= self.class.resources[name].new(connection: connection,
|
58
|
+
scope: self)
|
59
|
+
resources[name]
|
60
|
+
else
|
61
|
+
super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def authenticate
|
66
|
+
res = connection.post(
|
67
|
+
"/#{API_VERSION}/authentication/login", username: @username, password: @password
|
68
|
+
)
|
69
|
+
|
70
|
+
raise ClinkCloud::Errors::AuthenticationError unless res.success?
|
71
|
+
|
72
|
+
# also set the alias for later on
|
73
|
+
@auth_token = res.body['bearerToken']
|
74
|
+
@alias = res.body['accountAlias']
|
75
|
+
@roles = res.body['roles']
|
76
|
+
@primary_location = res.body['locationAlias']
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def connection_options
|
82
|
+
conn = {
|
83
|
+
url: API_URL,
|
84
|
+
headers: {
|
85
|
+
content_type: 'application/json',
|
86
|
+
accepts: 'application/json'
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
conn[:headers][:authorization] = "Bearer #{auth_token}" if auth_token
|
91
|
+
|
92
|
+
conn
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class FirewallPolicyMapping
|
3
|
+
include Kartograph::DSL
|
4
|
+
|
5
|
+
kartograph do
|
6
|
+
mapping FirewallPolicy
|
7
|
+
|
8
|
+
property :id, scopes: [:read]
|
9
|
+
property :status, scopes: [:read]
|
10
|
+
property :enabled, scopes: [:read]
|
11
|
+
property :source, scopes: [:read]
|
12
|
+
property :destination, scopes: [:read]
|
13
|
+
property :destinationAccount, scopes: [:read]
|
14
|
+
property :ports, scopes: [:read]
|
15
|
+
property :links, scopes: [:read]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class GroupMapping
|
3
|
+
include Kartograph::DSL
|
4
|
+
|
5
|
+
kartograph do
|
6
|
+
mapping Group
|
7
|
+
|
8
|
+
property :id, scopes: [:read]
|
9
|
+
property :name, scopes: [:read]
|
10
|
+
property :description, scopes: [:read]
|
11
|
+
property :locationId, scopes: [:read]
|
12
|
+
property :type, scopes: [:read]
|
13
|
+
property :status, scopes: [:read]
|
14
|
+
property :serversCount, scopes: [:read]
|
15
|
+
property :groups, scopes: [:read]
|
16
|
+
property :changeInfo, scopes: [:read]
|
17
|
+
property :customFields, scopes: [:read]
|
18
|
+
property :links, scopes: [:read]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class NetworkMapping
|
3
|
+
include Kartograph::DSL
|
4
|
+
|
5
|
+
kartograph do
|
6
|
+
mapping Network
|
7
|
+
|
8
|
+
property :id, scopes: [:read]
|
9
|
+
property :name, scopes: [:read]
|
10
|
+
property :cidr, scopes: [:read]
|
11
|
+
property :description, scopes: [:read]
|
12
|
+
property :gateway, scopes: [:read]
|
13
|
+
property :netmask, scopes: [:read]
|
14
|
+
property :type, scopes: [:read]
|
15
|
+
property :vlan, scopes: [:read]
|
16
|
+
property :links, scopes: [:read]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class OperationMapping
|
3
|
+
include Kartograph::DSL
|
4
|
+
|
5
|
+
kartograph do
|
6
|
+
mapping Operation
|
7
|
+
|
8
|
+
property :id, scopes: [:read]
|
9
|
+
property :isQueued, scopes: [:read]
|
10
|
+
property :errorMessage, scopes: [:read]
|
11
|
+
property :links, scopes: [:read]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class ServerMapping
|
3
|
+
include Kartograph::DSL
|
4
|
+
|
5
|
+
kartograph do
|
6
|
+
mapping Server
|
7
|
+
|
8
|
+
property :id, scopes: [:read]
|
9
|
+
property :name, scopes: [:read, :create]
|
10
|
+
property :description, scopes: [:read, :create]
|
11
|
+
property :groupId, scopes: [:read, :create]
|
12
|
+
property :isTemplate, scopes: [:read]
|
13
|
+
property :locationId, scopes: [:read]
|
14
|
+
property :osType, scopes: [:read]
|
15
|
+
property :status, scopes: [:read]
|
16
|
+
property :details, scopes: [:read]
|
17
|
+
property :type, scopes: [:read, :create]
|
18
|
+
property :storageType, scopes: [:read]
|
19
|
+
property :changeInfo, scopes: [:read]
|
20
|
+
property :links, scopes: [:read]
|
21
|
+
property :memoryGB, scopes: [:create]
|
22
|
+
property :cpu, scopes: [:create]
|
23
|
+
property :sourceServerId, scopes: [:create]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class DataCenter < Base
|
3
|
+
attribute :id
|
4
|
+
attribute :name
|
5
|
+
|
6
|
+
def group_id
|
7
|
+
@group_id ||= links.select { |l| true if l['rel'] == 'group' }.first['id']
|
8
|
+
rescue
|
9
|
+
# This happends when accessing group_id on an object
|
10
|
+
# sculpted from within a collection. Need to use .find to
|
11
|
+
# get more links
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class Group < Base
|
3
|
+
attribute :id
|
4
|
+
attribute :name
|
5
|
+
attribute :description
|
6
|
+
attribute :locationId
|
7
|
+
attribute :type
|
8
|
+
attribute :status
|
9
|
+
attribute :serversCount
|
10
|
+
attribute :groups
|
11
|
+
attribute :changeInfo
|
12
|
+
attribute :customFields
|
13
|
+
|
14
|
+
def servers(client = nil)
|
15
|
+
links.select { |l| l if l['rel'] == 'server' }
|
16
|
+
.map { |s| s['id'] }
|
17
|
+
.tap do |servers|
|
18
|
+
if client.is_a?(::ClinkCloud::Client)
|
19
|
+
# build an array of server objects
|
20
|
+
return servers.map { |s| client.servers.find(id: s) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
rescue
|
24
|
+
# This happends when accessing group_id on an object
|
25
|
+
# sculpted from within a collection. Need to use .find to
|
26
|
+
# get more links
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
# Accepts the name used to create the vm as well
|
31
|
+
# as the data center id and account alias and tries to find
|
32
|
+
# the server id that matches
|
33
|
+
def find_server_id(name:, dc_id:, account_alias:)
|
34
|
+
regex = /#{dc_id}#{account_alias}#{name}\d{2}/i
|
35
|
+
servers.select { |id| id.match regex }.first
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class Server < Base
|
3
|
+
attribute :id
|
4
|
+
attribute :name
|
5
|
+
attribute :description
|
6
|
+
attribute :groupId
|
7
|
+
attribute :isTemplate
|
8
|
+
attribute :locationId
|
9
|
+
attribute :osType
|
10
|
+
attribute :status
|
11
|
+
attribute :details
|
12
|
+
attribute :type
|
13
|
+
attribute :storageType
|
14
|
+
attribute :changeInfo
|
15
|
+
|
16
|
+
# only on create
|
17
|
+
attribute :memoryGB
|
18
|
+
attribute :cpu
|
19
|
+
attribute :sourceServerId
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'resource_kit'
|
2
|
+
|
3
|
+
module ClinkCloud
|
4
|
+
class BaseResource < ResourceKit::Resource
|
5
|
+
# helpful for century link api because the include
|
6
|
+
# account alias in the url itself
|
7
|
+
def account_alias
|
8
|
+
scope.alias
|
9
|
+
end
|
10
|
+
|
11
|
+
def extract_resources_from_links(links, obj, *keys)
|
12
|
+
links.each do |link|
|
13
|
+
next unless keys.include? link['rel']
|
14
|
+
obj.send "#{link['re']}=", link['id']
|
15
|
+
end
|
16
|
+
|
17
|
+
obj
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class DataCenterResource < BaseResource
|
3
|
+
resources do
|
4
|
+
default_handler do |response|
|
5
|
+
fail "Unexpected response status #{response.status}... #{response.body}"
|
6
|
+
end
|
7
|
+
|
8
|
+
action :all do
|
9
|
+
verb :get
|
10
|
+
path { "/v2/datacenters/#{account_alias}" }
|
11
|
+
handler(200) do |response|
|
12
|
+
DataCenterMapping.extract_collection(response.body.to_json, :read)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
action :find do
|
17
|
+
verb :get
|
18
|
+
path { "/v2/datacenters/#{account_alias}/:id?groupLinks=true" }
|
19
|
+
handler(200) do |response|
|
20
|
+
DataCenterMapping.extract_single(response.body.to_json, :read)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
action :get_deployment_capabilities do
|
25
|
+
verb :get
|
26
|
+
path { "/v2/datacenters/#{account_alias}/:id/deploymentCapabilities" }
|
27
|
+
handler(200) do |response|
|
28
|
+
# just a simple string
|
29
|
+
response.body
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
action :get_bare_deployment_capabilities do
|
34
|
+
verb :get
|
35
|
+
path { "/v2/datacenters/#{account_alias}/:id/bareDeploymentCapabilities" }
|
36
|
+
handler(200) do |response|
|
37
|
+
# just a simple string
|
38
|
+
response.body
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class GroupResource < BaseResource
|
3
|
+
resources do
|
4
|
+
default_handler do |response|
|
5
|
+
fail "Unexpected response status #{response.status}... #{response.body}"
|
6
|
+
end
|
7
|
+
|
8
|
+
action :find do
|
9
|
+
verb :get
|
10
|
+
path { "/v2/groups/#{account_alias}/:id" }
|
11
|
+
handler(200) do |response|
|
12
|
+
GroupMapping.extract_single(response.body.to_json, :read)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
action :defaults do
|
17
|
+
verb :get
|
18
|
+
path { "/v2/groups/#{account_alias}/:id/defaults" }
|
19
|
+
handler(200) do |response|
|
20
|
+
# for now
|
21
|
+
response.body
|
22
|
+
# GroupMapping.extract_single(response.body.to_json, :read)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
action :delete do
|
27
|
+
verb :delete
|
28
|
+
path { "/v2/groups/#{account_alias}/:id" }
|
29
|
+
handler(200) do |response|
|
30
|
+
StatusMapping.extract_single(response.body.to_json, :read)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
action :create do
|
35
|
+
verb :post
|
36
|
+
path { "/v2/groups/#{account_alias}/:id" }
|
37
|
+
handler(200) do |response|
|
38
|
+
GroupMapping.extract_single(response.body.to_json, :read)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class IpAddressResource < BaseResource
|
3
|
+
resources do
|
4
|
+
default_handler do |response|
|
5
|
+
fail "Unexpected response status #{response.status}... #{response.body}"
|
6
|
+
end
|
7
|
+
|
8
|
+
action :update do
|
9
|
+
verb :put
|
10
|
+
path { "/v2/servers/#{account_alias}/:server_id/publicIPAddresses/:id" }
|
11
|
+
body { |object| IpAddressMapping.representation_for(:update, object) }
|
12
|
+
handler(200) do |response|
|
13
|
+
IpAddressMapping.extract_collection(response.body, :read)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
action :find do
|
18
|
+
verb :get
|
19
|
+
path { "/v2/servers/#{account_alias}/:server_id/publicIPAddresses/:id" }
|
20
|
+
handler(200) do |response|
|
21
|
+
IpAddressMapping.extract_collection(response.body, :read)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
action :delete do
|
26
|
+
verb :delete
|
27
|
+
path { "/v2/servers/#{account_alias}/:server_id/publicIPAddresses/:id" }
|
28
|
+
handler(200) do |response|
|
29
|
+
response.body
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class NetworkResource < BaseResource
|
3
|
+
resources do
|
4
|
+
default_handler do |response|
|
5
|
+
fail "Unexpected response status #{response.status}... #{response.body}"
|
6
|
+
end
|
7
|
+
|
8
|
+
action :all do
|
9
|
+
verb :get
|
10
|
+
path { "/v2-experimental/networks/#{account_alias}/:data_center" }
|
11
|
+
handler(200) do |response|
|
12
|
+
NetworkMapping.extract_collection(response.body.to_json, :read)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
action :find do
|
17
|
+
verb :get
|
18
|
+
path { "/v2-experimental/networks/#{account_alias}/:data_center/:id" }
|
19
|
+
handler(200) do |response|
|
20
|
+
NetworkMapping.extract_collection(response.body.to_json, :read)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
action :ip_addresses do
|
25
|
+
verb :get
|
26
|
+
path { "/v2-experimental/networks/#{account_alias}/:data_center/:id/ipAddresses" }
|
27
|
+
handler(200) do |response|
|
28
|
+
NetworkMapping.extract_collection(response.body.to_json, :read)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
action :claim do
|
33
|
+
verb :get
|
34
|
+
path { "/v2-experimental/networks/#{account_alias}/:data_center/claim" }
|
35
|
+
handler(200) do |response|
|
36
|
+
NetworkMapping.extract_single(response.body.to_json, :read)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class OperationResource < BaseResource
|
3
|
+
resources do
|
4
|
+
default_handler do |response|
|
5
|
+
fail "Unexpected response status #{response.status}... #{response.body}"
|
6
|
+
end
|
7
|
+
|
8
|
+
%i(:pause :power_off :power_on :reboot :shutDown).each do |action|
|
9
|
+
action action do
|
10
|
+
verb :post
|
11
|
+
path { "/v2/operations/#{account_alias}/servers/#{action}" }
|
12
|
+
# pass in an array of ids or single id string
|
13
|
+
body { |object| object.is_a?(Array) ? object : [object] }
|
14
|
+
handler(200) do |response|
|
15
|
+
OperationMapping.extract_collection(response.body, :read)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class ServerResource < BaseResource
|
3
|
+
resources do
|
4
|
+
default_handler do |response|
|
5
|
+
binding.pry
|
6
|
+
fail "Unexpected response status #{response.status}... #{response.body}"
|
7
|
+
end
|
8
|
+
|
9
|
+
action :find do
|
10
|
+
verb :get
|
11
|
+
path { "/v2/servers/#{account_alias}/:id" }
|
12
|
+
handler(200) do |response|
|
13
|
+
ServerMapping.extract_single(response.body.to_json, :read)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Requires package ID, currently only available by browsing control and browsing
|
18
|
+
# for the package itself. The UUID parameter is the package ID we need
|
19
|
+
action :execute_package do
|
20
|
+
verb :post
|
21
|
+
path { "/v2/operations/#{account_alias}/servers/executePackage" }
|
22
|
+
body { |object| object }
|
23
|
+
handler(200) do |response|
|
24
|
+
Operation.extract_collection(response.body.to_json, :read)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
action :delete do
|
29
|
+
verb :delete
|
30
|
+
path { "/v2/servers/#{account_alias}/:id" }
|
31
|
+
handler(202) do |response|
|
32
|
+
OperationMapping.extract_single(response.body.to_json, :read)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
action :create do
|
37
|
+
verb :post
|
38
|
+
path { "/v2/servers/#{account_alias}" }
|
39
|
+
body { |object| ServerMapping.representation_for(:create, object) }
|
40
|
+
handler(202) do |response|
|
41
|
+
# easier to just use a hash
|
42
|
+
res = { 'id' => response.body['server'] }
|
43
|
+
map = { 'status' => 'status_id' }
|
44
|
+
|
45
|
+
response.body['links'].each do |link|
|
46
|
+
key = map[link['rel']]
|
47
|
+
next if key.nil?
|
48
|
+
res[key] = link['id']
|
49
|
+
end
|
50
|
+
|
51
|
+
res
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# action :clone do
|
56
|
+
# verb :post
|
57
|
+
# path { "/v2/servers/#{account_alias}" }
|
58
|
+
# body { |object| ServerMapping.representation_for(:clone, object) }
|
59
|
+
# handler(202) do |response|
|
60
|
+
# ServerMapping.extract_single(response.body, :read)
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
|
64
|
+
action :update, 'PATCH /v1/servers' do
|
65
|
+
# Object with no transforms
|
66
|
+
body { |object| object }
|
67
|
+
handler(202) do |response|
|
68
|
+
ServerMapping.extract_single(response.body.to_json, :read)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ClinkCloud
|
2
|
+
class StatusResource < BaseResource
|
3
|
+
resources do
|
4
|
+
default_handler do |response|
|
5
|
+
fail "Unexpected response status #{response.status}... #{response.body}"
|
6
|
+
end
|
7
|
+
|
8
|
+
action :find do
|
9
|
+
verb :get
|
10
|
+
path { "/v2/operations/#{account_alias}/status/:id" }
|
11
|
+
handler(200) do |response|
|
12
|
+
# just a simple string
|
13
|
+
response.body
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clink_cloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Connor Atherton
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
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: faraday
|
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: faraday_middleware
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: kartograph
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: virtus
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: resource_kit
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: CenturyLink cloud client library.
|
126
|
+
email:
|
127
|
+
- c.liam.atherton@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- clink_cloud.gemspec
|
143
|
+
- lib/clink_cloud.rb
|
144
|
+
- lib/clink_cloud/client.rb
|
145
|
+
- lib/clink_cloud/errors.rb
|
146
|
+
- lib/clink_cloud/mappings/data_center_mapping.rb
|
147
|
+
- lib/clink_cloud/mappings/firewall_policy_mapping.rb
|
148
|
+
- lib/clink_cloud/mappings/group_mapping.rb
|
149
|
+
- lib/clink_cloud/mappings/network_mapping.rb
|
150
|
+
- lib/clink_cloud/mappings/operation_mapping.rb
|
151
|
+
- lib/clink_cloud/mappings/server_mapping.rb
|
152
|
+
- lib/clink_cloud/models/base.rb
|
153
|
+
- lib/clink_cloud/models/data_center.rb
|
154
|
+
- lib/clink_cloud/models/firewall_policy.rb
|
155
|
+
- lib/clink_cloud/models/group.rb
|
156
|
+
- lib/clink_cloud/models/ip_address.rb
|
157
|
+
- lib/clink_cloud/models/network.rb
|
158
|
+
- lib/clink_cloud/models/operation.rb
|
159
|
+
- lib/clink_cloud/models/server.rb
|
160
|
+
- lib/clink_cloud/models/status.rb
|
161
|
+
- lib/clink_cloud/resources/base_resource.rb
|
162
|
+
- lib/clink_cloud/resources/data_center_resource.rb
|
163
|
+
- lib/clink_cloud/resources/firewall_policy_resource.rb
|
164
|
+
- lib/clink_cloud/resources/group_resource.rb
|
165
|
+
- lib/clink_cloud/resources/ip_address_resource.rb
|
166
|
+
- lib/clink_cloud/resources/network_resource.rb
|
167
|
+
- lib/clink_cloud/resources/operation_resource.rb
|
168
|
+
- lib/clink_cloud/resources/server_resource.rb
|
169
|
+
- lib/clink_cloud/resources/status_resource.rb
|
170
|
+
- lib/clink_cloud/version.rb
|
171
|
+
homepage: https://github.com/ConnorAtherton/clink_cloud
|
172
|
+
licenses:
|
173
|
+
- MIT
|
174
|
+
metadata: {}
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options: []
|
177
|
+
require_paths:
|
178
|
+
- lib
|
179
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
requirements: []
|
190
|
+
rubyforge_project:
|
191
|
+
rubygems_version: 2.2.2
|
192
|
+
signing_key:
|
193
|
+
specification_version: 4
|
194
|
+
summary: CenturyLink cloud client library.
|
195
|
+
test_files: []
|