bosh_docker_cpi 0.0.1.pre.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ require 'tmpdir'
2
+ require 'docker'
3
+ require 'cloud/docker'
4
+ require 'bosh_registry/instance_manager/docker'
5
+
@@ -0,0 +1,22 @@
1
+ module Bosh::Registry
2
+
3
+ class InstanceManager
4
+
5
+ class Docker < InstanceManager
6
+
7
+ def initialize(cloud_config)
8
+ @docker = Docker::API.new(base_url: 'http://localhost:4243')
9
+ end
10
+
11
+ # Get the list of IPs belonging to this instance
12
+ def instance_ips(instance_id)
13
+ details = docker.containers.show(instance_id)
14
+ details['NetworkSettings'].map{|network_settings| network_settings['IpAddress']}
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :docker
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,141 @@
1
+ module Bosh
2
+ module DockerCloud
3
+ class Cloud < 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 "tar -xzf #{image_path} root.img"
27
+
28
+ end
29
+ end
30
+ end
31
+
32
+ def delete_stemcell(stemcell_id)
33
+ not_implemented(:delete_stemcell)
34
+ end
35
+
36
+ def create_vm(agent_id, stemcell_id, resource_pool,
37
+ network_spec, disk_locality = nil, environment = nil)
38
+
39
+
40
+ result = containers.create(['/bin/sh', '-c', 'while true; do echo hello world; sleep 1; done'], stemcell_id)
41
+ vm_id = result["Id"]
42
+
43
+
44
+ registry_settings = initial_agent_settings(
45
+ agent_id,
46
+ network_spec,
47
+ environment,
48
+ ''
49
+ )
50
+ registry.update_settings(vm_id, registry_settings)
51
+
52
+ containers.start(vm_id)
53
+
54
+
55
+ vm_id
56
+ end
57
+
58
+ def delete_vm(vm_id)
59
+ containers.stop(vm_id)
60
+ containers.remove(vm_id)
61
+ end
62
+
63
+ def has_vm?(vm_id)
64
+ containers.list.collect { |c| c['Id'] }.include?(vm_id)
65
+ end
66
+
67
+ def reboot_vm(vm_id)
68
+ containers.restart(vm_id)
69
+ end
70
+
71
+ def set_vm_metadata(vm, metadata)
72
+ # Nothing to do here
73
+ end
74
+
75
+ def configure_networks(vm_id, networks)
76
+ #not_implemented(:configure_networks)
77
+ end
78
+
79
+ def create_disk(size, vm_locality = nil)
80
+ # create dir name for volume
81
+ #not_implemented(:create_disk)
82
+ end
83
+
84
+ def delete_disk(disk_id)
85
+ # remove dir
86
+ #not_implemented(:delete_disk)
87
+ end
88
+
89
+ def attach_disk(vm_id, disk_id)
90
+ # add volume to container (have to stop then start with volume)
91
+ #not_implemented(:attach_disk)
92
+ end
93
+
94
+ def snapshot_disk(disk_id, metadata={})
95
+ # copy dir (or put volume on btrfs and snapshot?)
96
+ #not_implemented(:snapshot_disk)
97
+ end
98
+
99
+ def delete_snapshot(snapshot_id)
100
+ # delete dir or btrfs snapshot
101
+ #not_implemented(:delete_snapshot)
102
+ end
103
+
104
+ def detach_disk(vm_id, disk_id)
105
+ # stop container, restart w/o volume
106
+ #not_implemented(:detach_disk)
107
+ end
108
+
109
+ def get_disks(vm_id)
110
+ details = containers.show(vm_id)
111
+ details['Volumes'].keys
112
+ end
113
+
114
+ private
115
+
116
+ attr_reader :registry, :agent_properties, :docker
117
+
118
+ def containers
119
+ @containers ||= docker.containers
120
+ end
121
+
122
+ def initial_agent_settings(agent_id, network_spec, environment, root_device_name)
123
+ settings = {
124
+ "vm" => {
125
+ "name" => "vm-#{SecureRandom.uuid}"
126
+ },
127
+ "agent_id" => agent_id,
128
+ "networks" => network_spec,
129
+ "disks" => {
130
+ "system" => root_device_name,
131
+ "ephemeral" => '',
132
+ "persistent" => {}
133
+ }
134
+ }
135
+
136
+ settings["env"] = environment if environment
137
+ settings.merge(agent_properties)
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'docker/cloud'
2
+
3
+ module Bosh
4
+ module Clouds
5
+ Docker = Bosh::DockerCloud::Cloud
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bosh_docker_cpi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre.1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Alex Jackson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: docker-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
47
+ name: bosh_cpi
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.5.0.pre.3
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ 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
+ description: BOSH Docker CPI
111
+ email:
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files: []
115
+ files:
116
+ - lib/bosh_docker_cpi.rb
117
+ - lib/bosh_registry/instance_manager/docker.rb
118
+ - lib/cloud/docker.rb
119
+ - lib/cloud/docker/cloud.rb
120
+ homepage: https://github.com/ajackson/bosh-lite
121
+ licenses:
122
+ - Apache 2.0
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: 1.9.3
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>'
137
+ - !ruby/object:Gem::Version
138
+ version: 1.3.1
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.25
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: BOSH Docker CPI
145
+ test_files: []