nfsadmin 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b6408e762bae666a4ac9a02272fee6dfc83f036
4
- data.tar.gz: e5569e448ff209e9c1e52b9ca3e725a8041a5ea4
3
+ metadata.gz: 8a4ade82f161c6de715391d95d43c45b0d999135
4
+ data.tar.gz: f27866c6cb23523f7492d227a0d497d91a23a335
5
5
  SHA512:
6
- metadata.gz: e96b2bcb0aedbd0c763390084c417bc80342a44faa97347bffc1492448e0292446c2495e65c4c09eda243215838e8f5d8baedefed2535765eb2e183c9c541d0f
7
- data.tar.gz: 429a729e61a58f0b4731bd0019dfc484f74a3eea385c5c1a1cbba77649ae695bf385e88f7d8c30514f130fa55fffb730595bd5cbe69ccf0ffa563b2226b0d695
6
+ metadata.gz: 5dea59632b93fb1df2c210e9ddb6b6fc2a297b2e861e26b601594822b7a378888c57744f3a71533619198c3575c8cfd5bad2594812d76592c5a791ebd7f793a5
7
+ data.tar.gz: a959e3f73eff8e24ccb4a55091481b7df2a13e9ffaad0372a4fb3e0e830a4decb7f3c47197117c4771fc9ddd50d7d6c4fa57c9785e39f9f46532fe82fd86cf7a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nfsadmin (0.0.2)
4
+ nfsadmin (0.0.3)
5
5
  gli (~> 2.9)
6
6
 
7
7
  GEM
data/bin/nfsadmin CHANGED
@@ -33,8 +33,10 @@ command :export do |c|
33
33
  add.flag [:a, :address]
34
34
  add.desc 'The NFS options for this share, e.g. rw,sync,no_root_squash,no_subtree_check'
35
35
  add.flag [:o, :options]
36
+ add.desc 'This option forces the location to be created'
37
+ add.switch [:c, :create]
36
38
  add.action do |global_options,options,args|
37
- Nfsadmin::Tasks.create_share(global_options[:c], options[:l], options[:a], options[:o])
39
+ Nfsadmin::Tasks.create_share(global_options[:c], options[:l], options[:a], options[:o], options[:c])
38
40
  end
39
41
  end
40
42
 
@@ -48,7 +50,7 @@ command :export do |c|
48
50
  c.desc 'Get information about a specific share'
49
51
  c.command [:get] do |get|
50
52
  get.action do |global_options,options,args|
51
- Nfsadmin::Tasks.get_share(global_options[:c], options[:l], options[:f])
53
+ Nfsadmin::Tasks.print_share(global_options[:c], options[:l], options[:f])
52
54
  end
53
55
  end
54
56
  end
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'fileutils'
2
3
 
3
4
  module Nfsadmin
4
5
 
@@ -72,9 +73,11 @@ module Nfsadmin
72
73
  end
73
74
  end
74
75
 
75
- def self.create_share(exportsfile, location, address, options)
76
+ def self.create_share(exportsfile, location, address, options, createlocation)
76
77
  if location.nil?
77
78
  fail 'Location must be specified'
79
+ else
80
+ fail 'Location must be an absolute path' unless (Pathname.new(location)).absolute?
78
81
  end
79
82
  if address.nil?
80
83
  fail 'Address must be specified'
@@ -82,6 +85,9 @@ module Nfsadmin
82
85
  if options.nil?
83
86
  fail 'Options must be specified'
84
87
  end
88
+ if createlocation
89
+ FileUtils::mkdir_p location unless File.directory?(location)
90
+ end
85
91
  share = { :location => location,
86
92
  :acl => [{
87
93
  :address => address,
@@ -93,6 +99,7 @@ module Nfsadmin
93
99
  if existingshare.nil?
94
100
  shares << share
95
101
  write_exports(exportsfile, shares)
102
+ puts 'Share created'
96
103
  else
97
104
  puts 'Share already exists. Use nfsadmin export modify to change it. Skipping'
98
105
  end
@@ -104,16 +111,28 @@ module Nfsadmin
104
111
  end
105
112
  shares = get_shares(exportsfile)
106
113
  share = shares.find { |share| share[:location] == location }
107
- shares.delete(share)
108
- write_exports(exportsfile, shares)
114
+ if share.nil?
115
+ fail "#{location} not found"
116
+ else
117
+ shares.delete(share)
118
+ write_exports(exportsfile, shares)
119
+ puts "Deleted #{location}"
120
+ end
109
121
  end
110
122
 
111
- def self.get_share(exportsfile, location, output_type)
123
+ def self.get_share(exportsfile, location)
112
124
  if location.nil?
113
125
  fail 'Location must be specified with -l or --location='
114
126
  end
115
127
  shares = get_shares(exportsfile)
116
- share = shares.find { |share| share[:location] == location }
128
+ shares.find { |share| share[:location] == location }
129
+ end
130
+
131
+ def self.print_share(exportsfile, location, output_type)
132
+ share = get_share(exportsfile, location)
133
+ if share.nil?
134
+ fail 'share not found'
135
+ end
117
136
  if output_type.downcase == 'text'
118
137
  printf('%-40s', share[:location])
119
138
  share[:acl].each do |acl|
@@ -1,3 +1,3 @@
1
1
  module Nfsadmin
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nfsadmin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bastiaan Schaap