twistlock-control 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rubocop.yml +6 -0
- data/Gemfile +16 -0
- data/Guardfile +30 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/features/provisioning_service_instances.feature +14 -0
- data/features/step_definitions/provisioning_service_instances_steps.rb +33 -0
- data/features/support/env.rb +22 -0
- data/lib/twistlock_control.rb +65 -0
- data/lib/twistlock_control/actions.rb +7 -0
- data/lib/twistlock_control/actions/container.rb +42 -0
- data/lib/twistlock_control/actions/container_instance.rb +28 -0
- data/lib/twistlock_control/actions/provisioner.rb +25 -0
- data/lib/twistlock_control/actions/service.rb +18 -0
- data/lib/twistlock_control/actions/service_instance.rb +40 -0
- data/lib/twistlock_control/collections.rb +22 -0
- data/lib/twistlock_control/entities.rb +11 -0
- data/lib/twistlock_control/entities/composite_service.rb +86 -0
- data/lib/twistlock_control/entities/container.rb +66 -0
- data/lib/twistlock_control/entities/container_instance.rb +22 -0
- data/lib/twistlock_control/entities/provisioner.rb +24 -0
- data/lib/twistlock_control/entities/provisioning_configuration.rb +65 -0
- data/lib/twistlock_control/entities/service.rb +19 -0
- data/lib/twistlock_control/entities/service_instance.rb +122 -0
- data/lib/twistlock_control/entity.rb +63 -0
- data/lib/twistlock_control/provisioner_api.rb +43 -0
- data/lib/twistlock_control/rethinkdb_repository.rb +74 -0
- data/lib/twistlock_control/version.rb +4 -0
- data/spec/actions/container_spec.rb +19 -0
- data/spec/actions/provisioner_spec.rb +37 -0
- data/spec/actions/service_instance_spec.rb +47 -0
- data/spec/collections_spec.rb +14 -0
- data/spec/entities/composite_service_spec.rb +126 -0
- data/spec/entities/container_spec.rb +8 -0
- data/spec/entities/provisioner_spec.rb +56 -0
- data/spec/entities/service_instance_spec.rb +33 -0
- data/spec/entities/shared_service_specs.rb +4 -0
- data/spec/provisioner_api_spec.rb +35 -0
- data/spec/rethinkdb_repository_spec.rb +15 -0
- data/spec/spec_helper.rb +25 -0
- data/twistlock-control.gemspec +29 -0
- metadata +172 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include TwistlockControl
|
4
|
+
|
5
|
+
describe Entities::Provisioner do
|
6
|
+
it 'can provision a container instance' do
|
7
|
+
prov = Entities::Provisioner.new(name: 'MyName', url: 'url')
|
8
|
+
|
9
|
+
container = Entities::Container.new(name: 'MyContainer', url: 'someUrl')
|
10
|
+
container.save
|
11
|
+
|
12
|
+
service_instance = Actions::ServiceInstance.add('myServiceInstance', container)
|
13
|
+
|
14
|
+
configuration = service_instance.container_configurations.first
|
15
|
+
configuration.provisioner = prov
|
16
|
+
|
17
|
+
api = double(TwistlockControl::ProvisionerAPI)
|
18
|
+
expect(prov).to receive(:api).and_return(api)
|
19
|
+
expect(api).to receive(:provision_container)
|
20
|
+
.with(configuration)
|
21
|
+
.and_return(container_id: 'abcd', ip_address: '127.0.0.1')
|
22
|
+
|
23
|
+
Actions::ContainerInstance.add(configuration)
|
24
|
+
service_instance.save
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can be initialized from its attributes' do
|
28
|
+
prov = Entities::Provisioner.new(name: 'MyName', url: 'url')
|
29
|
+
expect(prov.respond_to? :name).to be(true)
|
30
|
+
expect(prov.name).to eq('MyName')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'can be persisted and retrieved from the database' do
|
34
|
+
prov = Entities::Provisioner.new(name: 'MyName', url: 'url')
|
35
|
+
prov.save
|
36
|
+
retrieved = Entities::Provisioner.find_by_id(prov.id)
|
37
|
+
expect(retrieved).to eq(prov)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'can get a list of provisioners' do
|
41
|
+
(1..3).each do |i|
|
42
|
+
prov = Entities::Provisioner.new(name: "Prov#{i}", url: "url#{i}")
|
43
|
+
prov.save
|
44
|
+
end
|
45
|
+
retrieved = Entities::Provisioner.all
|
46
|
+
expect(retrieved.length).to eq(3)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'can remove provisioners' do
|
50
|
+
prov = Entities::Provisioner.new(name: 'MyName', url: 'url')
|
51
|
+
prov.save
|
52
|
+
prov.remove
|
53
|
+
prov = Entities::Provisioner.find_by_id(prov.id)
|
54
|
+
expect(prov).to be_nil
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include TwistlockControl
|
4
|
+
|
5
|
+
describe ServiceInstance do
|
6
|
+
def make_service
|
7
|
+
service = Entities::CompositeService.new(name: 'MyService')
|
8
|
+
@container = Entities::Container.new(name: 'MyContainer', url: 'someUrl')
|
9
|
+
service.save
|
10
|
+
@container.save
|
11
|
+
service.service_relations[@container.name] = @container.id
|
12
|
+
service.save
|
13
|
+
service
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#serialize' do
|
17
|
+
def make_serialized
|
18
|
+
service = make_service
|
19
|
+
instance = Actions::ServiceInstance.add('my-instance', service)
|
20
|
+
instance.serialize
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should return a hash of attributes' do
|
24
|
+
expect(make_serialized).to respond_to(:to_hash)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should be possible to initialize from serialized' do
|
28
|
+
serialized = make_serialized
|
29
|
+
instance = Entities::ServiceInstance.new(serialized)
|
30
|
+
expect(instance.configuration).to_not be(nil)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include TwistlockControl
|
4
|
+
|
5
|
+
describe ProvisionerAPI do
|
6
|
+
attr_reader :api
|
7
|
+
before :all do
|
8
|
+
@api = ProvisionerAPI.new('http://localhost:3000')
|
9
|
+
end
|
10
|
+
describe '#container_description' do
|
11
|
+
before :all do
|
12
|
+
stub_request(:get, api.url + '/templates/redis').to_return(body: {
|
13
|
+
name: 'redis',
|
14
|
+
description: 'a description'
|
15
|
+
}.to_json)
|
16
|
+
end
|
17
|
+
it 'should connect to the given address request the container description' do
|
18
|
+
result = api.container_description('redis')
|
19
|
+
expect(result['name']).to eq('redis')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#add_container' do
|
24
|
+
before :all do
|
25
|
+
stub_request(:post, api.url + '/templates').to_return do
|
26
|
+
{ body: { status: 'ok' }.to_json }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should issue an add container request to the api' do
|
31
|
+
result = api.add_container('redis', 'git@github.com:d-snp/redis-container.git')
|
32
|
+
expect(result['status']).to eq('ok')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include TwistlockControl
|
4
|
+
|
5
|
+
describe RethinkDBRepository do
|
6
|
+
it 'should be able to find documents with ids' do
|
7
|
+
app = {
|
8
|
+
id: 'my-app',
|
9
|
+
name: 'My App'
|
10
|
+
}
|
11
|
+
repo = RethinkDBRepository['services']
|
12
|
+
repo.save(app)
|
13
|
+
expect(repo.find_with_ids([app[:id]]).length).to be(1)
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'twistlock_control'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
|
7
|
+
TwistlockControl.configure do |c|
|
8
|
+
c.database_name = 'test'
|
9
|
+
end
|
10
|
+
|
11
|
+
def repositories
|
12
|
+
%w(provisioners services service_instances container_instances)
|
13
|
+
.map { |n| TwistlockControl::RethinkDBRepository[n] }
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.before(:all) do
|
18
|
+
repositories.each(&:create_table)
|
19
|
+
end
|
20
|
+
config.before(:each) do
|
21
|
+
repositories.each(&:delete_all)
|
22
|
+
end
|
23
|
+
config.after(:all) {}
|
24
|
+
config.after(:each) {}
|
25
|
+
end
|
@@ -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 'twistlock_control/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'twistlock-control'
|
8
|
+
spec.version = TwistlockControl::VERSION
|
9
|
+
spec.authors = ['Tinco Andringa']
|
10
|
+
spec.email = ['mail@tinco.nl']
|
11
|
+
spec.description = 'Library for controlling Twistlock Provisioners'
|
12
|
+
spec.summary = 'Library for controlling Twistlock Provisioners'
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($RS)
|
17
|
+
spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)/)
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
|
24
|
+
{
|
25
|
+
'rethinkdb' => nil,
|
26
|
+
'connection_pool' => nil,
|
27
|
+
'virtus' => nil
|
28
|
+
}.each { |k, v| spec.add_dependency(k, v) }
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twistlock-control
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tinco Andringa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-10 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: rethinkdb
|
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: connection_pool
|
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: virtus
|
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
|
+
description: Library for controlling Twistlock Provisioners
|
84
|
+
email:
|
85
|
+
- mail@tinco.nl
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- Gemfile
|
93
|
+
- Guardfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- features/provisioning_service_instances.feature
|
98
|
+
- features/step_definitions/provisioning_service_instances_steps.rb
|
99
|
+
- features/support/env.rb
|
100
|
+
- lib/twistlock_control.rb
|
101
|
+
- lib/twistlock_control/actions.rb
|
102
|
+
- lib/twistlock_control/actions/container.rb
|
103
|
+
- lib/twistlock_control/actions/container_instance.rb
|
104
|
+
- lib/twistlock_control/actions/provisioner.rb
|
105
|
+
- lib/twistlock_control/actions/service.rb
|
106
|
+
- lib/twistlock_control/actions/service_instance.rb
|
107
|
+
- lib/twistlock_control/collections.rb
|
108
|
+
- lib/twistlock_control/entities.rb
|
109
|
+
- lib/twistlock_control/entities/composite_service.rb
|
110
|
+
- lib/twistlock_control/entities/container.rb
|
111
|
+
- lib/twistlock_control/entities/container_instance.rb
|
112
|
+
- lib/twistlock_control/entities/provisioner.rb
|
113
|
+
- lib/twistlock_control/entities/provisioning_configuration.rb
|
114
|
+
- lib/twistlock_control/entities/service.rb
|
115
|
+
- lib/twistlock_control/entities/service_instance.rb
|
116
|
+
- lib/twistlock_control/entity.rb
|
117
|
+
- lib/twistlock_control/provisioner_api.rb
|
118
|
+
- lib/twistlock_control/rethinkdb_repository.rb
|
119
|
+
- lib/twistlock_control/version.rb
|
120
|
+
- spec/actions/container_spec.rb
|
121
|
+
- spec/actions/provisioner_spec.rb
|
122
|
+
- spec/actions/service_instance_spec.rb
|
123
|
+
- spec/collections_spec.rb
|
124
|
+
- spec/entities/composite_service_spec.rb
|
125
|
+
- spec/entities/container_spec.rb
|
126
|
+
- spec/entities/provisioner_spec.rb
|
127
|
+
- spec/entities/service_instance_spec.rb
|
128
|
+
- spec/entities/shared_service_specs.rb
|
129
|
+
- spec/provisioner_api_spec.rb
|
130
|
+
- spec/rethinkdb_repository_spec.rb
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
- twistlock-control.gemspec
|
133
|
+
homepage: ''
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.2.2
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: Library for controlling Twistlock Provisioners
|
157
|
+
test_files:
|
158
|
+
- features/provisioning_service_instances.feature
|
159
|
+
- features/step_definitions/provisioning_service_instances_steps.rb
|
160
|
+
- features/support/env.rb
|
161
|
+
- spec/actions/container_spec.rb
|
162
|
+
- spec/actions/provisioner_spec.rb
|
163
|
+
- spec/actions/service_instance_spec.rb
|
164
|
+
- spec/collections_spec.rb
|
165
|
+
- spec/entities/composite_service_spec.rb
|
166
|
+
- spec/entities/container_spec.rb
|
167
|
+
- spec/entities/provisioner_spec.rb
|
168
|
+
- spec/entities/service_instance_spec.rb
|
169
|
+
- spec/entities/shared_service_specs.rb
|
170
|
+
- spec/provisioner_api_spec.rb
|
171
|
+
- spec/rethinkdb_repository_spec.rb
|
172
|
+
- spec/spec_helper.rb
|