bosh_cli_plugin_redis 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ bosh_release/.final_builds/jobs/*/*.tgz
19
+ bosh_release/.final_builds/packages/*/*.tgz
20
+ bosh_release/releases/*.tgz
21
+ deployments
data/ChangeLog.md ADDED
@@ -0,0 +1,34 @@
1
+ # Change Log
2
+
3
+
4
+ ## v0.2 - bosh_cli_plugin_redis
5
+
6
+ Converted into a bosh plugin. Prefix "bosh" to the sub-commands below:
7
+
8
+ prepare redis
9
+ Prepare bosh for deploying one or more Redis services
10
+
11
+ create redis [--name] [--size] [--security_group]
12
+ Create a Redis service deployed upon target bosh
13
+ --name Unique name for service (within bosh & cloud foundry)
14
+ --size Size of provisioned VMs
15
+ --security_group Security group to assign to provisioned VMs
16
+
17
+ show redis uri
18
+ Show the redis URI for connection via bosh DNS
19
+
20
+ delete redis
21
+ Delete current Redis service
22
+
23
+ Note: the `cf bind-redis-env-var` command has been removed as it is a) specific to a Cloud Foundry user not a bosh user; b) kinda crappy "services" integration. Perhaps move it back into a cf plugin in future.
24
+
25
+ ## v0.1 - redis-cf-plugin
26
+
27
+ Initial release! The initial commands offered are:
28
+
29
+ cf create-redis Create a Redis service deployed upon target bosh
30
+ cf show-redis-uri Show the redis URI for connection via bosh DNS
31
+ cf bind-redis-env-var APP Bind current Redis service URI to current app via env variable
32
+ cf delete-redis Delete current Redis service
33
+
34
+ The redis service URI uses bosh DNS. As such it must be deployed into the same bosh being used for Cloud Foundry.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+ source 'https://s3.amazonaws.com/bosh-jenkins-gems/' # for prerelease bosh_cli
3
+
4
+ # Specify your gem's dependencies in redis-cf-plugin.gemspec
5
+ gemspec
6
+
7
+ bosh_cli_path = File.expand_path("~/gems/cloudfoundry/bosh/bosh_cli")
8
+ if File.directory?(bosh_cli_path)
9
+ gem "bosh_cli", path: bosh_cli_path
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dr Nic Williams
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,129 @@
1
+ # Dedicate Redis services on AWS or OpenStack
2
+
3
+ This is a simple `bosh` CLI plugin to create and delete dedicated redis services and provide a simple URI. It runs on AWS or OpenStack via bosh.
4
+
5
+ Example create/delete scenario that includes binding the redis service to a Cloud Foundry application via environment variables:
6
+
7
+ ```
8
+ $ bosh prepare redis
9
+ $ bosh create redis --name demoredis
10
+ $ bosh show redis uri
11
+ redis://:c1da049a75b3@0.redis.default.demoredis.microbosh:6379/0
12
+ $ cf set-env myapp REDIS_URI redis://:c1da049a75b3@0.redis.default.redis-123.microbosh:6379/0
13
+
14
+ $ cf unset-env myapp REDIS_URI
15
+ $ bosh delete redis
16
+ ```
17
+
18
+ The resulting redis servers can be discovered and accessed by any systems (such as Cloud Foundry applications) using the same bosh (or microbosh) or a connected DNS.
19
+
20
+ ## Requirements
21
+
22
+ You must use the same BOSH for deploying redis as you use to deploy Cloud Foundry (unless your DNS is configured to be shared across the two BOSH).
23
+
24
+ It is also requried that you have login access to the same BOSH being used to deploy your Cloud Foundry.
25
+
26
+ Confirm this by running:
27
+
28
+ ```
29
+ $ bosh status
30
+ $ bosh deployments
31
+ ```
32
+
33
+ The former will confirm you are targeting a bosh. The latter will display the deployments. One of which should be your Cloud Foundry.
34
+
35
+ ## Installation
36
+
37
+ Install via RubyGems:
38
+
39
+ ```
40
+ $ gem install bosh_cli "~> 1.5.0.pre" --source https://s3.amazonaws.com/bosh-jenkins-gems/
41
+ $ gem install bosh_cli_plugin_redis
42
+ ```
43
+
44
+ The `bosh_cli` gem is currently only available from S3, rather than RubyGem itself. So it needs to be installed first.
45
+
46
+ ## Usage
47
+
48
+ Each time you install the latest `redis-cf-plugin` you will want to re-upload the latest available redis release to your bosh. If no newer release is available then nothing good nor bad will occur.
49
+
50
+ ```
51
+ $ bosh prepare redis
52
+ Uploading new redis release to bosh...
53
+ ```
54
+
55
+ To create/provision a new redis service you run the following command. By default, it will select the smallest known instance size.
56
+
57
+ ```
58
+ $ bosh create redis myapp-redis
59
+ $ bosh create redis myapp-redis --size small
60
+ $ bosh create redis myapp-redis --size medium
61
+ $ bosh create redis myapp-redis --size large
62
+ $ bosh create redis myapp-redis --size xlarge
63
+ ```
64
+
65
+ NOTE: By default, the `default` security group is used. It must have port `6379` open.
66
+
67
+ To chose a different security group, use the `--security-group` option:
68
+
69
+ ```
70
+ $ bosh create redis --security-group redis-server
71
+ ```
72
+
73
+ To see the list of available instance sizes or to edit the list of available instance size, see the section "Customizing" below.
74
+
75
+ * TODO - how to show available instance sizes
76
+ * TODO - how to update a redis server to a different instance size/flavor
77
+ * TODO - how to update the persistent disk for the redis server
78
+
79
+ ## Customizing
80
+
81
+ * TODO - how to edit available instance sizes (via the bosh deployment file templates)
82
+
83
+ ## Releasing new plugin gem versions
84
+
85
+ There are two reasons to release new versions of this plugin.
86
+
87
+ 1. Package the latest [redis-boshrelease](https://github.com/cloudfoundry-community/redis-boshrelease) bosh release (which describes how the redis service is implemented)
88
+ 2. New features or bug fixes to the plugin
89
+
90
+ To package the latest "final release" of the redis bosh release into this source repository, run the following command:
91
+
92
+ ```
93
+ $ cd /path/to/releases
94
+ $ git clone https://github.com/cloudfoundry-community/redis-boshrelease.git
95
+ $ cd -
96
+ $ rake bosh:release:import[/path/to/releases/redis-boshrelease]
97
+ # for zsh shell quotes are required around rake arguments:
98
+ $ rake bosh:release:import'[/path/to/releases/redis-boshrelease]'
99
+ ```
100
+
101
+ Note: only the latest "final release" will be packaged. See https://github.com/cloudfoundry-community/redis-boshrelease#readme for information on creating new bosh releases.
102
+
103
+ To locally test the plugin (`bosh` cli loads plugins from its local path automatically):
104
+
105
+ ```
106
+ $ cf /path/to/bosh_cli_plugin_redis
107
+ $ bosh redis
108
+ ```
109
+
110
+ To release a new version of the plugin as a RubyGem:
111
+
112
+ 1. Edit `bosh_cli_plugin_redis.gemspec` to update the major or minor or patch version.
113
+ 2. Run the release command:
114
+
115
+ ```
116
+ $ rake release
117
+ ```
118
+
119
+ ## Contributing
120
+
121
+ For fixes or features to the `bosh_cli_plugin_redis` (`bosh redis`) plugin:
122
+
123
+ 1. Fork it
124
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
125
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
126
+ 4. Push to the branch (`git push origin my-new-feature`)
127
+ 5. Create new Pull Request
128
+
129
+ For fixes or features to the redis bosh release, please visit https://github.com/cloudfoundry-community/redis-boshrelease. Final releases of `redis-boshrelease` will be distributed in future gem versions of this plugin.
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ bosh_release = "redis-boshrelease"
4
+ target_bosh_release_path = File.expand_path("../bosh_release", __FILE__)
5
+
6
+ namespace :bosh do
7
+ namespace :release do
8
+ desc "Import latest #{bosh_release}"
9
+ task :import, :path do |t, args|
10
+ source_bosh_release = File.expand_path(args[:path])
11
+ unless File.directory?(source_bosh_release)
12
+ $stderr.puts "Please pass path to source bosh release"
13
+ exit 1
14
+ end
15
+
16
+ sh "rm -rf #{target_bosh_release_path}"
17
+
18
+ # required directories to pass bosh_cli validations
19
+ %w[config jobs packages src].each do |dir|
20
+ sh "mkdir -p #{target_bosh_release_path}/#{dir}"
21
+ sh "touch #{target_bosh_release_path}/#{dir}/.gitkeep"
22
+ end
23
+
24
+ chdir(target_bosh_release_path) do
25
+ sh "cp -R #{source_bosh_release}/releases #{target_bosh_release_path}"
26
+ sh "cp -R #{source_bosh_release}/templates #{target_bosh_release_path}"
27
+
28
+ sh "cp -R #{source_bosh_release}/.final_builds #{target_bosh_release_path}"
29
+ sh "cp -R #{source_bosh_release}/config/final.yml #{target_bosh_release_path}/config"
30
+ end
31
+ end
32
+
33
+ desc "Remove any large temporary tgz from internal bosh_release"
34
+ task :clean do
35
+ chdir(target_bosh_release_path) do
36
+ sh "ls .final_builds/**/*.tgz | xargs rm; true"
37
+ sh "ls releases/**/*.tgz | xargs rm; true"
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ task :release => "bosh:release:clean"
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "bosh_cli_plugin_redis"
5
+ spec.version = "0.2.0"
6
+ spec.authors = ["Dr Nic Williams"]
7
+ spec.email = ["drnicwilliams@gmail.com"]
8
+ spec.description = %q{Create dedicated Redis servers using Bosh}
9
+ spec.summary = %q{Create dedicated Redis servers using Bosh}
10
+ spec.homepage = ""
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_runtime_dependency "bosh_cli", "~> 1.5.0.pre"
19
+ spec.add_runtime_dependency "rake"
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ end
@@ -0,0 +1,7 @@
1
+ ---
2
+ builds:
3
+ !binary "ODk5Mzk1NzViM2ZkZGZlYjc4ZTk0NjNiNmI2Y2E5MDY3ZTczMDI2Zg==":
4
+ blobstore_id: 7b088545-1abf-4c52-a75d-efcc9172e04c
5
+ version: 1
6
+ sha1: !binary |-
7
+ MmRmNzYwY2I0ZGJiODdhYzE0YTBiZGMwYzBhNTU5OTc2NWViMzU2Mg==
@@ -0,0 +1,7 @@
1
+ ---
2
+ builds:
3
+ !binary "MDY3Y2QwMjVmNjFlZjAxNjI1NzFhYTg2NTQwYTE1OGMwOWE3YzM2Ng==":
4
+ blobstore_id: b51c851a-eab2-41cd-8b76-f714b1adb6bb
5
+ version: 1
6
+ sha1: !binary |-
7
+ OGJlZjUyYzQ2ZmRlNWI5ZWMwYzliYzVkY2I2YjQ2MjYxYmYzYTEwOA==
File without changes
@@ -0,0 +1,10 @@
1
+ ---
2
+ blobstore:
3
+ provider: s3
4
+ options:
5
+ bucket_name: redis-boshrelease
6
+ access_key_id: AKIAJPWUHOHV42IMTNQQ
7
+ secret_access_key: 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
8
+ encryption_key: cloudfoundry-community
9
+ min_cli_version: 1.5.0.pre.699
10
+ final_name: redis
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ ---
2
+ builds:
3
+ !binary "ZWU0YzZkYjNlY2Q2YjVkNWE4NjRlZmU5MGNiZTZiMzRmZjVmZWY5ZQ==":
4
+ version: 1
@@ -0,0 +1,20 @@
1
+ ---
2
+ packages:
3
+ - name: redis
4
+ version: 1
5
+ sha1: !binary |-
6
+ OGJlZjUyYzQ2ZmRlNWI5ZWMwYzliYzVkY2I2YjQ2MjYxYmYzYTEwOA==
7
+ fingerprint: !binary |-
8
+ MDY3Y2QwMjVmNjFlZjAxNjI1NzFhYTg2NTQwYTE1OGMwOWE3YzM2Ng==
9
+ dependencies: []
10
+ jobs:
11
+ - name: redis
12
+ version: 1
13
+ fingerprint: !binary |-
14
+ ODk5Mzk1NzViM2ZkZGZlYjc4ZTk0NjNiNmI2Y2E5MDY3ZTczMDI2Zg==
15
+ sha1: !binary |-
16
+ MmRmNzYwY2I0ZGJiODdhYzE0YTBiZGMwYzBhNTU5OTc2NWViMzU2Mg==
17
+ commit_hash: 59e77715
18
+ uncommitted_changes: true
19
+ name: redis
20
+ version: 1
File without changes
@@ -0,0 +1,16 @@
1
+ # Then target that deployment file:
2
+ #
3
+ # $ bosh deployment path/to/file/above
4
+ #
5
+ # Then apply this template:
6
+ #
7
+ # $ bosh diff templates/aws/single_vm.yml.erb
8
+ #
9
+ ---
10
+ name: NAME
11
+ director_uuid: UUID
12
+ networks: {}
13
+ properties:
14
+ redis:
15
+ resource: medium
16
+ security_group: redis-server
@@ -0,0 +1,107 @@
1
+ ---
2
+ <%-
3
+ # Example source deployment file that can be used:
4
+ # ---
5
+ # name: NAME
6
+ # director_uuid: 4ae3a0f0-70a5-4c0d-95f2-7fafaefe8b9e
7
+ # networks: {}
8
+ # properties:
9
+ # redis:
10
+ # instance_type: m1.medium
11
+ # security_groups: redis-server
12
+ #
13
+ # Then target that deployment file:
14
+ #
15
+ # $ bosh deployment path/to/file/above
16
+ #
17
+ # Then apply this template:
18
+ #
19
+ # $ bosh diff templates/aws/single_vm.yml.erb
20
+ #
21
+ redis_sg = find("properties.redis.security_group")
22
+ redis_port = 6379
23
+ redis_password = random_string 12, :redis
24
+ redis_resource = find("properties.redis.resource")
25
+ -%>
26
+ name: <%= find("name") %>
27
+ director_uuid: <%= find("director_uuid") %>
28
+
29
+ release:
30
+ name: redis
31
+ version: latest
32
+
33
+ compilation:
34
+ workers: 10
35
+ network: default
36
+ reuse_compilation_vms: true
37
+ cloud_properties:
38
+ instance_type: m1.small
39
+
40
+ update:
41
+ canaries: 1
42
+ canary_watch_time: 30000-300000
43
+ update_watch_time: 30000-300000
44
+ max_in_flight: 4
45
+ max_errors: 1
46
+
47
+ networks:
48
+ - name: default
49
+ type: dynamic
50
+ cloud_properties:
51
+ security_groups:
52
+ - <%= redis_sg %>
53
+
54
+ resource_pools:
55
+ - name: small
56
+ network: default
57
+ size: <%= redis_resource == "small" ? 1 : 0 %>
58
+ stemcell:
59
+ name: bosh-stemcell
60
+ version: latest
61
+ cloud_properties:
62
+ instance_type: m1.small
63
+
64
+ - name: medium
65
+ network: default
66
+ size: <%= redis_resource == "medium" ? 1 : 0 %>
67
+ stemcell:
68
+ name: bosh-stemcell
69
+ version: latest
70
+ cloud_properties:
71
+ instance_type: m1.medium
72
+
73
+ - name: large
74
+ network: default
75
+ size: <%= redis_resource == "large" ? 1 : 0 %>
76
+ stemcell:
77
+ name: bosh-stemcell
78
+ version: latest
79
+ cloud_properties:
80
+ instance_type: m1.large
81
+
82
+ - name: xlarge
83
+ network: default
84
+ size: <%= redis_resource == "xlarge" ? 1 : 0 %>
85
+ stemcell:
86
+ name: bosh-stemcell
87
+ version: latest
88
+ cloud_properties:
89
+ instance_type: m1.xlarge
90
+
91
+ jobs:
92
+ - name: redis
93
+ template: redis
94
+ instances: 1
95
+ resource_pool: <%= redis_resource %>
96
+ networks:
97
+ - name: default
98
+ default:
99
+ - dns
100
+ - gateway
101
+
102
+ properties:
103
+ redis:
104
+ resource: <%= redis_resource %>
105
+ security_group: <%= redis_sg %>
106
+ port: <%= redis_port %>
107
+ password: <%= redis_password %>
@@ -0,0 +1,13 @@
1
+ ---
2
+ resources:
3
+ - small
4
+ - medium
5
+ - large
6
+ - xlarge
7
+
8
+ properties:
9
+ - name: redis.resource
10
+ description: Resource/flavor of instance to use
11
+ - name: redis.security_group
12
+ description: Security group for instance(s). Must have TCP ports 22 & 6379 open.
13
+ default: default
@@ -0,0 +1,16 @@
1
+ # Then target that deployment file:
2
+ #
3
+ # $ bosh deployment path/to/file/above
4
+ #
5
+ # Then apply this template:
6
+ #
7
+ # $ bosh diff templates/openstack/single_vm.yml.erb
8
+ #
9
+ ---
10
+ name: NAME
11
+ director_uuid: UUID
12
+ networks: {}
13
+ properties:
14
+ redis:
15
+ resource: medium
16
+ security_group: redis-server
@@ -0,0 +1,107 @@
1
+ ---
2
+ <%-
3
+ # Example source deployment file that can be used:
4
+ # ---
5
+ # name: NAME
6
+ # director_uuid: 4ae3a0f0-70a5-4c0d-95f2-7fafaefe8b9e
7
+ # networks: {}
8
+ # properties:
9
+ # redis:
10
+ # instance_type: m1.medium
11
+ # security_groups: redis-server
12
+ #
13
+ # Then target that deployment file:
14
+ #
15
+ # $ bosh deployment path/to/file/above
16
+ #
17
+ # Then apply this template:
18
+ #
19
+ # $ bosh diff templates/openstack/single_vm.yml.erb
20
+ #
21
+ redis_sg = find("properties.redis.security_group")
22
+ redis_port = 6379
23
+ redis_password = random_string 12, :redis
24
+ redis_resource = find("properties.redis.resource")
25
+ -%>
26
+ name: <%= find("name") %>
27
+ director_uuid: <%= find("director_uuid") %>
28
+
29
+ release:
30
+ name: redis
31
+ version: latest
32
+
33
+ compilation:
34
+ workers: 10
35
+ network: default
36
+ reuse_compilation_vms: true
37
+ cloud_properties:
38
+ instance_type: m1.small
39
+
40
+ update:
41
+ canaries: 1
42
+ canary_watch_time: 30000-300000
43
+ update_watch_time: 30000-300000
44
+ max_in_flight: 4
45
+ max_errors: 1
46
+
47
+ networks:
48
+ - name: default
49
+ type: dynamic
50
+ cloud_properties:
51
+ security_groups:
52
+ - <%= redis_sg %>
53
+
54
+ resource_pools:
55
+ - name: small
56
+ network: default
57
+ size: <%= redis_resource == "small" ? 1 : 0 %>
58
+ stemcell:
59
+ name: bosh-stemcell
60
+ version: latest
61
+ cloud_properties:
62
+ instance_type: m1.small
63
+
64
+ - name: medium
65
+ network: default
66
+ size: <%= redis_resource == "medium" ? 1 : 0 %>
67
+ stemcell:
68
+ name: bosh-stemcell
69
+ version: latest
70
+ cloud_properties:
71
+ instance_type: m1.medium
72
+
73
+ - name: large
74
+ network: default
75
+ size: <%= redis_resource == "large" ? 1 : 0 %>
76
+ stemcell:
77
+ name: bosh-stemcell
78
+ version: latest
79
+ cloud_properties:
80
+ instance_type: m1.large
81
+
82
+ - name: xlarge
83
+ network: default
84
+ size: <%= redis_resource == "xlarge" ? 1 : 0 %>
85
+ stemcell:
86
+ name: bosh-stemcell
87
+ version: latest
88
+ cloud_properties:
89
+ instance_type: m1.xlarge
90
+
91
+ jobs:
92
+ - name: redis
93
+ template: redis
94
+ instances: 1
95
+ resource_pool: <%= redis_resource %>
96
+ networks:
97
+ - name: default
98
+ default:
99
+ - dns
100
+ - gateway
101
+
102
+ properties:
103
+ redis:
104
+ resource: <%= redis_resource %>
105
+ security_group: <%= redis_sg %>
106
+ port: <%= redis_port %>
107
+ password: <%= redis_password %>
@@ -0,0 +1,254 @@
1
+ require "yaml"
2
+
3
+ # for the #sh helper
4
+ require "rake"
5
+ require "rake/file_utils"
6
+
7
+ module Bosh::Cli::Command
8
+ class Redis < Base
9
+ include FileUtils
10
+ include Bosh::Cli::Validation
11
+
12
+ usage "redis"
13
+ desc "show micro bosh sub-commands"
14
+ def redis_help
15
+ say("bosh redis sub-commands:")
16
+ nl
17
+ cmds = Bosh::Cli::Config.commands.values.find_all {|c|
18
+ c.usage =~ /redis/
19
+ }
20
+ Bosh::Cli::Command::Help.list_commands(cmds)
21
+ end
22
+
23
+ usage "prepare redis"
24
+ desc "Prepare bosh for deploying one or more Redis services"
25
+ def prepare_redis
26
+ within_bosh_release do
27
+ # the releases/index.yml contains all the available release versions in an unordered
28
+ # hash of hashes in YAML format:
29
+ # ---
30
+ # builds:
31
+ # af61f03c5ad6327e0795402f1c458f2fc6f21201:
32
+ # version: 3
33
+ # 39c029d0af9effc6913f3333434b894ff6433638:
34
+ # version: 1
35
+ # 5f5d0a7fb577fec3c09408c94f7abbe2d52a042c:
36
+ # version: 4
37
+ # f044d47e0183f084db9dac5a6ef00d7bd21c8451:
38
+ # version: 2
39
+ release_index = YAML.load_file("releases/index.yml")
40
+ latest_version = release_index["builds"].values.inject(0) do |max_version, release|
41
+ version = release["version"]
42
+ max_version < version ? version : max_version
43
+ end
44
+
45
+ sh "bosh upload release releases/*-#{latest_version}.yml"
46
+ end
47
+ end
48
+
49
+ # TODO - size must be valid
50
+ # TODO - name must be unique (cf services & bosh deployments)
51
+
52
+ usage "create redis"
53
+ desc "Create a Redis service deployed upon target bosh"
54
+ option "--name redis-<timestamp>", String, "Unique bosh deployment name"
55
+ option "--size small", String, "Size of provisioned VMs"
56
+ option "--security-group default", String, "Security group to assign to provisioned VMs"
57
+ def create_redis
58
+ auth_required
59
+
60
+ service_name = options[:name] || default_name
61
+ resource_size = options[:size] || default_size
62
+ security_group = options[:security_group] || default_security_group
63
+ redis_port = 6379
64
+
65
+ bosh_status # preload
66
+ nl
67
+ say "CPI: #{bosh_cpi}"
68
+ say "Deployment name: #{service_name.make_green}"
69
+ say "Resource size: #{resource_size.make_green}"
70
+ say "Security group: #{security_group.make_green}"
71
+ nl
72
+ unless confirmed?("Security group exists with ports 22 & #{redis_port}")
73
+ cancel_deployment
74
+ end
75
+ unless confirmed?("Creating redis service")
76
+ cancel_deployment
77
+ end
78
+
79
+ template_file = template_file("single_vm.yml.erb")
80
+
81
+ # Create an initial deployment file; upon which the CPI-specific template will be applied below
82
+ # Initial file will look like:
83
+ # ---
84
+ # name: NAME
85
+ # director_uuid: UUID
86
+ # networks: {}
87
+ # properties:
88
+ # redis:
89
+ # resource: medium
90
+ # security_group: redis-server
91
+ deployment_file = "deployments/redis/#{service_name}.yml"
92
+ step("Checking/creating #{redis_deployments_store_path} for deployment files",
93
+ "Failed to create #{redis_deployments_store_path} for deployment files", :fatal) do
94
+ mkdir_p(redis_deployments_store_path)
95
+ end
96
+
97
+ step("Creating deployment file #{deployment_file}",
98
+ "Failed to create deployment file #{deployment_file}", :fatal) do
99
+ File.open(deployment_file, "w") do |file|
100
+ file << {
101
+ "name" => service_name,
102
+ "director_uuid" => bosh_uuid,
103
+ "networks" => {},
104
+ "properties" => {
105
+ "redis" => {
106
+ "resource" => resource_size,
107
+ "security_group" => security_group
108
+ }
109
+ }
110
+ }.to_yaml
111
+ end
112
+
113
+ stdout = Bosh::Cli::Config.output
114
+ Bosh::Cli::Config.output = nil
115
+ deployment_cmd(non_interactive: true).set_current(deployment_file)
116
+ biff_cmd(non_interactive: true).biff(template_file)
117
+ Bosh::Cli::Config.output = stdout
118
+ end
119
+ # re-set current deployment to show output
120
+ deployment_cmd.set_current(deployment_file)
121
+ deployment_cmd(non_interactive: options[:non_interactive]).perform
122
+ end
123
+
124
+ usage "show redis uri"
125
+ desc "Show the redis URI for connection via bosh DNS"
126
+ def show_redis_uri
127
+ load_bosh_and_validate_current_deployment
128
+ print service_uri
129
+ end
130
+
131
+ usage "delete redis"
132
+ desc "Delete current Redis service"
133
+ def delete_redis
134
+ load_bosh_and_validate_current_deployment
135
+ deployment_cmd(non_interactive: options[:non_interactive]).delete(deployment_name)
136
+ end
137
+
138
+ protected
139
+
140
+ def default_name
141
+ "redis-#{Time.now.to_i}"
142
+ end
143
+
144
+ def default_size
145
+ "small"
146
+ end
147
+
148
+ def default_security_group
149
+ "default"
150
+ end
151
+
152
+ def release_name
153
+ "redis"
154
+ end
155
+
156
+ def redis_deployments_store_path
157
+ "deployments/redis"
158
+ end
159
+
160
+ def bosh_release_dir
161
+ File.expand_path("../../../../../bosh_release", __FILE__)
162
+ end
163
+
164
+ def within_bosh_release(&block)
165
+ chdir(bosh_release_dir, &block)
166
+ end
167
+
168
+ def bosh_status
169
+ @bosh_status ||= begin
170
+ step("Fetching bosh information", "Cannot fetch bosh information", :fatal) do
171
+ @bosh_status = bosh_director_client.get_status
172
+ end
173
+ @bosh_status
174
+ end
175
+ end
176
+
177
+ def bosh_uuid
178
+ bosh_status["uuid"]
179
+ end
180
+
181
+ def bosh_cpi
182
+ bosh_status["cpi"]
183
+ end
184
+
185
+ def template_file(file)
186
+ File.join(bosh_release_dir, "templates", bosh_cpi, file)
187
+ end
188
+
189
+ # TODO this is now a bosh cli command itself; use #director
190
+ def bosh_director_client
191
+ director
192
+ end
193
+
194
+ def deployment_cmd(options = {})
195
+ cmd = Bosh::Cli::Command::Deployment.new
196
+ options.each do |key, value|
197
+ cmd.add_option key.to_sym, value
198
+ end
199
+ cmd
200
+ end
201
+
202
+ def biff_cmd(options = {})
203
+ cmd = Bosh::Cli::Command::Biff.new
204
+ options.each do |key, value|
205
+ cmd.add_option key.to_sym, value
206
+ end
207
+ cmd
208
+ end
209
+
210
+ # TODO this is now a bosh cli command itself
211
+ def deployment_file
212
+ @current_deployment_file ||= ::Bosh::Cli::Command::Deployment.new.deployment
213
+ end
214
+
215
+ # TODO use bosh cli helpers to validate/require this
216
+ def load_bosh_and_validate_current_deployment
217
+ auth_required
218
+ unless File.exists?(deployment_file)
219
+ err "Target deployment file no longer exists: #{deployment_file}"
220
+ end
221
+ @deployment = YAML.load_file(deployment_file)
222
+ unless @deployment["release"] && @deployment["release"]["name"] == release_name
223
+ err "Target deployment file is not for redis service: #{deployment_file}"
224
+ end
225
+ end
226
+
227
+ def deployment_name
228
+ @deployment["name"]
229
+ end
230
+
231
+ def service_uri
232
+ password = @deployment["properties"]["redis"]["password"]
233
+ port = @deployment["properties"]["redis"]["port"]
234
+ db = 0
235
+ "redis://:#{password}@#{server_host}:#{port}/#{db}"
236
+ end
237
+
238
+ # returns the first DNS entry for the running instance
239
+ def server_host
240
+ @server_host ||= begin
241
+ vms = bosh_director_client.fetch_vm_state(deployment_name, use_cache: false)
242
+ if vms.empty?
243
+ err "Deployment has no running instances"
244
+ end
245
+ if vms.size > 1
246
+ say "#{"WARNING!".make_red} Deployment has more than 1 running instance (#{vms.size}); using first instance"
247
+ end
248
+ vm = vms.first
249
+ # bug in bosh dns means old dns entries might still point to this new VM
250
+ vm["dns"].select { |dns| dns =~ %r{#{deployment_name}} }.first
251
+ end
252
+ end
253
+ end
254
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bosh_cli_plugin_redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dr Nic Williams
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bosh_cli
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.5.0.pre
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: 1.5.0.pre
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
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: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ description: Create dedicated Redis servers using Bosh
63
+ email:
64
+ - drnicwilliams@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - ChangeLog.md
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - bosh_cli_plugin_redis.gemspec
76
+ - bosh_release/.final_builds/jobs/redis/index.yml
77
+ - bosh_release/.final_builds/packages/redis/index.yml
78
+ - bosh_release/config/.gitkeep
79
+ - bosh_release/config/final.yml
80
+ - bosh_release/jobs/.gitkeep
81
+ - bosh_release/packages/.gitkeep
82
+ - bosh_release/releases/index.yml
83
+ - bosh_release/releases/redis-1.yml
84
+ - bosh_release/src/.gitkeep
85
+ - bosh_release/templates/aws/sample_deployment_file.yml
86
+ - bosh_release/templates/aws/single_vm.yml.erb
87
+ - bosh_release/templates/aws/spec
88
+ - bosh_release/templates/openstack/sample_deployment_file.yml
89
+ - bosh_release/templates/openstack/single_vm.yml.erb
90
+ - lib/bosh/cli/commands/redis.rb
91
+ homepage: ''
92
+ licenses:
93
+ - MIT
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ segments:
105
+ - 0
106
+ hash: 4389263479679262262
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ segments:
114
+ - 0
115
+ hash: 4389263479679262262
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.25
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Create dedicated Redis servers using Bosh
122
+ test_files: []