Grid環境構築用のChefリポジトリです。
リビジョン | 230422653c2b851f9897c04a04f2b80e3f59273c (tree) |
---|---|
日時 | 2017-01-07 21:38:08 |
作者 | whitestar <whitestar@gaea...> |
コミッター | whitestar |
adds the PlatformUtils::Helper.append_subusers method.
@@ -10,6 +10,10 @@ Lint/UnusedBlockArgument: | ||
10 | 10 | Enabled: false |
11 | 11 | Metrics/AbcSize: |
12 | 12 | Enabled: false |
13 | +Metrics/CyclomaticComplexity: | |
14 | + Max: 8 | |
15 | +Metrics/PerceivedComplexity: | |
16 | + Max: 10 | |
13 | 17 | Style/BlockComments: |
14 | 18 | Enabled: false |
15 | 19 | Style/BlockDelimiters: |
@@ -28,10 +32,10 @@ Style/TrailingCommaInLiteral: | ||
28 | 32 | EnforcedStyleForMultiline: comma |
29 | 33 | Style/WordArray: |
30 | 34 | Enabled: false |
31 | - | |
35 | + | |
32 | 36 | #Style/AccessorMethodName: |
33 | 37 | # Enabled: false |
34 | -#Metrics/MethodLength: | |
35 | -# Max: 15 | |
38 | +Metrics/MethodLength: | |
39 | + Max: 60 | |
36 | 40 | #Style/ModuleLength: |
37 | 41 | # Max: 150 |
@@ -1,6 +1,11 @@ | ||
1 | 1 | platform_utils CHANGELOG |
2 | 2 | ======================== |
3 | 3 | |
4 | +0.3.1 | |
5 | +----- | |
6 | +- adds the `PlatformUtils::Helper.append_subusers` method. | |
7 | +- bug fix. | |
8 | + | |
4 | 9 | 0.3.0 |
5 | 10 | ----- |
6 | 11 | - adds the `platform_utils::subid` recipe. |
@@ -2,7 +2,7 @@ | ||
2 | 2 | # Cookbook Name:: platform_utils |
3 | 3 | # Library:: Helper |
4 | 4 | # |
5 | -# Copyright 2016, whitestar | |
5 | +# Copyright 2016-2017, whitestar | |
6 | 6 | # |
7 | 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
8 | 8 | # you may not use this file except in compliance with the License. |
@@ -31,5 +31,74 @@ module PlatformUtils | ||
31 | 31 | raise |
32 | 32 | end |
33 | 33 | end |
34 | + | |
35 | + def touch_subid_files | |
36 | + subid_files = [ | |
37 | + '/etc/subuid', | |
38 | + '/etc/subgid', | |
39 | + ] | |
40 | + | |
41 | + subid_files.each {|subid_file| | |
42 | + resources(file: subid_file) rescue file subid_file do | |
43 | + owner 'root' | |
44 | + group 'root' | |
45 | + mode '0644' | |
46 | + action :touch | |
47 | + not_if { File.exist?(subid_file) } | |
48 | + end | |
49 | + } | |
50 | + | |
51 | + subid_files | |
52 | + end | |
53 | + | |
54 | + def append_subusers(users, notifies_hash = nil) | |
55 | + subid_files = touch_subid_files | |
56 | + | |
57 | + this_recipe = self | |
58 | + users.each {|uname| | |
59 | + blk_name = "adds_subid_entries_#{uname}" | |
60 | + resources(ruby_block: blk_name) rescue ruby_block blk_name do | |
61 | + action :run | |
62 | + not_if "cat /etc/subuid | grep #{uname}" | |
63 | + not_if "cat /etc/subgid | grep #{uname}" | |
64 | + notifies notifies_hash['action'], notifies_hash['resource'], notifies_hash['timer'] unless notifies_hash.nil? | |
65 | + block do | |
66 | + subid_files.each {|subid_file| | |
67 | + max_start_id = 100_000 | |
68 | + offset = 0 | |
69 | + already_exist = false | |
70 | + | |
71 | + begin | |
72 | + File.open(subid_file) {|file| | |
73 | + file.each_line {|line| | |
74 | + entry = line.split(':') | |
75 | + if entry[0] == uname | |
76 | + already_exist = true | |
77 | + break | |
78 | + end | |
79 | + if entry[1].to_i >= max_start_id | |
80 | + max_start_id = entry[1].to_i | |
81 | + offset = entry[2].to_i | |
82 | + end | |
83 | + } | |
84 | + } | |
85 | + | |
86 | + if already_exist | |
87 | + this_recipe.log "#{uname} already exists in #{subid_file}" | |
88 | + else | |
89 | + File.open(subid_file, 'a') {|file| | |
90 | + entry_str = "#{uname}:#{max_start_id + offset}:65536" | |
91 | + this_recipe.log "#{uname} (#{entry_str}) is added in #{subid_file}" | |
92 | + file.puts entry_str | |
93 | + } | |
94 | + end | |
95 | + rescue IOError => e | |
96 | + puts e | |
97 | + end | |
98 | + } | |
99 | + end | |
100 | + end | |
101 | + } | |
102 | + end | |
34 | 103 | end |
35 | 104 | end |
@@ -5,7 +5,7 @@ maintainer_email '' | ||
5 | 5 | license 'Apache 2.0' |
6 | 6 | description 'Platform Utilities' |
7 | 7 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) |
8 | -version '0.3.0' | |
8 | +version '0.3.1' | |
9 | 9 | source_url 'http://scm.osdn.jp/gitroot/metasearch/grid-chef-repo.git' |
10 | 10 | issues_url 'https://osdn.jp/projects/metasearch/ticket' |
11 | 11 |
@@ -17,62 +17,6 @@ | ||
17 | 17 | # limitations under the License. |
18 | 18 | # |
19 | 19 | |
20 | -subid_files = [ | |
21 | - '/etc/subuid', | |
22 | - '/etc/subgid', | |
23 | -] | |
20 | +::Chef::Recipe.send(:include, PlatformUtils::Helper) | |
24 | 21 | |
25 | -subid_files.each {|subid_file| | |
26 | - file subid_file do | |
27 | - owner 'root' | |
28 | - group 'root' | |
29 | - mode '0644' | |
30 | - action :touch | |
31 | - not_if { File.exist?(subid_file) } | |
32 | - end | |
33 | -} | |
34 | - | |
35 | -this_recipe = self | |
36 | -node['platform_utils']['subid']['users'].each {|uname| | |
37 | - ruby_block "adds_subid_entries_#{uname}" do | |
38 | - action :run | |
39 | - not_if "cat /etc/subuid | grep #{uname}" | |
40 | - not_if "cat /etc/subgid | grep #{uname}" | |
41 | - notifies :restart, 'service[docker]' | |
42 | - block do | |
43 | - subid_files.each {|subid_file| | |
44 | - max_start_id = 100_000 | |
45 | - offset = 0 | |
46 | - already_exist = false | |
47 | - | |
48 | - begin | |
49 | - File.open(subid_file) {|file| | |
50 | - file.each_line {|line| | |
51 | - entry = line.split(':') | |
52 | - if entry[0] == uname | |
53 | - already_exist = true | |
54 | - break | |
55 | - end | |
56 | - if entry[1].to_i >= max_start_id | |
57 | - max_start_id = entry[1].to_i | |
58 | - offset = entry[2].to_i | |
59 | - end | |
60 | - } | |
61 | - } | |
62 | - | |
63 | - if already_exist | |
64 | - this_recipe.log "#{uname} already exists in #{subid_file}" | |
65 | - else | |
66 | - File.open(subid_file, 'a') {|file| | |
67 | - entry_str = "#{uname}:#{max_start_id + offset}:65536" | |
68 | - this_recipe.log "#{uname} (#{entry_str}) is added in #{subid_file}" | |
69 | - file.puts entry_str | |
70 | - } | |
71 | - end | |
72 | - rescue IOError => e | |
73 | - puts e | |
74 | - end | |
75 | - } | |
76 | - end | |
77 | - end | |
78 | -} | |
22 | +append_subusers(node['platform_utils']['subid']['users']) |