Skip to content

Commit e061f46

Browse files
committed
Refactor mount share storages recipes and create mount share storage resources
Create mount share storage resources so they can be reused to support update share storages and support adding unmount action for resource Signed-off-by: chenwany <[email protected]>
1 parent ee04cb9 commit e061f46

File tree

8 files changed

+320
-248
lines changed

8 files changed

+320
-248
lines changed

cookbooks/aws-parallelcluster-config/recipes/base.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,8 @@
9090
mode '0644'
9191
end
9292

93-
# Mount EFS directory with efs_mount recipe
94-
include_recipe 'aws-parallelcluster-config::efs_mount'
95-
96-
# Mount FSx directory with fsx_mount recipe
97-
include_recipe 'aws-parallelcluster-config::fsx_mount'
93+
# Mount EFS, FSx
94+
include_recipe "aws-parallelcluster-config::fs_mount"
9895

9996
# Intel Runtime Libraries
10097
include_recipe "aws-parallelcluster-config::intel"

cookbooks/aws-parallelcluster-config/recipes/efs_mount.rb

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Cookbook:: aws-parallelcluster
5+
# Recipe:: fs_mount
6+
#
7+
# Copyright:: 2013-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the
10+
# License. A copy of the License is located at
11+
#
12+
# http://aws.amazon.com/apache2.0/
13+
#
14+
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
15+
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# Mount EFS directory with mount_efs resource
19+
mount_efs "efs" do
20+
shared_dir_array node['cluster']['efs_shared_dirs'].split(',')
21+
vol_array node['cluster']['efs_fs_ids'].split(',')
22+
end
23+
24+
# Mount FSx directory with mount_fsx resource
25+
mount_fsx "fsx" do
26+
fsx_fs_id_array node['cluster']['fsx_fs_ids'].split(',')
27+
fsx_fs_type_array node['cluster']['fsx_fs_types'].split(',')
28+
fsx_shared_dir_array node['cluster']['fsx_shared_dirs'].split(',')
29+
fsx_dns_name_array node['cluster']['fsx_dns_names'].split(',')
30+
fsx_mount_name_array node['cluster']['fsx_mount_names'].split(',')
31+
fsx_volume_junction_path_array node['cluster']['fsx_volume_junction_paths'].split(',')
32+
end

cookbooks/aws-parallelcluster-config/recipes/fsx_mount.rb

Lines changed: 0 additions & 99 deletions
This file was deleted.

cookbooks/aws-parallelcluster-config/recipes/head_node_base.rb

Lines changed: 4 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -15,97 +15,10 @@
1515
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

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)
10922
end
11023

11124
# Export /home

0 commit comments

Comments
 (0)