bosh_docker_cpi 0.0.1.pre.3 → 0.0.1.pre.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/active_support/core_ext/numeric.rb +1 -0
- data/lib/bosh_docker_cpi.rb +1 -2
- data/lib/bosh_registry/instance_manager/docker.rb +2 -2
- data/lib/cloud/docker.rb +154 -1
- metadata +2 -66
- data/lib/cloud/docker/cloud.rb +0 -153
@@ -0,0 +1 @@
|
|
1
|
+
#Nothing here just hack around issue with docker_client gem.
|
data/lib/bosh_docker_cpi.rb
CHANGED
data/lib/cloud/docker.rb
CHANGED
@@ -1,6 +1,159 @@
|
|
1
|
-
|
1
|
+
require 'docker'
|
2
|
+
require 'tmpdir'
|
2
3
|
|
3
4
|
module Bosh
|
4
5
|
module Clouds
|
6
|
+
|
7
|
+
class Docker < Bosh::Cloud
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@nats_uri = options.fetch('nats', '')
|
11
|
+
@agent_properties = options.fetch('agent', {})
|
12
|
+
#registry_properties = options.fetch('registry')
|
13
|
+
#registry_endpoint = registry_properties.fetch('endpoint')
|
14
|
+
#registry_user = registry_properties.fetch('user')
|
15
|
+
#registry_password = registry_properties.fetch('password')
|
16
|
+
#
|
17
|
+
#@registry = Bosh::Registry::Client.new(registry_endpoint,
|
18
|
+
# registry_user,
|
19
|
+
# registry_password)
|
20
|
+
|
21
|
+
@docker = ::Docker::API.new(base_url: 'http://localhost:4243')
|
22
|
+
end
|
23
|
+
|
24
|
+
def current_vm_id
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_stemcell(image_path, cloud_properties)
|
29
|
+
Dir.mktmpdir do |dir|
|
30
|
+
Dir.chdir(dir) do
|
31
|
+
system 'mkdir mnt'
|
32
|
+
system "tar -xzf #{image_path} root.img"
|
33
|
+
system 'sudo kpartx -a root.img'
|
34
|
+
system 'sudo mount /dev/mapper/loop0p1 mnt'
|
35
|
+
Dir.chdir('mnt') do
|
36
|
+
system 'sudo tar zcf ../stemcell_img.tgz .'
|
37
|
+
end
|
38
|
+
system 'sudo umount mnt'
|
39
|
+
system 'sudo kpartx -d root.img'
|
40
|
+
system 'sudo chmod 777 stemcell_img.tgz'
|
41
|
+
system 'cat stemcell_img.tgz | docker image - bosh latest' #returns stemcell_id
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete_stemcell(stemcell_id)
|
47
|
+
system "docker rmi #{stemcell_id}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_vm(agent_id, stemcell_id, resource_pool,
|
51
|
+
network_spec, disk_locality = nil, environment = nil)
|
52
|
+
|
53
|
+
#nats_uri = 'nats://172.16.42.1:21084'
|
54
|
+
blobstore_uri = 'http://172.16.42.1:21081'
|
55
|
+
agent_base_dir = '/var/vcap/bosh'
|
56
|
+
root_dir = '/var/vcap/bosh'
|
57
|
+
result = containers.create(['/bin/sh', '-c', "/var/vcap/bosh/bin/bosh_agent -a #{agent_id} -s #{blobstore_uri} -p simple -b #{agent_base_dir} -n #{nats_uri} -r #{root_dir}"], stemcell_id)
|
58
|
+
vm_id = result["Id"]
|
59
|
+
|
60
|
+
|
61
|
+
#registry_settings = initial_agent_settings(
|
62
|
+
# agent_id,
|
63
|
+
# network_spec,
|
64
|
+
# environment,
|
65
|
+
# ''
|
66
|
+
#)
|
67
|
+
#registry.update_settings(vm_id, registry_settings)
|
68
|
+
|
69
|
+
containers.start(vm_id)
|
70
|
+
|
71
|
+
|
72
|
+
vm_id
|
73
|
+
end
|
74
|
+
|
75
|
+
def delete_vm(vm_id)
|
76
|
+
containers.stop(vm_id)
|
77
|
+
containers.remove(vm_id)
|
78
|
+
end
|
79
|
+
|
80
|
+
def has_vm?(vm_id)
|
81
|
+
containers.list.collect { |c| c['Id'] }.include?(vm_id)
|
82
|
+
end
|
83
|
+
|
84
|
+
def reboot_vm(vm_id)
|
85
|
+
containers.restart(vm_id)
|
86
|
+
end
|
87
|
+
|
88
|
+
def set_vm_metadata(vm, metadata)
|
89
|
+
# Nothing to do here
|
90
|
+
end
|
91
|
+
|
92
|
+
def configure_networks(vm_id, networks)
|
93
|
+
#not_implemented(:configure_networks)
|
94
|
+
end
|
95
|
+
|
96
|
+
def create_disk(size, vm_locality = nil)
|
97
|
+
# create dir name for volume
|
98
|
+
#not_implemented(:create_disk)
|
99
|
+
end
|
100
|
+
|
101
|
+
def delete_disk(disk_id)
|
102
|
+
# remove dir
|
103
|
+
#not_implemented(:delete_disk)
|
104
|
+
end
|
105
|
+
|
106
|
+
def attach_disk(vm_id, disk_id)
|
107
|
+
# add volume to container (have to stop then start with volume)
|
108
|
+
#not_implemented(:attach_disk)
|
109
|
+
end
|
110
|
+
|
111
|
+
def snapshot_disk(disk_id, metadata={})
|
112
|
+
# copy dir (or put volume on btrfs and snapshot?)
|
113
|
+
#not_implemented(:snapshot_disk)
|
114
|
+
end
|
115
|
+
|
116
|
+
def delete_snapshot(snapshot_id)
|
117
|
+
# delete dir or btrfs snapshot
|
118
|
+
#not_implemented(:delete_snapshot)
|
119
|
+
end
|
120
|
+
|
121
|
+
def detach_disk(vm_id, disk_id)
|
122
|
+
# stop container, restart w/o volume
|
123
|
+
#not_implemented(:detach_disk)
|
124
|
+
end
|
125
|
+
|
126
|
+
def get_disks(vm_id)
|
127
|
+
details = containers.show(vm_id)
|
128
|
+
details['Volumes'].keys
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
attr_reader :registry, :agent_properties, :docker, :nats_uri
|
134
|
+
|
135
|
+
def containers
|
136
|
+
@containers ||= docker.containers
|
137
|
+
end
|
138
|
+
|
139
|
+
def initial_agent_settings(agent_id, network_spec, environment, root_device_name)
|
140
|
+
settings = {
|
141
|
+
"vm" => {
|
142
|
+
"name" => "vm-#{SecureRandom.uuid}"
|
143
|
+
},
|
144
|
+
"agent_id" => agent_id,
|
145
|
+
"networks" => network_spec,
|
146
|
+
"disks" => {
|
147
|
+
"system" => root_device_name,
|
148
|
+
"ephemeral" => '',
|
149
|
+
"persistent" => {}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
settings["env"] = environment if environment
|
154
|
+
settings.merge(agent_properties)
|
155
|
+
end
|
156
|
+
end
|
5
157
|
end
|
6
158
|
end
|
159
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bosh_docker_cpi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.pre.
|
4
|
+
version: 0.0.1.pre.4
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,22 +27,6 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: bosh_common
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 1.5.0.pre.3
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.5.0.pre.3
|
46
30
|
- !ruby/object:Gem::Dependency
|
47
31
|
name: bosh_cpi
|
48
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,64 +43,16 @@ dependencies:
|
|
59
43
|
- - ~>
|
60
44
|
- !ruby/object:Gem::Version
|
61
45
|
version: 1.5.0.pre.3
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: bosh_registry
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 1.5.0.pre.3
|
70
|
-
type: :runtime
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: 1.5.0.pre.3
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: httpclient
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - '='
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: 2.2.4
|
86
|
-
type: :runtime
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - '='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: 2.2.4
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: yajl-ruby
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ! '>='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: 0.8.2
|
102
|
-
type: :runtime
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 0.8.2
|
110
46
|
description: BOSH Docker CPI
|
111
47
|
email:
|
112
48
|
executables: []
|
113
49
|
extensions: []
|
114
50
|
extra_rdoc_files: []
|
115
51
|
files:
|
52
|
+
- lib/active_support/core_ext/numeric.rb
|
116
53
|
- lib/bosh_docker_cpi.rb
|
117
54
|
- lib/bosh_registry/instance_manager/docker.rb
|
118
55
|
- lib/cloud/docker.rb
|
119
|
-
- lib/cloud/docker/cloud.rb
|
120
56
|
homepage: https://github.com/ajackson/bosh-lite
|
121
57
|
licenses:
|
122
58
|
- Apache 2.0
|
data/lib/cloud/docker/cloud.rb
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
module Bosh
|
2
|
-
module Clouds
|
3
|
-
class Docker < Bosh::Cloud
|
4
|
-
|
5
|
-
def initialize(options)
|
6
|
-
@agent_properties ||= options.fetch('agent', {})
|
7
|
-
#registry_properties = options.fetch('registry')
|
8
|
-
#registry_endpoint = registry_properties.fetch('endpoint')
|
9
|
-
#registry_user = registry_properties.fetch('user')
|
10
|
-
#registry_password = registry_properties.fetch('password')
|
11
|
-
#
|
12
|
-
#@registry = Bosh::Registry::Client.new(registry_endpoint,
|
13
|
-
# registry_user,
|
14
|
-
# registry_password)
|
15
|
-
|
16
|
-
@docker = ::Docker::API.new(base_url: 'http://localhost:4243')
|
17
|
-
end
|
18
|
-
|
19
|
-
def current_vm_id
|
20
|
-
nil
|
21
|
-
end
|
22
|
-
|
23
|
-
def create_stemcell(image_path, cloud_properties)
|
24
|
-
Dir.mktmpdir do |dir|
|
25
|
-
Dir.chdir(dir) do
|
26
|
-
system 'mkdir mnt'
|
27
|
-
system "tar -xzf #{image_path} root.img"
|
28
|
-
system 'sudo kpartx -a root.img'
|
29
|
-
system 'sudo mount /dev/mapper/loop0p1 mnt'
|
30
|
-
Dir.chdir('mnt') do
|
31
|
-
system 'sudo tar zcf ../stemcell_img.tgz .'
|
32
|
-
end
|
33
|
-
system 'sudo umount mnt'
|
34
|
-
system 'sudo kpartx -d root.img'
|
35
|
-
system 'sudo chmod 777 stemcell_img.tgz'
|
36
|
-
system 'cat stemcell_img.tgz | docker image - bosh latest' #returns stemcell_id
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def delete_stemcell(stemcell_id)
|
42
|
-
system "docker rmi #{stemcell_id}"
|
43
|
-
end
|
44
|
-
|
45
|
-
def create_vm(agent_id, stemcell_id, resource_pool,
|
46
|
-
network_spec, disk_locality = nil, environment = nil)
|
47
|
-
|
48
|
-
nats_uri = 'nats://172.16.42.1:21084'
|
49
|
-
blobstore_uri = 'http://172.16.42.1:21081'
|
50
|
-
agent_base_dir = '/var/vcap/bosh'
|
51
|
-
root_dir = '/var/vcap/bosh'
|
52
|
-
result = containers.create(['/bin/sh', '-c', "/var/vcap/bosh/bin/bosh_agent -a #{agent_id} -s #{blobstore_uri} -p simple -b #{agent_base_dir} -n #{nats_uri} -r #{root_dir}"], stemcell_id)
|
53
|
-
vm_id = result["Id"]
|
54
|
-
|
55
|
-
|
56
|
-
#registry_settings = initial_agent_settings(
|
57
|
-
# agent_id,
|
58
|
-
# network_spec,
|
59
|
-
# environment,
|
60
|
-
# ''
|
61
|
-
#)
|
62
|
-
#registry.update_settings(vm_id, registry_settings)
|
63
|
-
|
64
|
-
containers.start(vm_id)
|
65
|
-
|
66
|
-
|
67
|
-
vm_id
|
68
|
-
end
|
69
|
-
|
70
|
-
def delete_vm(vm_id)
|
71
|
-
containers.stop(vm_id)
|
72
|
-
containers.remove(vm_id)
|
73
|
-
end
|
74
|
-
|
75
|
-
def has_vm?(vm_id)
|
76
|
-
containers.list.collect { |c| c['Id'] }.include?(vm_id)
|
77
|
-
end
|
78
|
-
|
79
|
-
def reboot_vm(vm_id)
|
80
|
-
containers.restart(vm_id)
|
81
|
-
end
|
82
|
-
|
83
|
-
def set_vm_metadata(vm, metadata)
|
84
|
-
# Nothing to do here
|
85
|
-
end
|
86
|
-
|
87
|
-
def configure_networks(vm_id, networks)
|
88
|
-
#not_implemented(:configure_networks)
|
89
|
-
end
|
90
|
-
|
91
|
-
def create_disk(size, vm_locality = nil)
|
92
|
-
# create dir name for volume
|
93
|
-
#not_implemented(:create_disk)
|
94
|
-
end
|
95
|
-
|
96
|
-
def delete_disk(disk_id)
|
97
|
-
# remove dir
|
98
|
-
#not_implemented(:delete_disk)
|
99
|
-
end
|
100
|
-
|
101
|
-
def attach_disk(vm_id, disk_id)
|
102
|
-
# add volume to container (have to stop then start with volume)
|
103
|
-
#not_implemented(:attach_disk)
|
104
|
-
end
|
105
|
-
|
106
|
-
def snapshot_disk(disk_id, metadata={})
|
107
|
-
# copy dir (or put volume on btrfs and snapshot?)
|
108
|
-
#not_implemented(:snapshot_disk)
|
109
|
-
end
|
110
|
-
|
111
|
-
def delete_snapshot(snapshot_id)
|
112
|
-
# delete dir or btrfs snapshot
|
113
|
-
#not_implemented(:delete_snapshot)
|
114
|
-
end
|
115
|
-
|
116
|
-
def detach_disk(vm_id, disk_id)
|
117
|
-
# stop container, restart w/o volume
|
118
|
-
#not_implemented(:detach_disk)
|
119
|
-
end
|
120
|
-
|
121
|
-
def get_disks(vm_id)
|
122
|
-
details = containers.show(vm_id)
|
123
|
-
details['Volumes'].keys
|
124
|
-
end
|
125
|
-
|
126
|
-
private
|
127
|
-
|
128
|
-
attr_reader :registry, :agent_properties, :docker
|
129
|
-
|
130
|
-
def containers
|
131
|
-
@containers ||= docker.containers
|
132
|
-
end
|
133
|
-
|
134
|
-
def initial_agent_settings(agent_id, network_spec, environment, root_device_name)
|
135
|
-
settings = {
|
136
|
-
"vm" => {
|
137
|
-
"name" => "vm-#{SecureRandom.uuid}"
|
138
|
-
},
|
139
|
-
"agent_id" => agent_id,
|
140
|
-
"networks" => network_spec,
|
141
|
-
"disks" => {
|
142
|
-
"system" => root_device_name,
|
143
|
-
"ephemeral" => '',
|
144
|
-
"persistent" => {}
|
145
|
-
}
|
146
|
-
}
|
147
|
-
|
148
|
-
settings["env"] = environment if environment
|
149
|
-
settings.merge(agent_properties)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|