Merge pull request #217 from cheekyhalf/master master
authorGuilhem Lettron <guilhem+github@lettron.fr>
Tue, 13 Oct 2015 14:47:16 +0000 (16:47 +0200)
committerGuilhem Lettron <guilhem+github@lettron.fr>
Tue, 13 Oct 2015 14:47:16 +0000 (16:47 +0200)
fix typo in mon role

70 files changed:
.gitignore [new file with mode: 0644]
.kitchen.yml [new file with mode: 0644]
.rubocop.yml [new file with mode: 0644]
.travis.yml [new file with mode: 0644]
Berksfile [new file with mode: 0644]
CHANGELOG.md [new file with mode: 0644]
Gemfile [new file with mode: 0644]
LICENSE [new file with mode: 0644]
README.md [new file with mode: 0644]
Rakefile [new file with mode: 0644]
attributes/cephfs.rb [new file with mode: 0644]
attributes/conf.rb [new file with mode: 0644]
attributes/default.rb [new file with mode: 0644]
attributes/mds.rb [new file with mode: 0644]
attributes/mon.rb [new file with mode: 0644]
attributes/osd.rb [new file with mode: 0644]
attributes/radosgw.rb [new file with mode: 0644]
attributes/radosgw_apache2.rb [new file with mode: 0644]
attributes/repo.rb [new file with mode: 0644]
chefignore [new file with mode: 0644]
infrastructure.yml [new file with mode: 0644]
libraries/default.rb [new file with mode: 0644]
libraries/utils.rb [new file with mode: 0644]
metadata.rb [new file with mode: 0644]
providers/cephfs.rb [new file with mode: 0644]
providers/client.rb [new file with mode: 0644]
providers/pool.rb [new file with mode: 0644]
recipes/all_in_one.rb [new file with mode: 0644]
recipes/apt.rb [new file with mode: 0644]
recipes/cephfs.rb [new file with mode: 0644]
recipes/cephfs_install.rb [new file with mode: 0644]
recipes/conf.rb [new file with mode: 0644]
recipes/default.rb [new file with mode: 0644]
recipes/install.rb [new file with mode: 0644]
recipes/mds.rb [new file with mode: 0644]
recipes/mds_install.rb [new file with mode: 0644]
recipes/mon.rb [new file with mode: 0644]
recipes/mon_install.rb [new file with mode: 0644]
recipes/osd.rb [new file with mode: 0644]
recipes/osd_install.rb [new file with mode: 0644]
recipes/pools.rb [new file with mode: 0644]
recipes/radosgw.rb [new file with mode: 0644]
recipes/radosgw_apache2.rb [new file with mode: 0644]
recipes/radosgw_apache2_repo.rb [new file with mode: 0644]
recipes/radosgw_civetweb.rb [new file with mode: 0644]
recipes/radosgw_install.rb [new file with mode: 0644]
recipes/repo.rb [new file with mode: 0644]
recipes/rpm.rb [new file with mode: 0644]
recipes/tgt.rb [new file with mode: 0644]
resources/cephfs.rb [new file with mode: 0644]
resources/client.rb [new file with mode: 0644]
resources/pool.rb [new file with mode: 0644]
roles/ceph-mds.json [new file with mode: 0644]
roles/ceph-mon.json [new file with mode: 0644]
roles/ceph-osd.json [new file with mode: 0644]
roles/ceph-radosgw.json [new file with mode: 0644]
roles/ceph-tgt.json [new file with mode: 0644]
templates/default/ceph.conf.erb [new file with mode: 0644]
templates/default/mods/fastcgi.conf.erb [new file with mode: 0644]
templates/default/rgw.conf.erb [new file with mode: 0644]
templates/default/s3gw.fcgi.erb [new file with mode: 0644]
test/cookbooks/ceph_test/CHANGELOG.md [new file with mode: 0644]
test/cookbooks/ceph_test/README.md [new file with mode: 0644]
test/cookbooks/ceph_test/attributes/cephfs_mount.rb [new file with mode: 0644]
test/cookbooks/ceph_test/metadata.rb [new file with mode: 0644]
test/cookbooks/ceph_test/recipes/cephfs.rb [new file with mode: 0644]
test/integration/Vagrantfile.erb [new file with mode: 0644]
test/integration/aio/bats/ceph-running.bats [new file with mode: 0644]
test/integration/aio/bats/cephfs.bats [new file with mode: 0644]
test/integration/aio/bats/version.bats [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..b3dd71e
--- /dev/null
@@ -0,0 +1,45 @@
+*.gem
+.zero-knife.rb
+*.rbc
+.bundle
+.config
+coverage
+InstalledFiles
+lib/bundler/man
+pkg
+rdoc
+spec/reports
+test/tmp
+test/version_tmp
+tmp
+Gemfile.lock
+_Store
+*~
+*#
+.#*
+\#*#
+.*.sw[a-z]
+*.un~
+*.tmp
+*.bk
+*.bkup
+.ruby-version
+.ruby-gemset
+.rvmrc
+
+# YARD artifacts
+.yardoc
+_yardoc
+doc/
+.idea
+
+#chef stuff
+Berksfile.lock
+.kitchen
+.kitchen.local.yml
+vendor/
+.coverage/
+
+#vagrant stuff
+.vagrant/
+.vagrant.d/
diff --git a/.kitchen.yml b/.kitchen.yml
new file mode 100644 (file)
index 0000000..ae7e508
--- /dev/null
@@ -0,0 +1,67 @@
+---
+driver_plugin: vagrant
+driver_config:
+  vagrantfile_erb: test/integration/Vagrantfile.erb
+  require_chef_omnibus: true
+
+platforms:
+- name: ubuntu-12.04
+  run_list:
+    - recipe[apt]
+- name: ubuntu-14.04
+  run_list:
+    - recipe[apt]
+  attributes:
+    apache:
+      mpm: event        # ugly workaround for onehealth-cookbooks/apache2 #236
+- name: debian-7.4
+  run_list:
+    - recipe[apt]
+- name: centos-6.5
+- name: centos-5.10
+- name: fedora-18
+
+provisioner:
+    name: chef_zero
+
+suites:
+- name: default
+  run_list:
+    - "recipe[ceph::repo]"
+    - "recipe[ceph]"
+  attributes: &defaults
+    ceph:
+      config:
+        fsid: ae3f1d03-bacd-4a90-b869-1a4fabb107f2
+        mon_initial_members:
+          - "127.0.0.1"
+- name: osd
+  run_list:
+    - "role[ceph-osd]"
+  attributes: *defaults
+- name: mon
+  run_list:
+    - "role[ceph-mon]"
+  attributes: *defaults
+- name: mds
+  run_list:
+    - "role[ceph-mds]"
+  attributes: *defaults
+- name: radosgw
+  run_list:
+    - "role[ceph-radosgw]"
+  attributes: *defaults
+- name: aio
+  attributes:
+    ceph:
+      config-sections:
+        global:
+          "osd journal size" : 128
+          "osd pool default size": 1
+      osd_devices:
+        - { device: "/dev/sdb" }
+        - { device: "/dev/sdc" }
+        - { device: "/dev/sdd" }
+  run_list:
+    - recipe[ceph::all_in_one]
+    - recipe[ceph_test::cephfs]
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644 (file)
index 0000000..c739e34
--- /dev/null
@@ -0,0 +1,32 @@
+AllCops:
+  Include:
+    - Berksfile
+    - Gemfile
+    - Rakefile
+    - Thorfile
+    - Guardfile
+  Exclude:
+    - vendor/**/*
+
+ClassLength:
+  Enabled: false
+Documentation:
+  Enabled: false
+Encoding:
+  Enabled: false
+HashSyntax:
+  Enabled: false
+LineLength:
+  Enabled: false
+MethodLength:
+  Enabled: false
+SignalException:
+  Enabled: false
+TrailingComma:
+  Enabled: false
+WordArray:
+  Enabled: false
+Metrics/AbcSize:
+  Enabled: false
+Metrics/PerceivedComplexity:
+  Enabled: false
diff --git a/.travis.yml b/.travis.yml
new file mode 100644 (file)
index 0000000..232d1a5
--- /dev/null
@@ -0,0 +1,10 @@
+language: ruby
+sudo: false
+cache: bundler
+bundler_args: --without kitchen_common kitchen_vagrant
+rvm:
+  - 2.0
+  - 2.1
+  - 2.2
+script:
+  - bundle exec rake travis
diff --git a/Berksfile b/Berksfile
new file mode 100644 (file)
index 0000000..73404dc
--- /dev/null
+++ b/Berksfile
@@ -0,0 +1,8 @@
+source 'https://supermarket.chef.io'
+
+metadata
+
+group :integration do
+  cookbook 'apt'
+  cookbook 'ceph_test', path: 'test/cookbooks/ceph_test'
+end
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644 (file)
index 0000000..bd9bf1c
--- /dev/null
@@ -0,0 +1,17 @@
+ceph
+====
+
+v0.2.0 (2014-03-03)
+-------------------
+
+- Add tests and fixes related.
+- Add ceph-extra
+- Fix searching feature
+- Refactor RPM part
+- Add iscsi tgt
+
+
+v0.1.0 (2013-07-18)
+-------------------
+
+- Initial changelog
diff --git a/Gemfile b/Gemfile
new file mode 100644 (file)
index 0000000..55080da
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,19 @@
+source 'https://rubygems.org'
+
+group :lint do
+  gem 'foodcritic', '~> 4.0'
+  gem 'rubocop', '~> 0.33'
+end
+
+group :unit do
+  gem 'berkshelf',  '~> 3.2'
+  gem 'chefspec',   '~> 4.3'
+end
+
+group :kitchen_common do
+  gem 'test-kitchen', '~> 1.4'
+end
+
+group :kitchen_vagrant do
+  gem 'kitchen-vagrant', '~> 0.18'
+end
diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..c807d72
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+                              Apache License
+                        Version 2.0, January 2004
+                     http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+   "License" shall mean the terms and conditions for use, reproduction,
+   and distribution as defined by Sections 1 through 9 of this document.
+
+   "Licensor" shall mean the copyright owner or entity authorized by
+   the copyright owner that is granting the License.
+
+   "Legal Entity" shall mean the union of the acting entity and all
+   other entities that control, are controlled by, or are under common
+   control with that entity. For the purposes of this definition,
+   "control" means (i) the power, direct or indirect, to cause the
+   direction or management of such entity, whether by contract or
+   otherwise, or (ii) ownership of fifty percent (50%) or more of the
+   outstanding shares, or (iii) beneficial ownership of such entity.
+
+   "You" (or "Your") shall mean an individual or Legal Entity
+   exercising permissions granted by this License.
+
+   "Source" form shall mean the preferred form for making modifications,
+   including but not limited to software source code, documentation
+   source, and configuration files.
+
+   "Object" form shall mean any form resulting from mechanical
+   transformation or translation of a Source form, including but
+   not limited to compiled object code, generated documentation,
+   and conversions to other media types.
+
+   "Work" shall mean the work of authorship, whether in Source or
+   Object form, made available under the License, as indicated by a
+   copyright notice that is included in or attached to the work
+   (an example is provided in the Appendix below).
+
+   "Derivative Works" shall mean any work, whether in Source or Object
+   form, that is based on (or derived from) the Work and for which the
+   editorial revisions, annotations, elaborations, or other modifications
+   represent, as a whole, an original work of authorship. For the purposes
+   of this License, Derivative Works shall not include works that remain
+   separable from, or merely link (or bind by name) to the interfaces of,
+   the Work and Derivative Works thereof.
+
+   "Contribution" shall mean any work of authorship, including
+   the original version of the Work and any modifications or additions
+   to that Work or Derivative Works thereof, that is intentionally
+   submitted to Licensor for inclusion in the Work by the copyright owner
+   or by an individual or Legal Entity authorized to submit on behalf of
+   the copyright owner. For the purposes of this definition, "submitted"
+   means any form of electronic, verbal, or written communication sent
+   to the Licensor or its representatives, including but not limited to
+   communication on electronic mailing lists, source code control systems,
+   and issue tracking systems that are managed by, or on behalf of, the
+   Licensor for the purpose of discussing and improving the Work, but
+   excluding communication that is conspicuously marked or otherwise
+   designated in writing by the copyright owner as "Not a Contribution."
+
+   "Contributor" shall mean Licensor and any individual or Legal Entity
+   on behalf of whom a Contribution has been received by Licensor and
+   subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   copyright license to reproduce, prepare Derivative Works of,
+   publicly display, publicly perform, sublicense, and distribute the
+   Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+   this License, each Contributor hereby grants to You a perpetual,
+   worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+   (except as stated in this section) patent license to make, have made,
+   use, offer to sell, sell, import, and otherwise transfer the Work,
+   where such license applies only to those patent claims licensable
+   by such Contributor that are necessarily infringed by their
+   Contribution(s) alone or by combination of their Contribution(s)
+   with the Work to which such Contribution(s) was submitted. If You
+   institute patent litigation against any entity (including a
+   cross-claim or counterclaim in a lawsuit) alleging that the Work
+   or a Contribution incorporated within the Work constitutes direct
+   or contributory patent infringement, then any patent licenses
+   granted to You under this License for that Work shall terminate
+   as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+   Work or Derivative Works thereof in any medium, with or without
+   modifications, and in Source or Object form, provided that You
+   meet the following conditions:
+
+   (a) You must give any other recipients of the Work or
+       Derivative Works a copy of this License; and
+
+   (b) You must cause any modified files to carry prominent notices
+       stating that You changed the files; and
+
+   (c) You must retain, in the Source form of any Derivative Works
+       that You distribute, all copyright, patent, trademark, and
+       attribution notices from the Source form of the Work,
+       excluding those notices that do not pertain to any part of
+       the Derivative Works; and
+
+   (d) If the Work includes a "NOTICE" text file as part of its
+       distribution, then any Derivative Works that You distribute must
+       include a readable copy of the attribution notices contained
+       within such NOTICE file, excluding those notices that do not
+       pertain to any part of the Derivative Works, in at least one
+       of the following places: within a NOTICE text file distributed
+       as part of the Derivative Works; within the Source form or
+       documentation, if provided along with the Derivative Works; or,
+       within a display generated by the Derivative Works, if and
+       wherever such third-party notices normally appear. The contents
+       of the NOTICE file are for informational purposes only and
+       do not modify the License. You may add Your own attribution
+       notices within Derivative Works that You distribute, alongside
+       or as an addendum to the NOTICE text from the Work, provided
+       that such additional attribution notices cannot be construed
+       as modifying the License.
+
+   You may add Your own copyright statement to Your modifications and
+   may provide additional or different license terms and conditions
+   for use, reproduction, or distribution of Your modifications, or
+   for any such Derivative Works as a whole, provided Your use,
+   reproduction, and distribution of the Work otherwise complies with
+   the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+   any Contribution intentionally submitted for inclusion in the Work
+   by You to the Licensor shall be under the terms and conditions of
+   this License, without any additional terms or conditions.
+   Notwithstanding the above, nothing herein shall supersede or modify
+   the terms of any separate license agreement you may have executed
+   with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+   names, trademarks, service marks, or product names of the Licensor,
+   except as required for reasonable and customary use in describing the
+   origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+   agreed to in writing, Licensor provides the Work (and each
+   Contributor provides its Contributions) on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+   implied, including, without limitation, any warranties or conditions
+   of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+   PARTICULAR PURPOSE. You are solely responsible for determining the
+   appropriateness of using or redistributing the Work and assume any
+   risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+   whether in tort (including negligence), contract, or otherwise,
+   unless required by applicable law (such as deliberate and grossly
+   negligent acts) or agreed to in writing, shall any Contributor be
+   liable to You for damages, including any direct, indirect, special,
+   incidental, or consequential damages of any character arising as a
+   result of this License or out of the use or inability to use the
+   Work (including but not limited to damages for loss of goodwill,
+   work stoppage, computer failure or malfunction, or any and all
+   other commercial damages or losses), even if such Contributor
+   has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+   the Work or Derivative Works thereof, You may choose to offer,
+   and charge a fee for, acceptance of support, warranty, indemnity,
+   or other liability obligations and/or rights consistent with this
+   License. However, in accepting such obligations, You may act only
+   on Your own behalf and on Your sole responsibility, not on behalf
+   of any other Contributor, and only if You agree to indemnify,
+   defend, and hold each Contributor harmless for any liability
+   incurred by, or claims asserted against, such Contributor by reason
+   of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+   To apply the Apache License to your work, attach the following
+   boilerplate notice, with the fields enclosed by brackets "[]"
+   replaced with your own identifying information. (Don't include
+   the brackets!)  The text should be enclosed in the appropriate
+   comment syntax for the file format. We also recommend that a
+   file or class name and description of purpose be included on the
+   same "printed page" as the copyright notice for easier
+   identification within third-party archives.
+
+Copyright 2011-2015, Red Hat, Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..f7a6e7c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,240 @@
+# Chef cookbook [![Build Status](https://travis-ci.org/ceph/ceph-cookbook.svg?branch=master)](https://travis-ci.org/ceph/ceph-cookbook) [![Gitter chat](https://badges.gitter.im/ceph/ceph-cookbook.png)](https://gitter.im/ceph/ceph-cookbook)
+
+## DESCRIPTION
+
+Installs and configures Ceph, a distributed network storage and filesystem designed to provide excellent performance, reliability, and scalability.
+
+The current version is focused towards deploying Monitors and OSD on Ubuntu.
+
+For documentation on how to use this cookbook, refer to the [USAGE](#USAGE) section.
+
+For help, use [Gitter chat](https://gitter.im/ceph/ceph-cookbook), [mailing-list](mailto:ceph-users-join@lists.ceph.com) or [issues](https://github.com/ceph/ceph-cookbook/issues)
+
+## REQUIREMENTS
+
+### Chef
+
+\>= 11.6.0
+
+### Platform
+
+Tested as working:
+
+* Debian Wheezy (7)
+* Ubuntu Precise (12.04)
+* Ubuntu Trusty (14.04)
+
+### Cookbooks
+
+The ceph cookbook requires the following cookbooks from Chef:
+
+https://supermarket.chef.io/
+
+* [apt](https://supermarket.chef.io/cookbooks/apt)
+* [apache2](https://supermarket.chef.io/cookbooks/apache2)
+
+## TEMPLATES
+
+## USAGE
+
+Ceph cluster design is beyond the scope of this README, please turn to the
+public wiki, mailing lists, visit our IRC channel, or contact Inktank:
+
+http://ceph.com/docs/master
+http://ceph.com/resources/mailing-list-irc/
+http://www.inktank.com/
+
+This cookbook can be used to implement a chosen cluster design. Most of the configuration is retrieved from node attributes, which can be set by an environment or by a wrapper cookbook. A basic cluster configuration will need most of the following attributes:
+
+* `node['ceph']['config']['fsid']` - the cluster UUID
+* `node['ceph']['config]'['global']['public network']` - a CIDR specification of the public network
+* `node['ceph']['config]'['global']['cluster network']` - a CIDR specification of a separate cluster replication network
+* `node['ceph']['config]'['global']['rgw dns name']` -  the main domain of the radosgw daemon
+
+Most notably, the configuration does _NOT_ need to set the `mon_initial_members`, because the cookbook does a node search to find other mons in the same environment.
+
+The other set of attributes that this recipe needs is `node['ceph']['osd_devices']`, which is an array of OSD definitions, similar to the following:
+
+* {'device' => '/dev/sdb'} - Use a full disk for the OSD, with a small partition for the journal
+* {'type' => 'directory', 'device' => '/src/node/sdb1/ceph'} - Use a directory, and have a small file for the journal
+* {'device' => '/dev/sde', 'dmcrypt' => true} - Store the data encrypted by passing --dmcrypt to `ceph-disk-prepare`
+* {'device' => '/dev/sdc', 'journal' => '/dev/sdd2'} - use a full disk for the OSD with a custom partition for the journal
+
+### Using a Policy Wrapper Cookbook
+
+To automate setting several of these node attributes, it is recommended to use a policy wrapper cookbook. This allows the ability to use Chef Server cookbook versions along with environment version restrictions to roll out configuration changes in an ordered fashion.
+
+It also can help with automating some settings. For example, a wrapper cookbook could peek at the list of harddrives that ohai has found and populate node['ceph']['osd_devices'] accordingly, instead of manually typing them all in:
+
+```ruby
+node.override['ceph']['osd_devices'] = node['block_device'].each.reject{ |name, data| name !~ /^sd[b-z]/}.sort.map { |name, data| {'journal' => "/dev/#{name}"} }
+```
+
+For best results, the wrapper cookbook's recipe should be placed before the Ceph cookbook in the node's runlist. This will ensure that any attributes are in place before the Ceph cookbook runs and consumes those attributes.
+
+### Ceph Monitor
+
+Ceph monitor nodes should use the ceph-mon role.
+
+Includes:
+
+* ceph::default
+
+### Ceph Metadata Server
+
+Ceph metadata server nodes should use the ceph-mds role.
+
+Includes:
+
+* ceph::default
+
+### Ceph OSD
+
+Ceph OSD nodes should use the ceph-osd role
+
+Includes:
+
+* ceph::default
+
+### Ceph Rados Gateway
+
+Ceph Rados Gateway nodes should use the ceph-radosgw role
+
+## ATTRIBUTES
+
+### General
+
+* `node['ceph']['search_environment']` - a custom Chef environment to search when looking for mon nodes. The cookbook defaults to searching the current environment
+* `node['ceph']['branch']` - selects whether to install the stable, testing, or dev version of Ceph
+* `node['ceph']['version']` - install a version of Ceph that is different than the cookbook default. If this is changed in a wrapper cookbook, some repository urls may also need to be replaced, and they are found in attributes/repo.rb. If the branch attribute is set to dev, this selects the gitbuilder branch to install
+* `node['ceph']['extras_repo']` - whether to install the ceph extras repo. The tgt recipe requires this
+
+* `node['ceph']['config']['fsid']` - the cluster UUID
+* `node['ceph']['config']['global']['public network']` - a CIDR specification of the public network
+* `node['ceph']['config']['global']['cluster network']` - a CIDR specification of a separate cluster replication network
+* `node['ceph']['config']['config-sections']` - add to this hash to add extra config sections to the ceph.conf
+
+* `node['ceph']['user_pools']` - an array of pool definitions, with attributes `name`, `pg_num` and `create_options` (optional), that are automatically created when a monitor is deployed
+
+### Ceph MON
+
+* `node['ceph']['config']['mon']` - a hash of settings to save in ceph.conf in the [mon] section, such as `'mon osd nearfull ratio' => '0.70'`
+
+### Ceph OSD
+
+* `node['ceph']['osd_devices']` - an array of OSD definitions for the current node
+* `node['ceph']['config']['osd']` - a hash of settings to save in ceph.conf in the [osd] section, such as `'osd max backfills' => 2`
+* `node['ceph']['config']['osd']['osd crush location']` - this attribute can be set on a per-node basis to maintain Crush map locations
+
+### Ceph MDS
+
+* `node['ceph']['config']['mds']` - a hash of settings to save in ceph.conf in the [mds] section, such as `'mds cache size' => '100000'`
+* `node['ceph']['cephfs_mount']` - where the cephfs recipe should mount CephFS
+* `node['ceph']['cephfs_use_fuse']` - whether the cephfs recipe should use the fuse cephfs client. It will default to heuristics based on the kernel version
+
+### Ceph Rados Gateway
+
+* `node['ceph']['radosgw']['api_fqdn']` - what vhost to configure in the web server
+* `node['ceph']['radosgw']['admin_email']` - the admin email address to configure in the web server
+* `node['ceph']['radosgw']['rgw_addr']` - the web server's bind address, such as *:80
+* `node['ceph']['radosgw']['rgw_port']` - if set, connects to the radosgw fastcgi over this port instead of a unix socket
+* `node['ceph']['radosgw']['webserver_companion']` - defaults to 'apache2', but it can be set to 'civetweb', or to false in order to leave it unconfigured
+* `node['ceph']['radosgw']['path']` - where to save the s3gw.fcgi file
+* `node['ceph']['config']['global']['rgw dns name']` -  the main domain of the radosgw daemon, to calculate the bucket name from a subdomain
+
+## Resources/Providers
+
+### ceph\_client
+
+The ceph\_client LWRP provides an easy way to construct a Ceph client key. These keys are needed by anything that needs to talk to the Ceph cluster, including RadosGW, CephFS, and RBD access.
+
+#### Actions
+
+- :add - creates a client key with the given parameters
+
+#### Parameters
+
+- :name - name attribute. The name of the client key to create. This is used to provide a default for the other parameters
+- :caps - A hash of capabilities that should be granted to the client key. Defaults to `{ 'mon' => 'allow r', 'osd' => 'allow r' }`
+- :as\_keyring - Whether the key should be saved in a keyring format or a simple secret key. Defaults to true, meaning it is saved as a keyring
+- :keyname - The key name to register in Ceph. Defaults to `client.#{name}.#{hostname}`
+- :filename - Where to save the key. Defaults to `/etc/ceph/ceph.client.#{name}.#{hostname}.keyring` if `as_keyring` and `/etc/ceph/ceph.client.#{name}.#{hostname}.secret` if not `as_keyring`
+- :owner - Which owner should own the saved key file. Defaults to root
+- :group - Which group should own the saved key file. Defaults to root
+- :mode - What file mode should be applied. Defaults to '00640'
+
+### ceph\_cephfs
+
+The ceph\_cephfs LWRP provides an easy way to mount CephFS. It will automatically create a Ceph client key for the machine and mount CephFS to the specified location. If the kernel client is used, instead of the fuse client, a pre-existing subdirectory of CephFS can be mounted instead of the root.
+
+#### Actions
+
+- :mount - mounts CephFS
+- :umount - unmounts CephFS
+- :remount - remounts CephFS
+- :enable - adds an fstab entry to mount CephFS
+- :disable - removes an fstab entry to mount CephFS
+
+#### Parameters
+
+- :directory - name attribute. Where to mount CephFS in the local filesystem
+- :use\_fuse - whether to use ceph-fuse or the kernel client to mount the filesystem. ceph-fuse is updated more often, but the kernel client allows for subdirectory mounting. Defaults to true
+- :cephfs\_subdir - which CephFS subdirectory to mount. Defaults to '/'. An exception will be thrown if this option is set to anything other than '/' if use\_fuse is also true
+
+### ceph\_pool
+
+The ceph\_pool LWRP provides an easy way to create and delete Ceph pools.
+
+It assumes that connectivity to the cluster is setup and that admin credentials are available from default locations, e.g. /etc/ceph/ceph.client.admin.keyring.
+
+#### Actions
+
+- :add - creates a pool with the given number of placement groups
+- :delete - deletes an existing pool
+
+#### Parameters
+
+- :name - the name of the pool to create or delete
+- :pg_num - number of placement groups, when creating a new pool
+- :create_options - arguments for pool creation (optional)
+- :force - force the deletion of an exiting pool along with any data that is stored in it
+
+## DEVELOPING
+
+### Style Guide
+
+This cookbook requires a style guide for all contributions. Travis will automatically verify that every Pull Request follows the style guide.
+
+1. Install [ChefDK](http://downloads.chef.io/chef-dk/)
+2. Activate ChefDK's copy of ruby: `eval "$(chef shell-init bash)"`
+3. `bundle install`
+4. `bundle exec rake style`
+
+### Testing
+
+This cookbook uses Test Kitchen to verify functionality. A Pull Request can't be merged if it causes any of the test configurations to fail.
+
+1. Install [ChefDK](http://downloads.chef.io/chef-dk/)
+2. Activate ChefDK's copy of ruby: `eval "$(chef shell-init bash)"`
+3. `bundle install`
+4. `bundle exec kitchen test aio-debian-74`
+5. `bundle exec kitchen test aio-ubuntu-1204`
+6. `bundle exec kitchen test aio-ubuntu-1404`
+
+## LICENSE AND AUTHORS
+
+* Author: Kyle Bader <kyle.bader@dreamhost.com>
+
+* Copyright 2013, DreamHost Web Hosting and Inktank Storage Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/Rakefile b/Rakefile
new file mode 100644 (file)
index 0000000..4a798ce
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,48 @@
+#!/usr/bin/env rake
+
+# Style tests. Rubocop and Foodcritic
+namespace :style do
+  begin
+    require 'rubocop/rake_task'
+    desc 'Run Ruby style checks'
+    RuboCop::RakeTask.new(:ruby)
+  rescue LoadError
+    puts '>>>>> Rubocop gem not loaded, omitting tasks' unless ENV['CI']
+  end
+
+  begin
+    require 'foodcritic'
+
+    desc 'Run Chef style checks'
+    FoodCritic::Rake::LintTask.new(:chef) do |t|
+      t.options = {
+        fail_tags: ['any'],
+        tags: ['~FC003'],
+        chef_version: '11.6.0'
+      }
+    end
+  rescue LoadError
+    puts '>>>>> foodcritic gem not loaded, omitting tasks' unless ENV['CI']
+  end
+end
+
+desc 'Run all style checks'
+task style: ['style:chef', 'style:ruby']
+
+# Integration tests. Kitchen.ci
+namespace :integration do
+  begin
+    require 'kitchen/rake_tasks'
+
+    desc 'Run kitchen integration tests'
+    Kitchen::RakeTasks.new
+  rescue LoadError
+    puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI']
+  end
+end
+
+desc 'Run all tests on Travis'
+task travis: ['style']
+
+# Default
+task default: ['style', 'integration:kitchen:all']
diff --git a/attributes/cephfs.rb b/attributes/cephfs.rb
new file mode 100644 (file)
index 0000000..0ca75f8
--- /dev/null
@@ -0,0 +1,13 @@
+default['ceph']['cephfs_mount'] = '/ceph'
+default['ceph']['cephfs_use_fuse'] = nil # whether the recipe's fuse mount uses cephfs-fuse instead of kernel client, defaults to heuristics
+
+case node['platform_family']
+when 'debian'
+  packages = ['ceph-fs-common', 'ceph-fuse']
+  packages += debug_packages(packages) if node['ceph']['install_debug']
+  default['ceph']['cephfs']['packages'] = packages
+when 'rhel', 'fedora', 'suse'
+  default['ceph']['cephfs']['packages'] = ['ceph-fuse']
+else
+  default['ceph']['cephfs']['packages'] = []
+end
diff --git a/attributes/conf.rb b/attributes/conf.rb
new file mode 100644 (file)
index 0000000..8836945
--- /dev/null
@@ -0,0 +1,3 @@
+default['ceph']['config'] = {}
+default['ceph']['config-sections'] = {}
+default['ceph']['search_environment'] = true
diff --git a/attributes/default.rb b/attributes/default.rb
new file mode 100644 (file)
index 0000000..2b7e541
--- /dev/null
@@ -0,0 +1,26 @@
+default['ceph']['install_debug'] = false
+default['ceph']['encrypted_data_bags'] = false
+
+default['ceph']['install_repo'] = true
+
+default['ceph']['user_pools'] = []
+
+case node['platform']
+when 'ubuntu'
+  default['ceph']['init_style'] = 'upstart'
+else
+  default['ceph']['init_style'] = 'sysvinit'
+end
+
+case node['platform_family']
+when 'debian'
+  packages = ['ceph-common']
+  packages += debug_packages(packages) if node['ceph']['install_debug']
+  default['ceph']['packages'] = packages
+when 'rhel', 'fedora'
+  packages = ['ceph']
+  packages += debug_packages(packages) if node['ceph']['install_debug']
+  default['ceph']['packages'] = packages
+else
+  default['ceph']['packages'] = []
+end
diff --git a/attributes/mds.rb b/attributes/mds.rb
new file mode 100644 (file)
index 0000000..54c21cd
--- /dev/null
@@ -0,0 +1,12 @@
+include_attribute 'ceph'
+
+default['ceph']['mds']['init_style'] = node['init_style']
+
+case node['platform_family']
+when 'debian'
+  packages = ['ceph-mds']
+  packages += debug_packages(packages) if node['ceph']['install_debug']
+  default['ceph']['mds']['packages'] = packages
+else
+  default['ceph']['mds']['packages'] = []
+end
diff --git a/attributes/mon.rb b/attributes/mon.rb
new file mode 100644 (file)
index 0000000..5d146e6
--- /dev/null
@@ -0,0 +1,14 @@
+include_attribute 'ceph'
+
+default['ceph']['mon']['init_style'] = node['ceph']['init_style']
+
+default['ceph']['mon']['secret_file'] = '/etc/chef/secrets/ceph_mon'
+
+case node['platform_family']
+when 'debian', 'rhel', 'fedora'
+  packages = ['ceph']
+  packages += debug_packages(packages) if node['ceph']['install_debug']
+  default['ceph']['mon']['packages'] = packages
+else
+  default['ceph']['mon']['packages'] = []
+end
diff --git a/attributes/osd.rb b/attributes/osd.rb
new file mode 100644 (file)
index 0000000..addbcce
--- /dev/null
@@ -0,0 +1,14 @@
+include_attribute 'ceph'
+
+default['ceph']['osd']['init_style'] = node['ceph']['init_style']
+
+default['ceph']['osd']['secret_file'] = '/etc/chef/secrets/ceph_osd'
+
+case node['platform_family']
+when 'debian', 'rhel', 'fedora'
+  packages = ['ceph']
+  packages += debug_packages(packages) if node['ceph']['install_debug']
+  default['ceph']['osd']['packages'] = packages
+else
+  default['ceph']['osd']['packages'] = []
+end
diff --git a/attributes/radosgw.rb b/attributes/radosgw.rb
new file mode 100644 (file)
index 0000000..246f744
--- /dev/null
@@ -0,0 +1,45 @@
+#
+# Cookbook Name:: ceph
+# Attributes:: radosgw
+#
+# Copyright 2011, DreamHost Web Hosting
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include_attribute 'ceph'
+
+default['ceph']['radosgw']['api_fqdn'] = 'localhost'
+default['ceph']['radosgw']['admin_email'] = 'admin@example.com'
+default['ceph']['radosgw']['rgw_addr'] = '*:80'
+default['ceph']['radosgw']['rgw_port'] = false
+default['ceph']['radosgw']['webserver_companion'] = 'apache2' # can be civetweb or false
+default['ceph']['radosgw']['use_apache_fork'] = true
+default['ceph']['radosgw']['init_style'] = node['ceph']['init_style']
+
+default['ceph']['radosgw']['path'] = '/var/www'
+
+if node['platform_family'] == 'suse'
+  default['ceph']['radosgw']['path'] = '/srv/www/ceph-radosgw'
+end
+
+case node['platform_family']
+when 'debian'
+  packages = ['radosgw']
+  packages += debug_packages(packages) if node['ceph']['install_debug']
+  default['ceph']['radosgw']['packages'] = packages
+when 'rhel', 'fedora', 'suse'
+  default['ceph']['radosgw']['packages'] = ['ceph-radosgw']
+else
+  default['ceph']['radosgw']['packages'] = []
+end
diff --git a/attributes/radosgw_apache2.rb b/attributes/radosgw_apache2.rb
new file mode 100644 (file)
index 0000000..79d6d45
--- /dev/null
@@ -0,0 +1,8 @@
+case node['platform_family']
+when 'debian'
+  default['ceph']['radosgw']['apache2']['packages'] = ['libapache2-mod-fastcgi']
+when 'suse'
+  default['ceph']['radosgw']['apache2']['packages'] = ['apache2-mod_fastcgi', 'apache2-worker']
+when 'rhel', 'fedora'
+  default['ceph']['radosgw']['apache2']['packages'] = ['mod_fastcgi']
+end
diff --git a/attributes/repo.rb b/attributes/repo.rb
new file mode 100644 (file)
index 0000000..f215493
--- /dev/null
@@ -0,0 +1,52 @@
+default['ceph']['branch'] = 'stable' # Can be stable, testing or dev.
+# Major release version to install or gitbuilder branch
+default['ceph']['version'] = 'firefly'
+default['ceph']['el_add_epel'] = true
+default['ceph']['repo_url'] = 'http://ceph.com'
+default['ceph']['extras_repo_url'] = 'http://ceph.com/packages/ceph-extras'
+default['ceph']['extras_repo'] = false
+
+case node['platform_family']
+when 'debian'
+  # Debian/Ubuntu default repositories
+  default['ceph']['debian']['stable']['repository'] = "#{node['ceph']['repo_url']}/debian-#{node['ceph']['version']}/"
+  default['ceph']['debian']['stable']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc'
+  default['ceph']['debian']['testing']['repository'] = "#{node['ceph']['repo_url']}/debian-testing/"
+  default['ceph']['debian']['testing']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc'
+  default['ceph']['debian']['dev']['repository'] = "http://gitbuilder.ceph.com/ceph-deb-#{node['lsb']['codename']}-x86_64-basic/ref/#{node['ceph']['version']}"
+  default['ceph']['debian']['dev']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/autobuild.asc'
+  default['ceph']['debian']['extras']['repository'] = "#{node['ceph']['extras_repo_url']}/debian/"
+  default['ceph']['debian']['extras']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc'
+when 'rhel'
+  # Redhat/CentOS default repositories
+  default['ceph']['rhel']['stable']['repository'] = "#{node['ceph']['repo_url']}/rpm-#{node['ceph']['version']}/el6/x86_64/"
+  default['ceph']['rhel']['stable']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc'
+  default['ceph']['rhel']['testing']['repository'] = "#{node['ceph']['repo_url']}/rpm-testing/el6/x86_64/"
+  default['ceph']['rhel']['testing']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc'
+  default['ceph']['rhel']['dev']['repository'] = "http://gitbuilder.ceph.com/ceph-rpm-centos6-x86_64-basic/ref/#{node['ceph']['version']}/x86_64/"
+  default['ceph']['rhel']['dev']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/autobuild.asc'
+  default['ceph']['rhel']['extras']['repository'] = "#{node['ceph']['extras_repo_url']}/rpm/rhel6/x86_64/"
+  default['ceph']['rhel']['extras']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc'
+when 'fedora'
+  # Fedora default repositories
+  default['ceph']['fedora']['stable']['repository'] = "#{node['ceph']['repo_url']}/rpm-#{node['ceph']['version']}/fc#{node['platform_version']}/x86_64/"
+  default['ceph']['fedora']['stable']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc'
+  default['ceph']['fedora']['testing']['repository'] = "#{node['ceph']['repo_url']}/rpm-testing/fc#{node['platform_version']}/x86_64/"
+  default['ceph']['fedora']['testing']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc'
+  default['ceph']['fedora']['dev']['repository'] = "http://gitbuilder.ceph.com/ceph-rpm-fc#{node['platform_version']}-x86_64-basic/ref/#{node['ceph']['version']}/RPMS/x86_64/"
+  default['ceph']['fedora']['dev']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/autobuild.asc'
+  default['ceph']['fedora']['extras']['repository'] = "#{node['ceph']['extras_repo_url']}/rpm/fedora#{node['platform_version']}/x86_64/"
+  default['ceph']['fedora']['extras']['repository_key'] = 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc'
+when 'suse'
+  # (Open)SuSE default repositories
+  # Chef doesn't make a difference between suse and opensuse
+  suse = Mixlib::ShellOut.new("head -n1 /etc/SuSE-release| awk '{print $1}'").run_command.stdout.chomp.downcase
+  suse = 'sles' if suse == 'suse'
+  suse_version = suse << Mixlib::ShellOut.new("grep VERSION /etc/SuSE-release | awk -F'= ' '{print $2}'").run_command.stdout.chomp
+
+  default['ceph']['suse']['stable']['repository'] = "#{node['ceph']['repo_url']}/rpm-#{node['ceph']['version']}/#{suse_version}/x86_64/ceph-release-1-0.#{suse_version}.noarch.rpm"
+  default['ceph']['suse']['testing']['repository'] = "#{node['ceph']['repo_url']}/rpm-testing/#{suse_version}/x86_64/ceph-release-1-0.#{suse_version}.noarch.rpm"
+  default['ceph']['suse']['extras']['repository'] = "#{node['ceph']['extras_repo_url']}/rpm/#{suse_version}/x86_64/"
+else
+  fail "#{node['platform_family']} is not supported"
+end
diff --git a/chefignore b/chefignore
new file mode 100644 (file)
index 0000000..e403950
--- /dev/null
@@ -0,0 +1,100 @@
+# Put files/directories that should be ignored in this file when uploading
+# or sharing to the community site.
+# Lines that start with '# ' are comments.
+
+# OS generated files #
+######################
+.DS_Store
+Icon?
+nohup.out
+ehthumbs.db
+Thumbs.db
+
+# SASS #
+########
+.sass-cache
+
+# EDITORS #
+###########
+\#*
+.#*
+*~
+*.sw[a-z]
+*.bak
+REVISION
+TAGS*
+tmtags
+*_flymake.*
+*_flymake
+*.tmproj
+.project
+.settings
+mkmf.log
+
+## COMPILED ##
+##############
+a.out
+*.o
+*.pyc
+*.so
+*.com
+*.class
+*.dll
+*.exe
+*/rdoc/
+
+# Testing #
+###########
+.watchr
+.rspec
+spec/*
+spec/fixtures/*
+test/*
+features/*
+examples/*
+Guardfile
+Procfile
+
+# SCM #
+#######
+.git
+*/.git
+.gitignore
+.gitmodules
+.gitconfig
+.gitattributes
+.svn
+*/.bzr/*
+*/.hg/*
+*/.svn/*
+
+# Berkshelf #
+#############
+Berksfile
+Berksfile.lock
+cookbooks/*
+tmp
+
+# Cookbooks #
+#############
+CONTRIBUTING
+CHANGELOG*
+
+# Strainer #
+############
+Colanderfile
+Strainerfile
+.colander
+.strainer
+
+# Vagrant #
+###########
+.vagrant
+Vagrantfile
+
+# Travis #
+##########
+.travis.yml
+test/
+spec/
+examples/
diff --git a/infrastructure.yml b/infrastructure.yml
new file mode 100644 (file)
index 0000000..de8655b
--- /dev/null
@@ -0,0 +1,6 @@
+roles:
+- ceph-mds:
+- ceph-mon:
+- ceph-osd:
+- ceph-radosgw:
+- ceph-tgt:
diff --git a/libraries/default.rb b/libraries/default.rb
new file mode 100644 (file)
index 0000000..297da37
--- /dev/null
@@ -0,0 +1,184 @@
+require 'json'
+
+def crowbar?
+  !defined?(Chef::Recipe::Barclamp).nil?
+end
+
+def mon_env_search_string
+  if crowbar?
+    mon_roles = search(:role, 'name:crowbar-* AND run_list:role\[ceph-mon\]')
+    unless mon_roles.empty?
+      search_string = mon_roles.map { |role_object| 'roles:' + role_object.name }.join(' OR ')
+      search_string = "(#{search_string}) AND ceph_config_environment:#{node['ceph']['config']['environment']}"
+    end
+  else
+    search_string = 'ceph_is_mon:true'
+    if node['ceph']['search_environment'].is_a?(String)
+      # search for nodes with this particular env
+      search_string += " AND chef_environment:#{node['ceph']['search_environment']}"
+    elsif node['ceph']['search_environment']
+      # search for any nodes with this environment
+      search_string += " AND chef_environment:#{node.chef_environment}"
+      # search for any mon nodes
+    end
+  end
+  search_string
+end
+
+def mon_nodes
+  search_string = mon_env_search_string
+
+  if use_cephx? && !node['ceph']['encrypted_data_bags']
+    search_string = "(#{search_string}) AND (ceph_bootstrap_osd_key:*)"
+  end
+  search(:node, search_string)
+end
+
+def osd_secret
+  if node['ceph']['encrypted_data_bags']
+    secret = Chef::EncryptedDataBagItem.load_secret(node['ceph']['osd']['secret_file'])
+    return Chef::EncryptedDataBagItem.load('ceph', 'osd', secret)['secret']
+  elsif node['ceph']['bootstrap_osd_key']
+    return node['ceph']['bootstrap_osd_key']
+  else
+    return mon_nodes[0]['ceph']['bootstrap_osd_key']
+  end
+end
+
+# If public_network is specified with one or more networks, we need to
+# search for a matching monitor IP in the node environment.
+# 1. For each public network specified:
+#    a. We look if the network is IPv6 or IPv4
+#    b. We look for a route matching the network
+#    c. If we found match, we return the IP with the port
+def find_node_ip_in_network(network, nodeish = nil)
+  require 'netaddr'
+  nodeish = node unless nodeish
+  network.split(/\s*,\s*/).each do |n|
+    net = NetAddr::CIDR.create(n)
+    nodeish['network']['interfaces'].each do |_iface, addrs|
+      addresses = addrs['addresses'] || []
+      addresses.each do |ip, params|
+        return ip_address_to_ceph_address(ip, params) if ip_address_in_network?(ip, params, net)
+      end
+    end
+  end
+  nil
+end
+
+def ip_address_in_network?(ip, params, net)
+  # Find the IP on this interface that matches the public_network
+  # Uses a few heuristics to find the primary IP that ceph would bind to
+  # Most secondary IPs never have a broadcast value set
+  # Other secondary IPs have a prefix of /32
+  # Match the prefix that we want from the public_network prefix
+  if params['family'] == 'inet' && net.version == 4
+    ip4_address_in_network?(ip, params, net)
+  elsif params['family'] == 'inet6' && net.version == 6
+    ip6_address_in_network?(ip, params, net)
+  else
+    false
+  end
+end
+
+def ip4_address_in_network?(ip, params, net)
+  net.contains?(ip) && params.key?('broadcast') && params['prefixlen'].to_i == net.bits
+end
+
+def ip6_address_in_network?(ip, params, net)
+  net.contains?(ip) && params['prefixlen'].to_i == net.bits
+end
+
+def ip_address_to_ceph_address(ip, params)
+  if params['family'].eql?('inet')
+    return "#{ip}:6789"
+  elsif params['family'].eql?('inet6')
+    return "[#{ip}]:6789"
+  end
+end
+
+def mon_addresses
+  mon_ips = []
+
+  if File.exist?("/var/run/ceph/ceph-mon.#{node['hostname']}.asok")
+    mon_ips = quorum_members_ips
+  else
+    mons = []
+    # make sure if this node runs ceph-mon, it's always included even if
+    # search is laggy; put it first in the hopes that clients will talk
+    # primarily to local node
+    mons << node if node['ceph']['is_mon']
+
+    mons += mon_nodes
+    if crowbar?
+      mon_ips = mons.map { |node| Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, 'admin').address }
+    else
+      if node['ceph']['config']['global'] && node['ceph']['config']['global']['public network']
+        mon_ips = mons.map { |nodeish| find_node_ip_in_network(node['ceph']['config']['global']['public network'], nodeish) }
+      else
+        mon_ips = mons.map { |node| node['ipaddress'] + ':6789' }
+      end
+    end
+  end
+  mon_ips.reject(&:nil?).uniq
+end
+
+def mon_secret
+  if node['ceph']['encrypted_data_bags']
+    secret = Chef::EncryptedDataBagItem.load_secret(node['ceph']['mon']['secret_file'])
+    Chef::EncryptedDataBagItem.load('ceph', 'mon', secret)['secret']
+  elsif !mon_nodes.empty?
+    mon_nodes[0]['ceph']['monitor-secret']
+  elsif node['ceph']['monitor-secret']
+    node['ceph']['monitor-secret']
+  else
+    Chef::Log.info('No monitor secret found')
+    nil
+  end
+end
+
+def quorum_members_ips
+  mon_ips = []
+  cmd = Mixlib::ShellOut.new("ceph --admin-daemon /var/run/ceph/ceph-mon.#{node['hostname']}.asok mon_status")
+  cmd.run_command
+  cmd.error!
+
+  mons = JSON.parse(cmd.stdout)['monmap']['mons']
+  mons.each do |k|
+    mon_ips.push(k['addr'][0..-3])
+  end
+  mon_ips
+end
+
+def quorum?
+  # "ceph auth get-or-create-key" would hang if the monitor wasn't
+  # in quorum yet, which is highly likely on the first run. This
+  # helper lets us delay the key generation into the next
+  # chef-client run, instead of hanging.
+  #
+  # Also, as the UNIX domain socket connection has no timeout logic
+  # in the ceph tool, this exits immediately if the ceph-mon is not
+  # running for any reason; trying to connect via TCP/IP would wait
+  # for a relatively long timeout.
+  quorum_states = %w(leader, peon)
+
+  cmd = Mixlib::ShellOut.new("ceph --admin-daemon /var/run/ceph/ceph-mon.#{node['hostname']}.asok mon_status")
+  cmd.run_command
+  cmd.error!
+
+  state = JSON.parse(cmd.stdout)['state']
+  quorum_states.include?(state)
+end
+
+# Cephx is on by default, but users can disable it.
+# type can be one of 3 values: cluster, service, or client.  If the value is none of the above, set it to cluster
+def use_cephx?(type = nil)
+  # Verify type is valid
+  type = 'cluster' if %w(cluster service client).index(type).nil?
+
+  # CephX is enabled if it's not configured at all, or explicity enabled
+  node['ceph']['config'].nil? ||
+    node['ceph']['config']['global'].nil? ||
+    node['ceph']['config']['global']["auth #{type} required"].nil? ||
+    node['ceph']['config']['global']["auth #{type} required"] == 'cephx'
+end
diff --git a/libraries/utils.rb b/libraries/utils.rb
new file mode 100644 (file)
index 0000000..bac9248
--- /dev/null
@@ -0,0 +1,35 @@
+def debug_packages(packages)
+  packages.map { |x| x + debug_ext }
+end
+
+def debug_ext
+  case node['platform_family']
+  when 'debian'
+    '-dbg'
+  when 'rhel', 'fedora'
+    '-debug'
+  else
+    ''
+  end
+end
+
+def cephfs_requires_fuse
+  # What kernel version supports the given Ceph version tunables
+  # http://ceph.com/docs/master/rados/operations/crush-map/
+  min_versions = {
+    'argonaut' => 3.6,
+    'bobtail' => 3.9,
+    'cuttlefish' => 3.9,
+    'dumpling' => 3.9,
+    'emperor' => 3.9,
+    'firefly' => 3.15
+  }
+  min_versions.default = 3.15
+
+  # If we are on linux and have a new-enough kernel, allow kernel mount
+  if node['os'] == 'linux' && Gem::Version.new(node['kernel']['release'].to_f) >= Gem::Version.new(min_versions[node['ceph']['version']])
+    false
+  else
+    true
+  end
+end
diff --git a/metadata.rb b/metadata.rb
new file mode 100644 (file)
index 0000000..e3b9d2b
--- /dev/null
@@ -0,0 +1,15 @@
+name 'ceph'
+maintainer 'Guilhem Lettron'
+maintainer_email 'guilhem@lettron.fr'
+license 'Apache 2.0'
+description 'Installs/Configures the Ceph distributed filesystem'
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
+version '0.9.3'
+
+depends        'apache2', '>= 1.1.12'
+depends 'apt'
+depends 'yum', '>= 3.0'
+depends 'yum-epel'
+
+source_url 'https://github.com/ceph/ceph-cookbook' if respond_to?(:source_url)
+issues_url 'https://github.com/ceph/ceph-cookbook/issues' if respond_to?(:issues_url)
diff --git a/providers/cephfs.rb b/providers/cephfs.rb
new file mode 100644 (file)
index 0000000..1205afb
--- /dev/null
@@ -0,0 +1,85 @@
+def create_client
+  # Client settings
+  client_name = "cephfs.#{node['hostname']}"
+  filename = "/etc/ceph/ceph.client.#{client_name}.secret"
+
+  name = 'cephfs'
+  ceph_client name do
+    filename filename
+    caps('mon' => 'allow r', 'osd' => 'allow rw', 'mds' => 'allow')
+    as_keyring false
+  end
+end
+
+def manage_mount(directory, subdir, use_fuse, action)
+  # Client settings
+  client_name = "cephfs.#{node['hostname']}"
+  filename = "/etc/ceph/ceph.client.#{client_name}.secret"
+
+  if use_fuse
+    if subdir != '/'
+      Chef::Application.fatal!("Can't use a subdir with fuse mounts yet")
+    end
+    mount "#{action} #{directory}" do
+      mount_point directory
+      fstype 'fuse.ceph'
+      # needs two slashes to indicate a network mount to chef
+      device "conf=//etc/ceph/ceph.conf,id=#{client_name},keyfile=#{filename}"
+      options 'defaults,_netdev'
+      dump 0
+      pass 0
+      action action
+    end
+  else
+    mons = mon_addresses.sort.join(',') + ':' + subdir
+    mount "#{action} #{directory}" do
+      mount_point directory
+      fstype 'ceph'
+      device mons
+      options "_netdev,name=#{client_name},secretfile=#{filename}"
+      dump 0
+      pass 0
+      action action
+    end
+  end
+end
+
+def whyrun_supported?
+  true
+end
+
+def create_mount(action)
+  create_client
+  directory @new_resource.directory
+  manage_mount(@new_resource.directory, @new_resource.cephfs_subdir, @new_resource.use_fuse, action)
+end
+
+action :mount do
+  converge_by("Creating cephfs mount at #{@new_resource.directory}") do
+    create_mount(:mount)
+  end
+end
+
+action :remount do
+  converge_by("Remounting cephfs mount at #{@new_resource.directory}") do
+    create_mount(:remount)
+  end
+end
+
+action :umount do
+  converge_by("Unmounting cephfs mount at #{@new_resource.directory}") do
+    manage_mount(@new_resource.directory, @new_resource.cephfs_subdir, @new_resource.use_fuse, :umount)
+  end
+end
+
+action :enable do
+  converge_by("Enabling cephfs mount at #{@new_resource.directory}") do
+    create_mount(:enable)
+  end
+end
+
+action :disable do
+  converge_by("Disabling cephfs mount at #{@new_resource.directory}") do
+    manage_mount(@new_resource.directory, @new_resource.cephfs_subdir, @new_resource.use_fuse, :disable)
+  end
+end
diff --git a/providers/client.rb b/providers/client.rb
new file mode 100644 (file)
index 0000000..548b76b
--- /dev/null
@@ -0,0 +1,118 @@
+use_inline_resources
+
+def whyrun_supported?
+  true
+end
+
+action :add do
+  filename = @current_resource.filename
+  keyname = @current_resource.keyname
+  as_keyring = @current_resource.as_keyring
+  owner = @new_resource.owner
+  group = @new_resource.group
+  mode = @new_resource.mode
+
+  if @current_resource.exists
+    if @current_resource.keys_match && @current_resource.caps_match
+      Chef::Log.info "Client #{@new_resource} already exists and matches "\
+                     'specifications - nothing to do.'
+    else
+      converge_by("Recreating client #{@new_resource} as existing doesn't "\
+                  'match specifications') do
+        delete_entity(keyname)
+        create_entity(keyname)
+      end
+    end
+  else
+    converge_by("Creating client #{@new_resource}") do
+      create_entity(keyname)
+    end
+  end
+
+  # Obtain the randomly generated key if one wasn't provided
+  key = @new_resource.key || get_key(keyname)
+
+  # update the key in the file
+  file filename do # ~FC009
+    content file_content(keyname, key, as_keyring)
+    owner owner
+    group group
+    mode mode
+    sensitive true if Chef::Resource::File.method_defined? :sensitive
+  end
+end
+
+def load_current_resource
+  @current_resource = Chef::Resource::CephClient.new(@new_resource.name)
+  @current_resource.name(@new_resource.name)
+  @current_resource.as_keyring(@new_resource.as_keyring)
+  @current_resource.keyname(@new_resource.keyname || "client.#{@new_resource.name}.#{node['hostname']}")
+  @current_resource.caps(get_caps(@current_resource.keyname))
+  default_filename = "/etc/ceph/ceph.client.#{@new_resource.name}.#{node['hostname']}.#{@new_resource.as_keyring ? 'keyring' : 'secret'}"
+  @current_resource.filename(@new_resource.filename || default_filename)
+  @current_resource.key(get_key(@current_resource.keyname))
+  @current_resource.caps_match = @current_resource.caps == @new_resource.caps
+  @current_resource.keys_match = @new_resource.key.nil? || (@current_resource.key == @new_resource.key)
+  @current_resource.exists = ! (@current_resource.key.nil? || @current_resource.key.empty?)
+end
+
+def file_content(keyname, key, as_keyring)
+  if as_keyring
+    "[#{keyname}]\n\tkey = #{key}\n"
+  else
+    key
+  end
+end
+
+def get_key(keyname)
+  cmd = "ceph auth print_key #{keyname} --name mon. --key='#{mon_secret}'"
+  Mixlib::ShellOut.new(cmd).run_command.stdout
+end
+
+def get_caps(keyname)
+  caps = {}
+  cmd = "ceph auth get #{keyname} --name mon. --key='#{mon_secret}'"
+  output = Mixlib::ShellOut.new(cmd).run_command.stdout
+  output.scan(/caps\s*(\S+)\s*=\s*"([^"]*)"/) { |k, v| caps[k] = v }
+  caps
+end
+
+def delete_entity(keyname)
+  cmd_text = "ceph auth del #{keyname} --name mon. --key='#{mon_secret}'"
+  cmd = Mixlib::ShellOut.new(cmd_text)
+  cmd.run_command
+  cmd.error!
+  Chef::Log.debug "Client #{keyname} deleted"
+end
+
+def create_entity(keyname)
+  tmp_keyring = "#{Chef::Config[:file_cache_path]}/.#{keyname}.keyring"
+
+  if new_resource.key
+    # store key provided in a temporary keyring file
+    cmd_text = "ceph-authtool #{tmp_keyring} --create-keyring --name #{keyname} "\
+               "--add-key '#{new_resource.key}'"
+    cmd = Mixlib::ShellOut.new(cmd_text)
+    cmd.run_command
+    cmd.error!
+
+    key_option = "-i #{tmp_keyring}"
+  else
+    key_option = ''
+  end
+
+  caps = new_resource.caps.map { |k, v| "#{k} '#{v}'" }.join(' ')
+
+  cmd_text = "ceph auth #{key_option} add #{keyname} #{caps} --name mon. "\
+             "--key='#{mon_secret}'"
+  cmd = Mixlib::ShellOut.new(cmd_text)
+  cmd.run_command
+  cmd.error!
+  Chef::Log.debug "Client #{keyname} created"
+
+  # remove temporary keyring file
+  file tmp_keyring do # ~FC009
+    action :delete
+    sensitive true if Chef::Resource::File.method_defined? :sensitive
+  end
+end
diff --git a/providers/pool.rb b/providers/pool.rb
new file mode 100644 (file)
index 0000000..182c450
--- /dev/null
@@ -0,0 +1,68 @@
+#
+# Cookbook Name:: ceph
+# Provider:: pool
+#
+# Author:: Sergio de Carvalho <scarvalhojr@users.noreply.github.com>
+#
+
+def whyrun_supported?
+  true
+end
+
+use_inline_resources
+
+action :create do
+  if @current_resource.exists
+    Chef::Log.info "#{@new_resource} already exists - nothing to do."
+  else
+    converge_by("Creating #{@new_resource}") do
+      create_pool
+    end
+  end
+end
+
+action :delete do
+  if @current_resource.exists
+    converge_by("Deleting #{@new_resource}") do
+      delete_pool
+    end
+  else
+    Chef::Log.info "#{@current_resource} does not exist - nothing to do."
+  end
+end
+
+def load_current_resource
+  @current_resource = Chef::Resource::CephPool.new(@new_resource.name)
+  @current_resource.name(@new_resource.name)
+  @current_resource.exists = pool_exists?(@current_resource.name)
+end
+
+def create_pool
+  cmd_text = "ceph osd pool create #{new_resource.name} #{new_resource.pg_num}"
+  cmd_text << " #{new_resource.create_options}" if new_resource.create_options
+  cmd = Mixlib::ShellOut.new(cmd_text)
+  cmd.run_command
+  cmd.error!
+  Chef::Log.debug "Pool created: #{cmd.stderr}"
+end
+
+def delete_pool
+  cmd_text = "ceph osd pool delete #{new_resource.name}"
+  cmd_text << " #{new_resource.name} --yes-i-really-really-mean-it" if
+    new_resource.force
+  cmd = Mixlib::ShellOut.new(cmd_text)
+  cmd.run_command
+  cmd.error!
+  Chef::Log.debug "Pool deleted: #{cmd.stderr}"
+end
+
+def pool_exists?(name)
+  cmd = Mixlib::ShellOut.new("ceph osd pool get #{name} size")
+  cmd.run_command
+  cmd.error!
+  Chef::Log.debug "Pool exists: #{cmd.stdout}"
+  true
+rescue
+  Chef::Log.debug "Pool doesn't seem to exist: #{cmd.stderr}"
+  false
+end
diff --git a/recipes/all_in_one.rb b/recipes/all_in_one.rb
new file mode 100644 (file)
index 0000000..794f377
--- /dev/null
@@ -0,0 +1,6 @@
+
+include_recipe 'ceph::mon'
+include_recipe 'ceph::osd'
+include_recipe 'ceph::mds'
+include_recipe 'ceph::cephfs'
+include_recipe 'ceph::radosgw'
diff --git a/recipes/apt.rb b/recipes/apt.rb
new file mode 100644 (file)
index 0000000..b5720fb
--- /dev/null
@@ -0,0 +1,33 @@
+
+include_recipe 'apt'
+
+branch = node['ceph']['branch']
+
+distribution_codename =
+case node['lsb']['codename']
+when 'jessie' then 'sid'
+else node['lsb']['codename']
+end
+
+apt_preference 'ceph_repo' do
+  glob '*'
+  pin 'origin "ceph.com"'
+  pin_priority '1001'
+end
+
+apt_repository 'ceph' do
+  repo_name 'ceph'
+  uri node['ceph']['debian'][branch]['repository']
+  distribution distribution_codename
+  components ['main']
+  key node['ceph']['debian'][branch]['repository_key']
+end
+
+apt_repository 'ceph-extras' do
+  repo_name 'ceph-extras'
+  uri node['ceph']['debian']['extras']['repository']
+  distribution distribution_codename
+  components ['main']
+  key node['ceph']['debian']['extras']['repository_key']
+  only_if { node['ceph']['extras_repo'] }
+end
diff --git a/recipes/cephfs.rb b/recipes/cephfs.rb
new file mode 100644 (file)
index 0000000..0c713f9
--- /dev/null
@@ -0,0 +1,23 @@
+#
+# Author:: Kyle Bader <kyle.bader@dreamhost.com>
+# Cookbook Name:: ceph
+# Recipe:: cephfs
+#
+# Copyright 2011, DreamHost Web Hosting
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+ceph_cephfs node['ceph']['cephfs_mount'] do
+  use_fuse node['ceph']['cephfs_use_fuse'].nil? ? cephfs_requires_fuse : node['ceph']['cephfs_use_fuse']
+  action [:mount, :enable]
+end
diff --git a/recipes/cephfs_install.rb b/recipes/cephfs_install.rb
new file mode 100644 (file)
index 0000000..434e22b
--- /dev/null
@@ -0,0 +1,12 @@
+include_recipe 'ceph'
+
+node['ceph']['cephfs']['packages'].each do |pck|
+  package pck
+end
+
+# Update the fuse.ceph helper for pre-firefly
+remote_file '/sbin/mount.fuse.ceph' do
+  source 'https://raw.githubusercontent.com/ceph/ceph/master/src/mount.fuse.ceph'
+  only_if { ::File.exist?('/sbin/mount.fuse.ceph') }
+  not_if { ::File.readlines('/sbin/mount.fuse.ceph').grep(/_netdev/).any? }
+end
diff --git a/recipes/conf.rb b/recipes/conf.rb
new file mode 100644 (file)
index 0000000..43d6a54
--- /dev/null
@@ -0,0 +1,26 @@
+# fail 'mon_initial_members must be set in config' if node['ceph']['config']['mon_initial_members'].nil?
+
+unless node['ceph']['config']['fsid']
+  Chef::Log.warn('We are genereting a new uuid for fsid')
+  require 'securerandom'
+  node.set['ceph']['config']['fsid'] = SecureRandom.uuid
+  node.save
+end
+
+directory '/etc/ceph' do
+  owner 'root'
+  group 'root'
+  mode '0755'
+  action :create
+end
+
+template '/etc/ceph/ceph.conf' do
+  source 'ceph.conf.erb'
+  variables lazy {
+    {
+      :mon_addresses => mon_addresses,
+      :is_rgw => node['ceph']['is_radosgw']
+    }
+  }
+  mode '0644'
+end
diff --git a/recipes/default.rb b/recipes/default.rb
new file mode 100644 (file)
index 0000000..936bc33
--- /dev/null
@@ -0,0 +1,9 @@
+include_recipe 'ceph::repo' if node['ceph']['install_repo']
+include_recipe 'ceph::conf'
+
+# Tools needed by cookbook
+node['ceph']['packages'].each do |pck|
+  package pck
+end
+
+chef_gem 'netaddr'
diff --git a/recipes/install.rb b/recipes/install.rb
new file mode 100644 (file)
index 0000000..7d1eb57
--- /dev/null
@@ -0,0 +1,53 @@
+#
+# Author:: Kyle Bader <kyle.bader@dreamhost.com>
+# Cookbook Name:: ceph
+# Recipe:: default
+#
+# Copyright 2011, DreamHost Web Hosting
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+packages = []
+
+case node['platform_family']
+when 'debian'
+  packages = %w(
+    ceph
+    ceph-common
+  )
+
+  if node['ceph']['install_debug']
+    packages_dbg = %w(
+      ceph-dbg
+      ceph-common-dbg
+    )
+    packages += packages_dbg
+  end
+when 'rhel', 'fedora'
+  packages = %w(
+    ceph
+  )
+
+  if node['ceph']['install_debug']
+    packages_dbg = %w(
+      ceph-debug
+    )
+    packages += packages_dbg
+  end
+end
+
+packages.each do |pkg|
+  package pkg do
+    action :install
+  end
+end
diff --git a/recipes/mds.rb b/recipes/mds.rb
new file mode 100644 (file)
index 0000000..aedff15
--- /dev/null
@@ -0,0 +1,69 @@
+#
+# Author:: Kyle Bader <kyle.bader@dreamhost.com>
+# Cookbook Name:: ceph
+# Recipe:: mds
+#
+# Copyright 2011, DreamHost Web Hosting
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+include_recipe 'ceph'
+include_recipe 'ceph::mds_install'
+
+cluster = 'ceph'
+
+directory "/var/lib/ceph/mds/#{cluster}-#{node['hostname']}" do
+  owner 'root'
+  group 'root'
+  mode 00755
+  recursive true
+  action :create
+end
+
+ceph_client 'mds' do
+  caps('osd' => 'allow *', 'mon' => 'allow rwx')
+  keyname "mds.#{node['hostname']}"
+  filename "/var/lib/ceph/mds/#{cluster}-#{node['hostname']}/keyring"
+end
+
+file "/var/lib/ceph/mds/#{cluster}-#{node['hostname']}/done" do
+  owner 'root'
+  group 'root'
+  mode 00644
+end
+
+service_type = node['ceph']['osd']['init_style']
+
+case service_type
+when 'upstart'
+  filename = 'upstart'
+else
+  filename = 'sysvinit'
+end
+file "/var/lib/ceph/mds/#{cluster}-#{node['hostname']}/#{filename}" do
+  owner 'root'
+  group 'root'
+  mode 00644
+end
+
+service 'ceph_mds' do
+  case service_type
+  when 'upstart'
+    service_name 'ceph-mds-all-starter'
+    provider Chef::Provider::Service::Upstart
+  else
+    service_name 'ceph'
+  end
+  action [:enable, :start]
+  supports :restart => true
+end
diff --git a/recipes/mds_install.rb b/recipes/mds_install.rb
new file mode 100644 (file)
index 0000000..a04ee5a
--- /dev/null
@@ -0,0 +1,5 @@
+include_recipe 'ceph'
+
+node['ceph']['mds']['packages'].each do |pck|
+  package pck
+end
diff --git a/recipes/mon.rb b/recipes/mon.rb
new file mode 100644 (file)
index 0000000..4da92e0
--- /dev/null
@@ -0,0 +1,134 @@
+# This recipe creates a monitor cluster
+#
+# You should never change the mon default path or
+# the keyring path.
+# Don't change the cluster name either
+# Default path for mon data: /var/lib/ceph/mon/$cluster-$id/
+#   which will be /var/lib/ceph/mon/ceph-`hostname`/
+#   This path is used by upstart. If changed, upstart won't
+#   start the monitor
+# The keyring files are created using the following pattern:
+#  /etc/ceph/$cluster.client.$name.keyring
+#  e.g. /etc/ceph/ceph.client.admin.keyring
+#  The bootstrap-osd and bootstrap-mds keyring are a bit
+#  different and are created in
+#  /var/lib/ceph/bootstrap-{osd,mds}/ceph.keyring
+
+node.default['ceph']['is_mon'] = true
+
+include_recipe 'ceph'
+include_recipe 'ceph::mon_install'
+
+service_type = node['ceph']['mon']['init_style']
+
+directory '/var/run/ceph' do
+  owner 'root'
+  group 'root'
+  mode 00755
+  recursive true
+  action :create
+end
+
+directory "/var/lib/ceph/mon/ceph-#{node['hostname']}" do
+  owner 'root'
+  group 'root'
+  mode 00755
+  recursive true
+  action :create
+end
+
+# TODO: cluster name
+cluster = 'ceph'
+
+keyring = "#{Chef::Config[:file_cache_path]}/#{cluster}-#{node['hostname']}.mon.keyring"
+
+execute 'format mon-secret as keyring' do # ~FC009
+  command lazy { "ceph-authtool '#{keyring}' --create-keyring --name=mon. --add-key='#{mon_secret}' --cap mon 'allow *'" }
+  creates keyring
+  only_if { mon_secret }
+  sensitive true if Chef::Resource::Execute.method_defined? :sensitive
+end
+
+execute 'generate mon-secret as keyring' do # ~FC009
+  command "ceph-authtool '#{keyring}' --create-keyring --name=mon. --gen-key --cap mon 'allow *'"
+  creates keyring
+  not_if { mon_secret }
+  notifies :create, 'ruby_block[save mon_secret]', :immediately
+  sensitive true if Chef::Resource::Execute.method_defined? :sensitive
+end
+
+execute 'add bootstrap-osd key to keyring' do
+  command lazy { "ceph-authtool '#{keyring}' --name=client.bootstrap-osd --add-key='#{osd_secret}' --cap mon 'allow profile bootstrap-osd'  --cap osd 'allow profile bootstrap-osd'" }
+  only_if { node['ceph']['encrypted_data_bags'] && osd_secret }
+end
+
+ruby_block 'save mon_secret' do
+  block do
+    fetch = Mixlib::ShellOut.new("ceph-authtool '#{keyring}' --print-key --name=mon.")
+    fetch.run_command
+    key = fetch.stdout
+    node.set['ceph']['monitor-secret'] = key
+    node.save
+  end
+  action :nothing
+end
+
+execute 'ceph-mon mkfs' do
+  command "ceph-mon --mkfs -i #{node['hostname']} --keyring '#{keyring}'"
+end
+
+ruby_block 'finalise' do
+  block do
+    ['done', service_type].each do |ack|
+      ::File.open("/var/lib/ceph/mon/ceph-#{node['hostname']}/#{ack}", 'w').close
+    end
+  end
+end
+
+if service_type == 'upstart'
+  service 'ceph-mon' do
+    provider Chef::Provider::Service::Upstart
+    action :enable
+  end
+  service 'ceph-mon-all' do
+    provider Chef::Provider::Service::Upstart
+    supports :status => true
+    action [:enable, :start]
+  end
+end
+
+service 'ceph_mon' do
+  case service_type
+  when 'upstart'
+    service_name 'ceph-mon-all-starter'
+    provider Chef::Provider::Service::Upstart
+  else
+    service_name 'ceph'
+  end
+  supports :restart => true, :status => true
+  action [:enable, :start]
+end
+
+mon_addresses.each do |addr|
+  execute "peer #{addr}" do
+    command "ceph --admin-daemon '/var/run/ceph/ceph-mon.#{node['hostname']}.asok' add_bootstrap_peer_hint #{addr}"
+    ignore_failure true
+  end
+end
+
+# The key is going to be automatically created, We store it when it is created
+# If we're storing keys in encrypted data bags, then they've already been generated above
+if use_cephx? && !node['ceph']['encrypted_data_bags']
+  ruby_block 'get osd-bootstrap keyring' do
+    block do
+      run_out = ''
+      while run_out.empty?
+        run_out = Mixlib::ShellOut.new('ceph auth get-key client.bootstrap-osd').run_command.stdout.strip
+        sleep 2
+      end
+      node.set['ceph']['bootstrap_osd_key'] = run_out
+      node.save
+    end
+    not_if { node['ceph']['bootstrap_osd_key'] }
+  end
+end
diff --git a/recipes/mon_install.rb b/recipes/mon_install.rb
new file mode 100644 (file)
index 0000000..a125f35
--- /dev/null
@@ -0,0 +1,5 @@
+include_recipe 'ceph'
+
+node['ceph']['mon']['packages'].each do |pck|
+  package pck
+end
diff --git a/recipes/osd.rb b/recipes/osd.rb
new file mode 100644 (file)
index 0000000..d07f161
--- /dev/null
@@ -0,0 +1,150 @@
+#
+# Author:: Kyle Bader <kyle.bader@dreamhost.com>
+# Cookbook Name:: ceph
+# Recipe:: osd
+#
+# Copyright 2011, DreamHost Web Hosting
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# this recipe allows bootstrapping new osds, with help from mon
+# Sample environment:
+# #knife node edit ceph1
+# "osd_devices": [
+#   {
+#       "device": "/dev/sdc"
+#   },
+#   {
+#       "device": "/dev/sdd",
+#       "dmcrypt": true,
+#       "journal": "/dev/sdd"
+#   }
+# ]
+
+include_recipe 'ceph'
+include_recipe 'ceph::osd_install'
+
+package 'gdisk' do
+  action :upgrade
+end
+
+package 'cryptsetup' do
+  action :upgrade
+  only_if { node['dmcrypt'] }
+end
+
+service_type = node['ceph']['osd']['init_style']
+
+directory '/var/lib/ceph/bootstrap-osd' do
+  owner 'root'
+  group 'root'
+  mode '0755'
+end
+
+# TODO: cluster name
+cluster = 'ceph'
+
+execute 'format bootstrap-osd as keyring' do # ~FC009
+  command lazy { "ceph-authtool '/var/lib/ceph/bootstrap-osd/#{cluster}.keyring' --create-keyring --name=client.bootstrap-osd --add-key='#{osd_secret}'" }
+  creates "/var/lib/ceph/bootstrap-osd/#{cluster}.keyring"
+  only_if { osd_secret }
+  sensitive true if Chef::Resource::Execute.method_defined? :sensitive
+end
+
+if crowbar?
+  node['crowbar']['disks'].each do |disk, _data|
+    execute "ceph-disk-prepare #{disk}" do
+      command "ceph-disk-prepare /dev/#{disk}"
+      only_if { node['crowbar']['disks'][disk]['usage'] == 'Storage' }
+      notifies :run, 'execute[udev trigger]', :immediately
+    end
+
+    ruby_block "set disk usage for #{disk}" do
+      block do
+        node.set['crowbar']['disks'][disk]['usage'] = 'ceph-osd'
+        node.save
+      end
+    end
+  end
+
+  execute 'udev trigger' do
+    command 'udevadm trigger --subsystem-match=block --action=add'
+    action :nothing
+  end
+else
+  # Calling ceph-disk-prepare is sufficient for deploying an OSD
+  # After ceph-disk-prepare finishes, the new device will be caught
+  # by udev which will run ceph-disk-activate on it (udev will map
+  # the devices if dm-crypt is used).
+  # IMPORTANT:
+  #  - Always use the default path for OSD (i.e. /var/lib/ceph/
+  # osd/$cluster-$id)
+  #  - $cluster should always be ceph
+  #  - The --dmcrypt option will be available starting w/ Cuttlefish
+  if node['ceph']['osd_devices']
+    devices = node['ceph']['osd_devices']
+
+    devices = Hash[(0...devices.size).zip devices] unless devices.is_a? Hash
+
+    devices.each do |index, osd_device|
+      unless osd_device['status'].nil?
+        Log.info("osd: osd_device #{osd_device} has already been setup.")
+        next
+      end
+
+      directory osd_device['device'] do # ~FC022
+        owner 'root'
+        group 'root'
+        recursive true
+        only_if { osd_device['type'] == 'directory' }
+      end
+
+      dmcrypt = osd_device['encrypted'] == true ? '--dmcrypt' : ''
+
+      execute "ceph-disk-prepare on #{osd_device['device']}" do
+        command "ceph-disk-prepare #{dmcrypt} #{osd_device['device']} #{osd_device['journal']}"
+        action :run
+        notifies :create, "ruby_block[save osd_device status #{index}]", :immediately
+      end
+
+      execute "ceph-disk-activate #{osd_device['device']}" do
+        only_if { osd_device['type'] == 'directory' }
+      end
+
+      # we add this status to the node env
+      # so that we can implement recreate
+      # and/or delete functionalities in the
+      # future.
+      ruby_block "save osd_device status #{index}" do
+        block do
+          node.normal['ceph']['osd_devices'][index]['status'] = 'deployed'
+          node.save
+        end
+        action :nothing
+      end
+    end
+    service 'ceph_osd' do
+      case service_type
+      when 'upstart'
+        service_name 'ceph-osd-all-starter'
+        provider Chef::Provider::Service::Upstart
+      else
+        service_name 'ceph'
+      end
+      action [:enable, :start]
+      supports :restart => true
+    end
+  else
+    Log.info('node["ceph"]["osd_devices"] empty')
+  end
+end
diff --git a/recipes/osd_install.rb b/recipes/osd_install.rb
new file mode 100644 (file)
index 0000000..f368db3
--- /dev/null
@@ -0,0 +1,5 @@
+include_recipe 'ceph'
+
+node['ceph']['osd']['packages'].each do |pck|
+  package pck
+end
diff --git a/recipes/pools.rb b/recipes/pools.rb
new file mode 100644 (file)
index 0000000..d33cb41
--- /dev/null
@@ -0,0 +1,19 @@
+# Author:: mick-m <mick-m@users.noreply.github.com>
+# Cookbook Name:: ceph
+# Recipe:: pools
+#
+# Copyright 2015, Workday
+#
+# This recipe creates user-defined Ceph pools defined in the Chef environment.
+# Having this code in a separate recipe allows better control of when the pools
+# are created.
+
+if node['ceph']['user_pools']
+  node['ceph']['user_pools'].each do |pool|
+    # Create user-defined pools
+    ceph_pool pool['name'] do
+      pg_num pool['pg_num']
+      create_options pool['create_options'] if pool['create_options']
+    end
+  end
+end
diff --git a/recipes/radosgw.rb b/recipes/radosgw.rb
new file mode 100644 (file)
index 0000000..410b557
--- /dev/null
@@ -0,0 +1,81 @@
+#
+# Author:: Kyle Bader <kyle.bader@dreamhost.com>
+# Cookbook Name:: ceph
+# Recipe:: radosgw
+#
+# Copyright 2011, DreamHost Web Hosting
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+node.default['ceph']['is_radosgw'] = true
+
+include_recipe 'ceph'
+include_recipe 'ceph::radosgw_install'
+
+directory '/var/log/radosgw' do
+  owner node['apache']['user']
+  group node['apache']['group']
+  mode '0755'
+  action :create
+end
+
+file '/var/log/radosgw/radosgw.log' do
+  owner node['apache']['user']
+  group node['apache']['group']
+end
+
+directory '/var/run/ceph-radosgw' do
+  owner node['apache']['user']
+  group node['apache']['group']
+  mode '0755'
+  action :create
+end
+
+if node['ceph']['radosgw']['webserver_companion']
+  include_recipe "ceph::radosgw_#{node['ceph']['radosgw']['webserver_companion']}"
+end
+
+ceph_client 'radosgw' do
+  caps('mon' => 'allow rw', 'osd' => 'allow rwx')
+  owner 'root'
+  group node['apache']['group']
+  mode 0640
+end
+
+directory "/var/lib/ceph/radosgw/ceph-radosgw.#{node['hostname']}" do
+  recursive true
+  only_if { node['platform'] == 'ubuntu' }
+end
+
+# needed by https://github.com/ceph/ceph/blob/master/src/upstart/radosgw-all-starter.conf
+file "/var/lib/ceph/radosgw/ceph-radosgw.#{node['hostname']}/done" do
+  action :create
+  only_if { node['platform'] == 'ubuntu' }
+end
+
+service 'radosgw' do
+  case node['ceph']['radosgw']['init_style']
+  when 'upstart'
+    service_name 'radosgw-all-starter'
+    provider Chef::Provider::Service::Upstart
+  else
+    if node['platform'] == 'debian'
+      service_name 'radosgw'
+    else
+      service_name 'ceph-radosgw'
+    end
+  end
+  supports :restart => true
+  action [:enable, :start]
+  subscribes :restart, 'template[/etc/ceph/ceph.conf]'
+end
diff --git a/recipes/radosgw_apache2.rb b/recipes/radosgw_apache2.rb
new file mode 100644 (file)
index 0000000..119b7eb
--- /dev/null
@@ -0,0 +1,93 @@
+#
+# Author:: Kyle Bader <kyle.bader@dreamhost.com>
+# Cookbook Name:: ceph
+# Recipe:: radosgw_apache2
+#
+# Copyright 2011, DreamHost Web Hosting
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# For EL, delete the current fastcgi configuration
+# and set the correct owners for dirs and logs
+# d_owner = d_group = 'root'
+# if node['platform_family'] == 'rhel'
+#   file "#{node['apache']['dir']}/conf.d/fastcgi.conf" do
+#     action :delete
+#     backup false
+#   end
+#   d_owner = d_group = 'apache'
+# end
+
+# %W(/var/run/ceph
+#    /var/lib/ceph/radosgw/ceph-radosgw.#{node['hostname']}
+#    /var/lib/apache2/
+# ).each do |dir|
+#   directory dir do
+#     owner d_owner
+#     group d_group
+#     mode '0755'
+#     recursive true
+#     action :create
+#   end
+# end
+
+include_recipe 'ceph'
+include_recipe 'ceph::radosgw_apache2_repo'
+
+node['ceph']['radosgw']['apache2']['packages'].each do |pck|
+  package pck
+end
+
+include_recipe 'apache2'
+
+apache_module 'fastcgi' do
+  conf true
+  notifies :restart, 'service[apache2]'
+end
+
+apache_module 'rewrite' do
+  conf false
+  notifies :restart, 'service[apache2]'
+end
+
+web_app 'rgw' do
+  template 'rgw.conf.erb'
+  server_name node['ceph']['radosgw']['api_fqdn']
+  admin_email node['ceph']['radosgw']['admin_email']
+  ceph_rgw_addr node['ceph']['radosgw']['rgw_addr']
+end
+
+directory node['ceph']['radosgw']['path'] do
+  owner 'root'
+  group 'root'
+  mode '0755'
+  action :create
+end
+
+template "#{node['ceph']['radosgw']['path']}/s3gw.fcgi" do
+  source 's3gw.fcgi.erb'
+  owner 'root'
+  group 'root'
+  mode '0755'
+  variables(
+    :ceph_rgw_client => "client.radosgw.#{node['hostname']}"
+  )
+end
+
+if node['platform_family'] == 'suse'
+  bash 'Set MPM apache value' do
+    code 'sed -i s/^[[:space:]]*APACHE_MPM=.*/APACHE_MPM=\"worker\"/ /etc/sysconfig/apache2'
+    not_if 'grep -q "^[[:space:]]*APACHE_MPM=\"worker\"" /etc/sysconfig/apache2'
+    notifies :restart, 'service[apache2]'
+  end
+end
diff --git a/recipes/radosgw_apache2_repo.rb b/recipes/radosgw_apache2_repo.rb
new file mode 100644 (file)
index 0000000..e58182b
--- /dev/null
@@ -0,0 +1,33 @@
+if node['ceph']['radosgw']['use_apache_fork'] == true
+  if node.platform_family?('debian') &&
+     %w(precise quantal raring saucy squeeze trusty wheezy).include?(node['lsb']['codename'])
+    apt_repository 'ceph-apache2' do
+      repo_name 'ceph-apache2'
+      uri "http://gitbuilder.ceph.com/apache2-deb-#{node['lsb']['codename']}-x86_64-basic/ref/master"
+      distribution node['lsb']['codename']
+      components ['main']
+      key 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/autobuild.asc'
+    end
+    apt_repository 'ceph-modfastcgi' do
+      repo_name 'ceph-modfastcgi'
+      uri "http://gitbuilder.ceph.com/libapache-mod-fastcgi-deb-#{node['lsb']['codename']}-x86_64-basic/ref/master"
+      distribution node['lsb']['codename']
+      components ['main']
+      key 'https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/autobuild.asc'
+    end
+  elsif (node.platform_family?('fedora') && [18, 19].include?(node['platform_version'].to_i)) ||
+        (node.platform_family?('rhel') && [6].include?(node['platform_version'].to_i))
+    platform_family = node['platform_family']
+    platform_version = node['platform_version'].to_i
+    yum_repository 'ceph-apache2' do
+      baseurl "http://gitbuilder.ceph.com/apache2-rpm-#{node['platform']}#{platform_version}-x86_64-basic/ref/master"
+      gpgkey node['ceph'][platform_family]['dev']['repository_key']
+    end
+    yum_repository 'ceph-modfastcgi' do
+      baseurl "http://gitbuilder.ceph.com/mod_fastcgi-rpm-#{node['platform']}#{platform_version}-x86_64-basic/ref/master"
+      gpgkey node['ceph'][platform_family]['dev']['repository_key']
+    end
+  else
+    Log.info("Ceph's Apache and Apache FastCGI forks not available for this distribution")
+  end
+end
diff --git a/recipes/radosgw_civetweb.rb b/recipes/radosgw_civetweb.rb
new file mode 100644 (file)
index 0000000..ac8d4d1
--- /dev/null
@@ -0,0 +1 @@
+# Civetweb has no dependencies. It is included since the Firefly release.
diff --git a/recipes/radosgw_install.rb b/recipes/radosgw_install.rb
new file mode 100644 (file)
index 0000000..5dde1d7
--- /dev/null
@@ -0,0 +1,5 @@
+include_recipe 'ceph'
+
+node['ceph']['radosgw']['packages'].each do |pck|
+  package pck
+end
diff --git a/recipes/repo.rb b/recipes/repo.rb
new file mode 100644 (file)
index 0000000..6ef37de
--- /dev/null
@@ -0,0 +1,8 @@
+case node['platform_family']
+when 'debian'
+  include_recipe 'ceph::apt'
+when 'rhel', 'suse', 'fedora'
+  include_recipe 'ceph::rpm'
+else
+  fail 'not supported'
+end
diff --git a/recipes/rpm.rb b/recipes/rpm.rb
new file mode 100644 (file)
index 0000000..a2708ef
--- /dev/null
@@ -0,0 +1,32 @@
+platform_family = node['platform_family']
+
+case platform_family
+when 'rhel'
+  include_recipe 'yum-epel' if node['ceph']['el_add_epel']
+end
+
+branch = node['ceph']['branch']
+if branch == 'dev' && platform_family != 'centos' && platform_family != 'fedora'
+  fail "Dev branch for #{platform_family} is not yet supported"
+end
+
+yum_repository 'ceph' do
+  baseurl node['ceph'][platform_family][branch]['repository']
+  gpgkey node['ceph'][platform_family][branch]['repository_key']
+end
+
+yum_repository 'ceph-extra' do
+  baseurl node['ceph'][platform_family]['extras']['repository']
+  gpgkey node['ceph'][platform_family]['extras']['repository_key']
+  only_if { node['ceph']['extras_repo'] }
+end
+
+package 'parted'    # needed by ceph-disk-prepare to run partprobe
+package 'hdparm'    # used by ceph-disk activate
+package 'xfsprogs'  # needed by ceph-disk-prepare to format as xfs
+if node['platform_family'] == 'rhel' && node['platform_version'].to_f > 6
+  package 'btrfs-progs' # needed to format as btrfs, in the future
+end
+if node['platform_family'] == 'rhel' && node['platform_version'].to_f < 7
+  package 'python-argparse'
+end
diff --git a/recipes/tgt.rb b/recipes/tgt.rb
new file mode 100644 (file)
index 0000000..eb353e9
--- /dev/null
@@ -0,0 +1,51 @@
+#
+# Author:: Kyle Bader <kyle.bader@dreamhost.com>
+# Cookbook Name:: ceph
+# Recipe:: radosgw
+#
+# Copyright 2011, DreamHost Web Hosting
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+node.default['ceph']['extras_repo'] = true
+
+case node['platform_family']
+when 'debian'
+  packages = %w(
+    tgt
+  )
+when 'rhel', 'fedora'
+  packages = %w(
+    scsi-target-utils
+  )
+end
+
+packages.each do |pkg|
+  package pkg do
+    action :upgrade
+  end
+end
+
+include_recipe 'ceph::conf'
+# probably needs the key
+service 'tgt' do
+  if node['platform'] == 'ubuntu'
+    # The ceph version of tgt does not provide an Upstart script
+    provider Chef::Provider::Service::Init::Debian
+    service_name 'tgt'
+  else
+    service_name 'tgt'
+  end
+  supports :restart => true
+  action [:enable, :start]
+end
diff --git a/resources/cephfs.rb b/resources/cephfs.rb
new file mode 100644 (file)
index 0000000..34e64f3
--- /dev/null
@@ -0,0 +1,13 @@
+actions :mount, :umount, :remount, :enable, :disable
+default_action :mount
+
+attribute :directory, :kind_of => String, :name_attribute => true, :required => true
+attribute :use_fuse, :kind_of => [TrueClass, FalseClass], :required => true, :default => true
+attribute :cephfs_subdir, :kind_of => String, :default => '/'
+
+def initialize(*args)
+  super
+  @action = :mount
+  @run_context.include_recipe 'ceph'
+  @run_context.include_recipe 'ceph::cephfs_install'
+end
diff --git a/resources/client.rb b/resources/client.rb
new file mode 100644 (file)
index 0000000..04d1dd9
--- /dev/null
@@ -0,0 +1,27 @@
+actions :add
+default_action :add
+
+attribute :name, :kind_of => String, :name_attribute => true
+attribute :caps, :kind_of => Hash, :default => { 'mon' => 'allow r', 'osd' => 'allow r' }
+
+# Whether to store the secret in a keyring file or a plain secret file
+attribute :as_keyring, :kind_of => [TrueClass, FalseClass], :default => true
+
+# what the key should be called in the ceph cluster
+# defaults to client.#{name}.#{hostname}
+attribute :keyname, :kind_of => String
+
+# The actual key (a random key will be generated if not provided)
+attribute :key, :kind_of => String, :default => nil
+
+# where the key should be saved
+# defaults to /etc/ceph/ceph.client.#{name}.#{hostname}.keyring if as_keyring
+# defaults to /etc/ceph/ceph.client.#{name}.#{hostname}.secret if not as_keyring
+attribute :filename, :kind_of => String
+
+# key file access creds
+attribute :owner, :kind_of => String, :default => 'root'
+attribute :group, :kind_of => String, :default => 'root'
+attribute :mode, :kind_of => [Integer, String], :default => '00640'
+
+attr_accessor :exists, :caps_match, :keys_match
diff --git a/resources/pool.rb b/resources/pool.rb
new file mode 100644 (file)
index 0000000..2e3052e
--- /dev/null
@@ -0,0 +1,22 @@
+#
+# Cookbook Name:: ceph
+# Resource:: pool
+#
+# Author:: Sergio de Carvalho <scarvalhojr@users.noreply.github.com>
+#
+
+actions :create, :delete
+default_action :create
+
+attribute :name, :kind_of => String, :name_attribute => true
+
+# The total number of placement groups for the pool.
+attribute :pg_num, :kind_of => Integer, :required => true
+
+# Optional arguments for pool creation
+attribute :create_options, :kind_of => String
+
+# Forces a non-empty pool to be deleted.
+attribute :force, :kind_of => [TrueClass, FalseClass], :default => false
+
+attr_accessor :exists
diff --git a/roles/ceph-mds.json b/roles/ceph-mds.json
new file mode 100644 (file)
index 0000000..ebf80ab
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "name": "ceph-mds",
+  "json_class": "Chef::Role",
+  "description": "Ceph Metadata Server",
+  "run_list": [
+    "recipe[ceph::repo]",
+    "recipe[ceph::mds]"
+  ]
+}
diff --git a/roles/ceph-mon.json b/roles/ceph-mon.json
new file mode 100644 (file)
index 0000000..cedae1e
--- /dev/null
@@ -0,0 +1,10 @@
+{
+  "name": "ceph-mon",
+  "json_class": "Chef::Role",
+  "description": "Ceph Monitor",
+  "run_list": [
+    "recipe[ceph::repo]",
+    "recipe[ceph::mon]",
+    "recipe[ceph::pools]"
+  ]
+}
diff --git a/roles/ceph-osd.json b/roles/ceph-osd.json
new file mode 100644 (file)
index 0000000..aa0c731
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "name": "ceph-osd",
+  "json_class": "Chef::Role",
+  "description": "Ceph Object Storage Device",
+  "run_list": [
+    "recipe[ceph::repo]",
+    "recipe[ceph::osd]"
+  ]
+}
diff --git a/roles/ceph-radosgw.json b/roles/ceph-radosgw.json
new file mode 100644 (file)
index 0000000..ab2c563
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "name": "ceph-radosgw",
+  "json_class": "Chef::Role",
+  "description": "Ceph RADOS Gateway",
+  "run_list": [
+    "recipe[ceph::repo]",
+    "recipe[ceph::radosgw]"
+  ]
+}
diff --git a/roles/ceph-tgt.json b/roles/ceph-tgt.json
new file mode 100644 (file)
index 0000000..913d30f
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "name": "ceph-tgt",
+  "json_class": "Chef::Role",
+  "description": "Ceph iSCSI Target",
+  "run_list": [
+    "recipe[ceph::repo]",
+    "recipe[ceph::tgt]"
+  ]
+}
diff --git a/templates/default/ceph.conf.erb b/templates/default/ceph.conf.erb
new file mode 100644 (file)
index 0000000..c58d879
--- /dev/null
@@ -0,0 +1,63 @@
+[global]
+<% unless node['ceph']['config']['fsid'].nil? -%>
+  fsid = <%= node['ceph']['config']['fsid'] %>
+<% end -%>
+<% if node['ceph']['is_mon'] -%>
+  mon initial members = <%= node['ceph']['config']['mon_initial_members'] %>
+<% end -%>
+  mon host = <%= @mon_addresses.sort.join(', ') %>
+<% if (! node['ceph']['config']['global'].nil?) -%>
+  <% node['ceph']['config']['global'].sort.each do |k, v| %>
+  <%= k %> = <%= v %>
+  <% end %>
+<% end -%>
+
+<% if (! node['ceph']['config']['osd'].nil?) -%>
+[osd]
+  <% node['ceph']['config']['osd'].sort.each do |k, v| %>
+  <%= k %> = <%= v %>
+  <% end %>
+<% end -%>
+
+<% if (! node['ceph']['config']['mon'].nil?) -%>
+[mon]
+  <% node['ceph']['config']['mon'].sort.each do |k, v| %>
+  <%= k %> = <%= v %>
+  <% end %>
+<% end -%>
+
+<% if (! node['ceph']['config']['mds'].nil?) -%>
+[mds]
+  <% node['ceph']['config']['mds'].sort.each do |key, value| -%>
+  <%= key %> = <%= value %>
+  <%   end -%>
+<% end -%>
+
+<% if (@is_rgw) -%>
+[client.radosgw.<%= node['hostname'] %>]
+<% if node['ceph']['radosgw']['webserver_companion'] == 'civetweb' -%>
+  <% if node['ceph']['radosgw']['rgw_port'] == false %>
+  rgw frontends = "civetweb port=80"
+<% else -%>
+  rgw frontends = "civetweb port=<%=node['ceph']['radosgw']['rgw_port']%>"
+<% end -%>
+<% end -%>
+  host = <%= node['hostname'] %>
+  rgw socket path = /var/run/ceph-radosgw/radosgw.<%= node['hostname'] %>
+  admin socket = /var/run/ceph-radosgw/ceph-client.radosgw.<%= node['hostname'] %>.asok
+  pid file = /var/run/ceph-radosgw/$name.pid
+  keyring = /etc/ceph/ceph.client.radosgw.<%= node['hostname'] %>.keyring
+  log file = /var/log/radosgw/radosgw.log
+<% if (! node['ceph']['config']['rgw'].nil?) -%>
+  <% node['ceph']['config']['rgw'].sort.each do |k, v| %>
+  <%= k %> = <%= v %>
+  <% end %>
+<% end -%>
+<% end -%>
+
+<% node['ceph']['config-sections'].sort.each do |name, sect| %>
+[<%= name %>]
+  <% sect.sort.each do |k, v| %>
+  <%= k %> = <%= v %>
+  <% end %>
+<% end %>
diff --git a/templates/default/mods/fastcgi.conf.erb b/templates/default/mods/fastcgi.conf.erb
new file mode 100644 (file)
index 0000000..a252609
--- /dev/null
@@ -0,0 +1,5 @@
+<IfModule mod_fastcgi.c>
+  AddHandler fastcgi-script .fcgi
+  #FastCgiWrapper /usr/lib/apache2/suexec
+  FastCgiIpcDir /var/lib/apache2/fastcgi
+</IfModule>
diff --git a/templates/default/rgw.conf.erb b/templates/default/rgw.conf.erb
new file mode 100644 (file)
index 0000000..16778de
--- /dev/null
@@ -0,0 +1,43 @@
+<% if node['ceph']['radosgw']['rgw_port'] -%>
+FastCgiExternalServer <%= node['ceph']['radosgw']['path'] %>/s3gw.fcgi -host 127.0.0.1:<%= node['ceph']['radosgw']['rgw_port'] %>
+<% else -%>
+FastCgiExternalServer <%= node['ceph']['radosgw']['path'] %>/s3gw.fcgi -socket /var/run/ceph-radosgw/radosgw.<%= node['hostname'] %>
+<% end -%>
+
+LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" \"%{Host}i\"" proxy_combined
+LogFormat "%{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" \"%{Host}i\"" proxy_debug
+
+<VirtualHost <%= node['ceph']['radosgw']['rgw_addr'] %>>
+  ServerName <%= @params[:server_name] %>
+<% if node['ceph']['radosgw']['api_aliases'] -%>
+<%   node['ceph']['radosgw']['api_aliases'].each do |api_alias| -%>
+  ServerAlias <%= api_alias %>
+<%   end -%>
+<% end -%>
+  ServerAdmin <%= node["ceph"]["radosgw"]["admin_email"] %>
+  DocumentRoot <%= node['ceph']['radosgw']['path'] %>
+
+  RewriteEngine On
+  RewriteRule ^/([a-zA-Z0-9-_.]*)([/]?.*) /s3gw.fcgi?page=$1&params=$2&%{QUERY_STRING} [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
+
+  <IfModule mod_fastcgi.c>
+    <Directory <%= node['ceph']['radosgw']['path'] %>>
+      Options +ExecCGI
+      AllowOverride All
+      SetHandler fastcgi-script
+      AuthBasicAuthoritative Off
+      <%- if node['apache']['version'].to_f < 2.4 %>
+      Order allow,deny
+      Allow from all
+      <%- else %>
+      Require all granted
+      <%- end %>
+    </Directory>
+  </IfModule>
+
+  AllowEncodedSlashes On
+
+  ErrorLog /var/log/<%= node['apache']['package'] %>/error.log
+  CustomLog /var/log/<%= node['apache']['package'] %>/rgw-access.log proxy_combined
+  ServerSignature Off
+</VirtualHost>
diff --git a/templates/default/s3gw.fcgi.erb b/templates/default/s3gw.fcgi.erb
new file mode 100644 (file)
index 0000000..c6b684f
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+exec /usr/bin/radosgw -c /etc/ceph/ceph.conf -n <%= @ceph_rgw_client %>
diff --git a/test/cookbooks/ceph_test/CHANGELOG.md b/test/cookbooks/ceph_test/CHANGELOG.md
new file mode 100644 (file)
index 0000000..d6e3f13
--- /dev/null
@@ -0,0 +1,13 @@
+ceph_test CHANGELOG
+===================
+
+This file is used to list changes made in each version of the ceph_test cookbook.
+
+0.1.0
+-----
+- [your_name] - Initial release of ceph_test
+
+- - -
+Check the [Markdown Syntax Guide](http://daringfireball.net/projects/markdown/syntax) for help with Markdown.
+
+The [Github Flavored Markdown page](http://github.github.com/github-flavored-markdown/) describes the differences between markdown on github and standard markdown.
diff --git a/test/cookbooks/ceph_test/README.md b/test/cookbooks/ceph_test/README.md
new file mode 100644 (file)
index 0000000..7b9b0ba
--- /dev/null
@@ -0,0 +1,68 @@
+ceph_test Cookbook
+==================
+TODO: Enter the cookbook description here.
+
+e.g.
+This cookbook makes your favorite breakfast sandwich.
+
+Requirements
+------------
+TODO: List your cookbook requirements. Be sure to include any requirements this cookbook has on platforms, libraries, other cookbooks, packages, operating systems, etc.
+
+e.g.
+#### packages
+- `toaster` - ceph_test needs toaster to brown your bagel.
+
+Attributes
+----------
+TODO: List your cookbook attributes here.
+
+e.g.
+#### ceph_test::default
+<table>
+  <tr>
+    <th>Key</th>
+    <th>Type</th>
+    <th>Description</th>
+    <th>Default</th>
+  </tr>
+  <tr>
+    <td><tt>['ceph_test']['bacon']</tt></td>
+    <td>Boolean</td>
+    <td>whether to include bacon</td>
+    <td><tt>true</tt></td>
+  </tr>
+</table>
+
+Usage
+-----
+#### ceph_test::default
+TODO: Write usage instructions for each cookbook.
+
+e.g.
+Just include `ceph_test` in your node's `run_list`:
+
+```json
+{
+  "name":"my_node",
+  "run_list": [
+    "recipe[ceph_test]"
+  ]
+}
+```
+
+Contributing
+------------
+TODO: (optional) If this is a public cookbook, detail the process for contributing. If this is a private cookbook, remove this section.
+
+e.g.
+1. Fork the repository on Github
+2. Create a named feature branch (like `add_component_x`)
+3. Write your change
+4. Write tests for your change (if applicable)
+5. Run the tests, ensuring they all pass
+6. Submit a Pull Request using Github
+
+License and Authors
+-------------------
+Authors: TODO: List authors
diff --git a/test/cookbooks/ceph_test/attributes/cephfs_mount.rb b/test/cookbooks/ceph_test/attributes/cephfs_mount.rb
new file mode 100644 (file)
index 0000000..fc2c912
--- /dev/null
@@ -0,0 +1 @@
+default['ceph']['cephfs_mount'] = '/recipe_ceph'
diff --git a/test/cookbooks/ceph_test/metadata.rb b/test/cookbooks/ceph_test/metadata.rb
new file mode 100644 (file)
index 0000000..17f6f69
--- /dev/null
@@ -0,0 +1,8 @@
+name 'ceph_test'
+maintainer 'Kyle Bader'
+maintainer_email 'kyle.bader@dreamhost.com'
+license 'Apache 2.0'
+description 'Installs/Configures ceph_test'
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
+version '0.1.0'
+depends 'ceph'
diff --git a/test/cookbooks/ceph_test/recipes/cephfs.rb b/test/cookbooks/ceph_test/recipes/cephfs.rb
new file mode 100644 (file)
index 0000000..b6e7f7c
--- /dev/null
@@ -0,0 +1,43 @@
+#
+# Author:: Kyle Bader <kyle.bader@dreamhost.com>
+# Cookbook Name:: ceph_test
+# Recipe:: cephfs
+#
+# Copyright 2011, DreamHost Web Hosting
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+ceph_cephfs '/ceph' do
+  use_fuse cephfs_requires_fuse
+  action [:mount, :enable]
+end
+ceph_cephfs '/ceph.fuse' do
+  use_fuse true
+  action [:mount]
+end
+ceph_cephfs '/ceph.fstab' do
+  use_fuse true
+  action [:mount, :enable]
+end
+directory '/ceph/subdir'
+file '/ceph/subdir/file' do
+  content "It works\n"
+end
+
+unless cephfs_requires_fuse
+  ceph_cephfs '/subceph' do
+    use_fuse false
+    cephfs_subdir '/subdir'
+    action [:mount]
+  end
+end
diff --git a/test/integration/Vagrantfile.erb b/test/integration/Vagrantfile.erb
new file mode 100644 (file)
index 0000000..8266d08
--- /dev/null
@@ -0,0 +1,10 @@
+Vagrant.configure("2") do |config|
+  config.vm.box = "<%= config[:box] %>"
+  config.vm.box_url = "<%= config[:box_url ]%>"
+  (0..2).each do |d|
+    config.vm.provider :virtualbox do |vb|
+      vb.customize [ "createhd", "--filename", "disk-#{d}", "--size", "1000" ]
+      vb.customize [ "storageattach", :id, "--storagectl", "IDE Controller", "--device", (1+d)/2, "--port", (1+d)%2, "--type", "hdd", "--medium", "disk-#{d}.vdi" ]
+    end
+  end
+end
diff --git a/test/integration/aio/bats/ceph-running.bats b/test/integration/aio/bats/ceph-running.bats
new file mode 100644 (file)
index 0000000..65789ec
--- /dev/null
@@ -0,0 +1,19 @@
+@test "ceph is running" {
+  ceph -s | grep HEALTH
+}
+
+@test "ceph is healthy" {
+  ceph -s | grep HEALTH_OK
+}
+
+@test "cephfs is mounted" {
+  mount | grep -E 'type (fuse\.)?ceph'
+}
+
+@test "radosgw is running" {
+  ps auxwww | grep radosg[w]
+}
+
+@test "apache is running and listening" {
+  netstat -ln | grep -E '^\S+\s+\S+\s+\S+\s+\S+:80\s+'
+}
diff --git a/test/integration/aio/bats/cephfs.bats b/test/integration/aio/bats/cephfs.bats
new file mode 100644 (file)
index 0000000..b5d2a99
--- /dev/null
@@ -0,0 +1,47 @@
+@test "/recipe_ceph is mounted" {
+  grep -q -E '^\S+\s+/recipe_ceph\s+' /proc/mounts
+}
+
+@test "/ceph is mounted" {
+  grep -q -E '^\S+\s+/ceph\s+' /proc/mounts
+}
+@test "/ceph.fuse is mounted" {
+  grep -q -E '^\S+\s+/ceph\.fuse\s+fuse' /proc/mounts
+}
+@test "/ceph.fstab is mounted" {
+  grep -q -E '^\S+\s+/ceph\.fstab\s+fuse' /proc/mounts
+}
+
+@test "/ceph is in fstab" {
+  grep -q -E '^\S+\s+/ceph\s+\S+\s+\S*_netdev\S*\s' /etc/fstab
+}
+@test "/ceph.fuse is NOT in fstab" {
+  grep -v -q -E '^\S+\s+/ceph.fuse\s+' /etc/fstab
+}
+@test "/ceph.fstab is in fstab" {
+  grep -q -E '^\S+\s+/ceph.fstab\s+\S+\s+\S*_netdev\S*\s' /etc/fstab
+}
+
+@test "test file exists in /ceph" {
+  test -e /ceph/subdir/file
+  grep -q 'It works' /ceph/subdir/file
+}
+@test "test file exists in /ceph.fuse" {
+  test -e /ceph.fuse/subdir/file
+  grep -q 'It works' /ceph.fuse/subdir/file
+}
+
+# if we are using kernel cephfs
+if grep -q -E '^\S+\s+/ceph\s+ceph' /proc/mounts; then
+  @test "/subceph is mounted" {
+    grep -q -E '^\S+\s+/subceph\s+ceph' /proc/mounts
+  }
+  @test "/subceph is NOT in fstab" {
+    grep -v -q -E '^\S+\s+/subceph\s+' /etc/fstab
+  }
+  @test "test file exists in /subceph" {
+    test -e /subceph/file
+    grep -q 'It works' /subceph/file
+  }
+fi
+
diff --git a/test/integration/aio/bats/version.bats b/test/integration/aio/bats/version.bats
new file mode 100644 (file)
index 0000000..93abb29
--- /dev/null
@@ -0,0 +1,6 @@
+@test "ceph is installed from the official repo" {
+  cephversion=`apt-cache policy ceph | grep -B 1 ceph.com | head -n 1 | sed 's/^[^0-9]\+\([^ ]\+\).*/\1/'`
+  installedversion=`apt-cache policy ceph | grep 'Installed:' | awk '{print $2}'`
+  test "$cephversion" = "$installedversion"
+}
+