shipyard_client 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa96cc6e971a0b557f9da8585e166f3de4f4370d
4
+ data.tar.gz: b9ad729c2b16149f3af13bb099c151eed5dfbc86
5
+ SHA512:
6
+ metadata.gz: 46ab352c19a8e9ef7e06edc54431e0d7b5a600ba5dddf39c13df5fe5a5abc0b19452dbc06543c4eace5f4e2b739e85b4e3cad6883da73878fe316d0e27887407
7
+ data.tar.gz: be223df3f81d53a323ea35cabd709087b2e79729539fe4f0ba89a137158781491e6dff2b11389b81079e72c7f3d022f85e81b408a7ea9de36a31fd0959a13ccc
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.gem
12
+ .DS_Store
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at linton.tw@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shipyardClient.gemspec
4
+ gemspec
5
+
6
+ gem 'http'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Che-Wei Lin
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,67 @@
1
+ # ShipyardClient
2
+
3
+ A Shipyard 3.0 API wrapper for Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'shipyard_client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install shipyard_client
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'shipyard_client'
25
+
26
+ HOST = 'http://localhost:8080'
27
+ SERVICE_KEY = 'your_service_key'
28
+
29
+ s = ShipyardClient::Shipyard.new(HOST, SERVICE_KEY)
30
+
31
+ puts s.list_containers
32
+
33
+ s.remove_container('3a8151e21caa')
34
+ s.start_container('3a8151e21caa')
35
+ s.stop_container('3a8151e21caa')
36
+ s.restart_container('3a8151e21caa')
37
+
38
+ options = {
39
+ ExposedPorts: {
40
+ '1999/tcp': {},
41
+ '6633/tcp': {}
42
+ },
43
+ HostConfig: {
44
+ PortBindings: {
45
+ '1999/tcp': [{ HostPort: '7896' }],
46
+ '6633/tcp': [{ HostPort: '9089' }]
47
+ }
48
+ }
49
+ }
50
+
51
+ s.create_container('linton/remote-ryu', options)
52
+ ```
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hsnl-dev/shipyard_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
63
+
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
3
+
4
+ task :clean do
5
+ sh "gem uninstall shipyard_client"
6
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'shipyard_client'
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,90 @@
1
+ require 'shipyard_client/version'
2
+ require 'json'
3
+ require 'http'
4
+
5
+ module ShipyardClient
6
+ class Shipyard
7
+ attr_accessor :host, :service_key
8
+ def initialize(host, service_key)
9
+ @host = host
10
+ @service_key = service_key
11
+ end
12
+
13
+ def list_containers
14
+ res = HTTP.headers('X-Service-Key' => @service_key)
15
+ .get("#{host}/containers/json")
16
+ handle_response(res)
17
+ end
18
+
19
+ def create_container(image, options)
20
+ create_template = {
21
+ AttachStdin: false,
22
+ CpuShares: nil,
23
+ Env: [],
24
+ Cmd: [],
25
+ ExposedPorts: {},
26
+ HostConfig: {
27
+ Binds: [],
28
+ Links: [],
29
+ PortBindings: {},
30
+ Privileged: false,
31
+ PublishAllPorts: false,
32
+ RestartPolicy: {
33
+ Name: 'no'
34
+ }
35
+ },
36
+ Image: '',
37
+ Links: [],
38
+ Memory: nil,
39
+ Tty: true,
40
+ Volumes: {}
41
+ }
42
+ create_template[:Image] = image
43
+ create_template.merge!(options)
44
+ res = HTTP.headers('X-Service-Key' => @service_key)
45
+ .post("#{host}/containers/create?name=",
46
+ json: create_template)
47
+ handle_response(res)
48
+ end
49
+
50
+ def inspect_container(id)
51
+ res = HTTP.headers('X-Service-Key' => @service_key)
52
+ .get("#{host}/containers/#{id}/json")
53
+ handle_response(res)
54
+ end
55
+
56
+ def remove_container(id)
57
+ res = HTTP.headers('X-Service-Key' => @service_key)
58
+ .delete("#{host}/containers/#{id}?force=1")
59
+ handle_response(res)
60
+ end
61
+
62
+ def start_container(id)
63
+ res = HTTP.headers('X-Service-Key' => @service_key)
64
+ .post("#{host}/containers/#{id}/start")
65
+ handle_response(res)
66
+ end
67
+
68
+ def stop_container(id)
69
+ res = HTTP.headers('X-Service-Key' => @service_key)
70
+ .post("#{host}/containers/#{id}/stop")
71
+ handle_response(res)
72
+ end
73
+
74
+ def restart_container(id)
75
+ res = HTTP.headers('X-Service-Key' => @service_key)
76
+ .post("#{host}/containers/#{id}/restart")
77
+ handle_response(res)
78
+ end
79
+
80
+ private
81
+
82
+ def handle_response(res)
83
+ if res.code < 200 || res.code >= 300
84
+ raise "FAILED with status code: #{res.code} #{res}"
85
+ end
86
+ # Do not parse JSON if there is no content
87
+ res.code == 204 ? nil : JSON.load(res.to_s)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,3 @@
1
+ module ShipyardClient
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shipyard_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'shipyard_client'
8
+ spec.version = ShipyardClient::VERSION
9
+ spec.authors = ['Che-Wei Lin', 'Chi-Hsuan Li']
10
+ spec.email = ['linton.tw@gmail.com', 'lch82327@gmail.com']
11
+
12
+ spec.summary = 'A Shipyard 3.0 API wrapper for Ruby'
13
+ spec.description = 'Shipyard API'
14
+ spec.homepage = 'https://github.com/hsnl-dev/shipyard_client'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files`.split("\n")
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.11'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_runtime_dependency 'http', '2.0.0'
23
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shipyard_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Che-Wei Lin
8
+ - Chi-Hsuan Li
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-05-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.11'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.11'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: http
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 2.0.0
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 2.0.0
56
+ description: Shipyard API
57
+ email:
58
+ - linton.tw@gmail.com
59
+ - lch82327@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/shipyard_client.rb
73
+ - lib/shipyard_client/version.rb
74
+ - shipyard_client.gemspec
75
+ homepage: https://github.com/hsnl-dev/shipyard_client
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A Shipyard 3.0 API wrapper for Ruby
99
+ test_files: []