• R/O
  • HTTP
  • SSH
  • HTTPS

grid-chef-repo: コミット

Grid環境構築用のChefリポジトリです。


コミットメタ情報

リビジョン230422653c2b851f9897c04a04f2b80e3f59273c (tree)
日時2017-01-07 21:38:08
作者whitestar <whitestar@gaea...>
コミッターwhitestar

ログメッセージ

adds the PlatformUtils::Helper.append_subusers method.

変更サマリ

差分

--- a/cookbooks/platform_utils/.rubocop.yml
+++ b/cookbooks/platform_utils/.rubocop.yml
@@ -10,6 +10,10 @@ Lint/UnusedBlockArgument:
1010 Enabled: false
1111 Metrics/AbcSize:
1212 Enabled: false
13+Metrics/CyclomaticComplexity:
14+ Max: 8
15+Metrics/PerceivedComplexity:
16+ Max: 10
1317 Style/BlockComments:
1418 Enabled: false
1519 Style/BlockDelimiters:
@@ -28,10 +32,10 @@ Style/TrailingCommaInLiteral:
2832 EnforcedStyleForMultiline: comma
2933 Style/WordArray:
3034 Enabled: false
31-
35+
3236 #Style/AccessorMethodName:
3337 # Enabled: false
34-#Metrics/MethodLength:
35-# Max: 15
38+Metrics/MethodLength:
39+ Max: 60
3640 #Style/ModuleLength:
3741 # Max: 150
--- a/cookbooks/platform_utils/CHANGELOG.md
+++ b/cookbooks/platform_utils/CHANGELOG.md
@@ -1,6 +1,11 @@
11 platform_utils CHANGELOG
22 ========================
33
4+0.3.1
5+-----
6+- adds the `PlatformUtils::Helper.append_subusers` method.
7+- bug fix.
8+
49 0.3.0
510 -----
611 - adds the `platform_utils::subid` recipe.
--- a/cookbooks/platform_utils/libraries/helper.rb
+++ b/cookbooks/platform_utils/libraries/helper.rb
@@ -2,7 +2,7 @@
22 # Cookbook Name:: platform_utils
33 # Library:: Helper
44 #
5-# Copyright 2016, whitestar
5+# Copyright 2016-2017, whitestar
66 #
77 # Licensed under the Apache License, Version 2.0 (the "License");
88 # you may not use this file except in compliance with the License.
@@ -31,5 +31,74 @@ module PlatformUtils
3131 raise
3232 end
3333 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
34103 end
35104 end
--- a/cookbooks/platform_utils/metadata.rb
+++ b/cookbooks/platform_utils/metadata.rb
@@ -5,7 +5,7 @@ maintainer_email ''
55 license 'Apache 2.0'
66 description 'Platform Utilities'
77 long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
8-version '0.3.0'
8+version '0.3.1'
99 source_url 'http://scm.osdn.jp/gitroot/metasearch/grid-chef-repo.git'
1010 issues_url 'https://osdn.jp/projects/metasearch/ticket'
1111
--- a/cookbooks/platform_utils/recipes/subid.rb
+++ b/cookbooks/platform_utils/recipes/subid.rb
@@ -17,62 +17,6 @@
1717 # limitations under the License.
1818 #
1919
20-subid_files = [
21- '/etc/subuid',
22- '/etc/subgid',
23-]
20+::Chef::Recipe.send(:include, PlatformUtils::Helper)
2421
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'])
旧リポジトリブラウザで表示