This repository was archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: Iacb8e43e1b0f7c399eb555e6ff45f5b0bd3aa2c5
- Loading branch information
Showing
45 changed files
with
1,175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in warden-protocol.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "rspec/core/rake_task" | ||
require "rspec/core/version" | ||
|
||
task :default => :spec | ||
|
||
desc "Run all examples" | ||
RSpec::Core::RakeTask.new(:spec) do |t| | ||
t.rspec_opts = %w[--color --format documentation] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require "warden/protocol/version" | ||
|
||
require "warden/protocol/error" | ||
|
||
require "warden/protocol/create" | ||
require "warden/protocol/stop" | ||
require "warden/protocol/destroy" | ||
require "warden/protocol/info" | ||
|
||
require "warden/protocol/spawn" | ||
require "warden/protocol/link" | ||
require "warden/protocol/run" | ||
|
||
require "warden/protocol/net_in" | ||
require "warden/protocol/net_out" | ||
|
||
require "warden/protocol/copy_in" | ||
require "warden/protocol/copy_out" | ||
|
||
require "warden/protocol/limit_memory" | ||
require "warden/protocol/limit_disk" | ||
|
||
require "warden/protocol/ping" | ||
require "warden/protocol/list" | ||
|
||
module Warden | ||
module Protocol | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
require "beefcake" | ||
|
||
module Warden | ||
module Protocol | ||
module Type | ||
Error = 1 | ||
|
||
Create = 11 | ||
Stop = 12 | ||
Destroy = 13 | ||
Info = 14 | ||
|
||
Spawn = 21 | ||
Link = 22 | ||
Run = 23 | ||
|
||
NetIn = 31 | ||
NetOut = 32 | ||
|
||
CopyIn = 41 | ||
CopyOut = 42 | ||
|
||
LimitMemory = 51 | ||
LimitDisk = 52 | ||
|
||
Ping = 91 | ||
List = 92 | ||
|
||
def self.generate_klass_map(suffix) | ||
map = Hash[self.constants.map do |name| | ||
klass_name = "#{name}#{suffix}" | ||
if Protocol.const_defined?(klass_name) | ||
[const_get(name), Protocol.const_get(klass_name)] | ||
end | ||
end] | ||
|
||
if map.respond_to?(:default_proc=) | ||
map.default_proc = lambda do |h, k| | ||
raise "Unknown request type: #{k}" | ||
end | ||
end | ||
|
||
map | ||
end | ||
|
||
def self.to_request_klass(type) | ||
@request_klass_map ||= generate_klass_map("Request") | ||
@request_klass_map[type] | ||
end | ||
|
||
def self.to_response_klass(type) | ||
@response_klass_map ||= generate_klass_map("Response") | ||
@response_klass_map[type] | ||
end | ||
end | ||
|
||
class BaseMessage | ||
include Beefcake::Message | ||
|
||
def reload | ||
self.class.decode(encode) | ||
end | ||
end | ||
|
||
class BaseRequest < BaseMessage | ||
def create_response(attributes = {}) | ||
klass_name = self.class.name.gsub(/Request$/, "Response") | ||
klass_name = klass_name.split("::").last | ||
klass = Protocol.const_get(klass_name) | ||
klass.new(attributes) | ||
end | ||
|
||
def wrap | ||
klass_name = self.class.name.gsub(/Request$/, "") | ||
klass_name = klass_name.split("::").last | ||
|
||
WrappedRequest.new \ | ||
:type => Type.const_get(klass_name), | ||
:payload => encode | ||
end | ||
end | ||
|
||
class BaseResponse < BaseMessage | ||
def wrap | ||
klass_name = self.class.name.gsub(/Response$/, "") | ||
klass_name = klass_name.split("::").last | ||
|
||
WrappedResponse.new \ | ||
:type => Type.const_get(klass_name), | ||
:payload => encode | ||
end | ||
end | ||
|
||
class WrappedRequest < BaseRequest | ||
required :type, Type, 1 | ||
required :payload, :string, 2 | ||
|
||
def request | ||
Type.to_request_klass(type).decode(payload) | ||
end | ||
end | ||
|
||
class WrappedResponse < BaseResponse | ||
required :type, Type, 1 | ||
required :payload, :string, 2 | ||
|
||
def response | ||
Type.to_response_klass(type).decode(payload) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class CopyInRequest < BaseRequest | ||
required :handle, :string, 1 | ||
required :src_path, :string, 2 | ||
required :dst_path, :string, 3 | ||
end | ||
|
||
class CopyInResponse < BaseResponse | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class CopyOutRequest < BaseRequest | ||
required :handle, :string, 1 | ||
required :src_path, :string, 2 | ||
required :dst_path, :string, 3 | ||
optional :owner, :string, 4 | ||
end | ||
|
||
class CopyOutResponse < BaseResponse | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class CreateRequest < BaseRequest | ||
class BindMount < BaseMessage | ||
module Mode | ||
RO = 0 | ||
RW = 1 | ||
end | ||
|
||
required :src, :string, 1 | ||
required :dst, :string, 2 | ||
required :mode, BindMount::Mode, 3 | ||
end | ||
|
||
repeated :bind_mounts, BindMount, 1 | ||
optional :grace_time, :uint32, 2 | ||
end | ||
|
||
class CreateResponse < BaseResponse | ||
required :handle, :string, 1 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class DestroyRequest < BaseRequest | ||
required :handle, :string, 1 | ||
end | ||
|
||
class DestroyResponse < BaseResponse | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class ErrorResponse < BaseResponse | ||
optional :message, :string, 2 | ||
optional :data, :string, 4 | ||
repeated :backtrace, :string, 3 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class InfoRequest < BaseRequest | ||
required :handle, :string, 1 | ||
end | ||
|
||
class InfoResponse < BaseResponse | ||
optional :state, :string, 10 | ||
|
||
repeated :events, :string, 20 | ||
|
||
optional :host_ip, :string, 30 | ||
optional :container_ip, :string, 31 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class LimitDiskRequest < BaseRequest | ||
required :handle, :string, 1 | ||
optional :block_limit, :uint32, 10 | ||
optional :inode_limit, :uint32, 20 | ||
end | ||
|
||
class LimitDiskResponse < BaseResponse | ||
optional :block_limit, :uint32, 10 | ||
optional :inode_limit, :uint32, 20 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class LimitMemoryRequest < BaseRequest | ||
required :handle, :string, 1 | ||
optional :limit_in_bytes, :uint32, 2 | ||
end | ||
|
||
class LimitMemoryResponse < BaseResponse | ||
optional :limit_in_bytes, :uint32, 1 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class LinkRequest < BaseRequest | ||
required :handle, :string, 1 | ||
required :job_id, :uint32, 2 | ||
end | ||
|
||
class LinkResponse < BaseResponse | ||
optional :exit_status, :uint32, 1 | ||
optional :stdout, :string, 2 | ||
optional :stderr, :string, 3 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class ListRequest < BaseRequest | ||
end | ||
|
||
class ListResponse < BaseResponse | ||
repeated :handles, :string, 1 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class NetInRequest < BaseRequest | ||
required :handle, :string, 1 | ||
optional :container_port, :uint32, 2 | ||
end | ||
|
||
class NetInResponse < BaseResponse | ||
required :host_port, :uint32, 1 | ||
required :container_port, :uint32, 2 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class NetOutRequest < BaseRequest | ||
required :handle, :string, 1 | ||
optional :network, :string, 2 | ||
optional :port, :uint32, 3 | ||
end | ||
|
||
class NetOutResponse < BaseResponse | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class PingRequest < BaseRequest | ||
end | ||
|
||
class PingResponse < BaseResponse | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "warden/protocol/base" | ||
|
||
module Warden | ||
module Protocol | ||
class RunRequest < BaseRequest | ||
required :handle, :string, 1 | ||
required :script, :string, 2 | ||
optional :privileged, :bool, 3, :default => false | ||
end | ||
|
||
class RunResponse < BaseResponse | ||
optional :exit_status, :uint32, 1 | ||
optional :stdout, :string, 2 | ||
optional :stderr, :string, 3 | ||
end | ||
end | ||
end |
Oops, something went wrong.