|
15 | 15 | # OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and |
16 | 16 | # limitations under the License. |
17 | 17 |
|
18 | | -# Parse shared directory info and turn into an array |
19 | | -shared_dir_array = node['cluster']['ebs_shared_dirs'].split(',') |
20 | | -shared_dir_array.each_with_index do |dir, index| |
21 | | - shared_dir_array[index] = dir.strip |
22 | | - shared_dir_array[index] = "/#{shared_dir_array[index]}" unless shared_dir_array[index].start_with?('/') |
23 | | -end |
24 | | - |
25 | | -# Parse volume info into an arary |
26 | | -vol_array = node['cluster']['volume'].split(',') |
27 | | -vol_array.each_with_index do |vol, index| |
28 | | - vol_array[index] = vol.strip |
29 | | -end |
30 | | - |
31 | | -# Mount each volume |
32 | | -dev_path = [] # device labels |
33 | | -dev_uuids = [] # device uuids |
34 | | - |
35 | | -vol_array.each_with_index do |volumeid, index| |
36 | | - dev_path[index] = "/dev/disk/by-ebs-volumeid/#{volumeid}" |
37 | | - |
38 | | - # Attach EBS volume |
39 | | - execute "attach_volume_#{index}" do |
40 | | - command "#{node.default['cluster']['cookbook_virtualenv_path']}/bin/python /usr/local/sbin/attachVolume.py #{volumeid}" |
41 | | - creates dev_path[index] |
42 | | - end |
43 | | - |
44 | | - # wait for the drive to attach, before making a filesystem |
45 | | - ruby_block "sleeping_for_volume_#{index}" do |
46 | | - block do |
47 | | - wait_for_block_dev(dev_path[index]) |
48 | | - end |
49 | | - action :nothing |
50 | | - subscribes :run, "execute[attach_volume_#{index}]", :immediately |
51 | | - end |
52 | | - |
53 | | - # Setup disk, will be formatted xfs if empty |
54 | | - ruby_block "setup_disk_#{index}" do |
55 | | - block do |
56 | | - pt_type = get_pt_type(dev_path[index]) |
57 | | - if pt_type.nil? |
58 | | - Chef::Log.info("device #{dev_path[index]} not partitioned, mounting directly") |
59 | | - fs_type = setup_disk(dev_path[index]) |
60 | | - else |
61 | | - # Partitioned device, mount 1st partition |
62 | | - Chef::Log.info("device #{dev_path[index]} partitioned, mounting first partition") |
63 | | - partition_dev = get_1st_partition(dev_path[index]) |
64 | | - Chef::Log.info("First partition for device #{dev_path[index]} is: #{partition_dev}") |
65 | | - fs_type = get_fs_type(partition_dev) |
66 | | - dev_path[index] = partition_dev |
67 | | - end |
68 | | - node.default['cluster']['volume_fs_type'] = fs_type |
69 | | - dev_uuids[index] = get_uuid(dev_path[index]) |
70 | | - end |
71 | | - action :nothing |
72 | | - subscribes :run, "ruby_block[sleeping_for_volume_#{index}]", :immediately |
73 | | - end |
74 | | - |
75 | | - # Create the shared directories |
76 | | - directory shared_dir_array[index] do |
77 | | - owner 'root' |
78 | | - group 'root' |
79 | | - mode '1777' |
80 | | - recursive true |
81 | | - action :create |
82 | | - end |
83 | | - |
84 | | - # Add volume to /etc/fstab |
85 | | - mount shared_dir_array[index] do |
86 | | - device(DelayedEvaluator.new { dev_uuids[index] }) |
87 | | - fstype(DelayedEvaluator.new { node['cluster']['volume_fs_type'] }) |
88 | | - device_type :uuid |
89 | | - options "_netdev" |
90 | | - pass 0 |
91 | | - action %i(mount enable) |
92 | | - retries 10 |
93 | | - retry_delay 6 |
94 | | - end |
95 | | - |
96 | | - # Make sure shared directory permissions are correct |
97 | | - directory shared_dir_array[index] do |
98 | | - owner 'root' |
99 | | - group 'root' |
100 | | - mode '1777' |
101 | | - end |
102 | | - |
103 | | - # Export shared dir |
104 | | - nfs_export shared_dir_array[index] do |
105 | | - network get_vpc_cidr_list |
106 | | - writeable true |
107 | | - options ['no_root_squash'] |
108 | | - end |
| 18 | +manage_ebs "ebs" do |
| 19 | + shared_dir_array node['cluster']['ebs_shared_dirs'].split(',') |
| 20 | + vol_array node['cluster']['volume'].split(',') |
| 21 | + action %i(mount export) |
109 | 22 | end |
110 | 23 |
|
111 | 24 | # Export /home |
|
0 commit comments