ruby-lvm-attrib 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1,5 @@
1
+ === 0.0.1 / 2008-07-21
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
5
+ * Test release.
@@ -0,0 +1,28 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ Todo.txt
6
+ bin/generate_field_data
7
+ lib/lvm/attributes.rb
8
+ lib/lvm/attributes/2.02.26/lvs.yaml
9
+ lib/lvm/attributes/2.02.26/lvsseg.yaml
10
+ lib/lvm/attributes/2.02.26/pvs.yaml
11
+ lib/lvm/attributes/2.02.26/pvsseg.yaml
12
+ lib/lvm/attributes/2.02.26/vgs.yaml
13
+ lib/lvm/attributes/2.02.27/lvs.yaml
14
+ lib/lvm/attributes/2.02.27/lvsseg.yaml
15
+ lib/lvm/attributes/2.02.27/pvs.yaml
16
+ lib/lvm/attributes/2.02.27/pvsseg.yaml
17
+ lib/lvm/attributes/2.02.27/vgs.yaml
18
+ lib/lvm/attributes/2.02.29/lvs.yaml
19
+ lib/lvm/attributes/2.02.29/lvsseg.yaml
20
+ lib/lvm/attributes/2.02.29/pvs.yaml
21
+ lib/lvm/attributes/2.02.29/pvsseg.yaml
22
+ lib/lvm/attributes/2.02.29/vgs.yaml
23
+ lib/lvm/attributes/2.02.30/lvs.yaml
24
+ lib/lvm/attributes/2.02.30/lvsseg.yaml
25
+ lib/lvm/attributes/2.02.30/pvs.yaml
26
+ lib/lvm/attributes/2.02.30/pvsseg.yaml
27
+ lib/lvm/attributes/2.02.30/vgs.yaml
28
+ test/test_ruby-lvm-attributes.rb
@@ -0,0 +1,63 @@
1
+ = ruby-lvm-attrib
2
+
3
+ * http://ruby-lvm-attrib.rubyforge.org
4
+ * mailto:mkent@magoazul.com
5
+
6
+ == DESCRIPTION:
7
+
8
+ This is a list of attributes for lvm objects. They are generated from the
9
+ source code and broken down by version.
10
+
11
+ At their core these files exist to determine which arguments to pass
12
+ lvs/vgs/pvs and the subsequent type conversions.
13
+
14
+ Currently this is split from the main ruby-lvm gem since these files require
15
+ updating to follow LVM2 releases.
16
+
17
+ == FEATURES/PROBLEMS:
18
+
19
+ * This library may go away depending on future progress of ruby-lvm.
20
+
21
+ == SYNOPSIS:
22
+
23
+ require 'lvm/attributes'
24
+
25
+ attributes = Attributes.load("2.0.36", "vgs.yaml")
26
+
27
+ == REQUIREMENTS:
28
+
29
+ * None
30
+
31
+ == INSTALL:
32
+
33
+ * sudo gem install ruby-lvm-attrib
34
+
35
+ == FEEDBACK:
36
+
37
+ Please feel free to submit patches or constructive criticism, I'm still pretty
38
+ new to ruby and object oriented programming in general.
39
+
40
+ == LICENSE:
41
+
42
+ (The MIT License)
43
+
44
+ Copyright (c) 2008 Matthew Kent, Bravenet Web Services Inc.
45
+
46
+ Permission is hereby granted, free of charge, to any person obtaining
47
+ a copy of this software and associated documentation files (the
48
+ 'Software'), to deal in the Software without restriction, including
49
+ without limitation the rights to use, copy, modify, merge, publish,
50
+ distribute, sublicense, and/or sell copies of the Software, and to
51
+ permit persons to whom the Software is furnished to do so, subject to
52
+ the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be
55
+ included in all copies or substantial portions of the Software.
56
+
57
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
58
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
59
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
60
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
61
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
62
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
63
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ $:.unshift(File.dirname(__FILE__) + "/lib")
6
+ require 'lvm/attributes'
7
+
8
+ Hoe.new('ruby-lvm-attrib', LVM::Attributes::VERSION) do |p|
9
+ p.developer('Matthew Kent', 'mkent@magoazul.com')
10
+ p.remote_rdoc_dir = ''
11
+ end
12
+
13
+ # vim: syntax=Ruby
@@ -0,0 +1,4 @@
1
+ = to do
2
+
3
+ == 0.1.1
4
+ * attribute generation should be a proper class with a binary invoking it
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Build yaml files which provide arguments passed to {lv,pv,vg}s and subsequent
4
+ # type conversions.
5
+ #
6
+ # ./generate_field_data ~/LVM2.2.02.38
7
+
8
+ require 'fileutils'
9
+ require 'yaml'
10
+
11
+ VERSION_FILE = "/VERSION"
12
+ COLUMNS_FILE = "/lib/report/columns.h"
13
+
14
+ debug = false
15
+
16
+ TYPE_CONVERSION_MAP = {
17
+ # Only types we can really trust
18
+ "uint32" => "Integer",
19
+ "int32" => "Integer",
20
+ # These were determined by reading the code, they invoke _(u)int32_disp right away
21
+ "pvmdas" => "Integer",
22
+ "vgmdas" => "Integer",
23
+ "lvcount" => "Integer",
24
+ "lvsegcount" => "Integer",
25
+ "segstartpe" => "Integer",
26
+ # listed to return STR?
27
+ "lvkmaj" => "Integer",
28
+ "lvkmin" => "Integer",
29
+ "snpercent" => "Float",
30
+ "copypercent" => "Float",
31
+ # size32/64, these do unit formatting unless overridden on command line. We
32
+ # typically want them in bytes so we can convert them to Integers safely
33
+ "size32" => "Integer",
34
+ "size64" => "Integer",
35
+ # These types return size32/size64 as well
36
+ "lvkreadahead" => "Integer",
37
+ "pvsize" => "Integer",
38
+ "devsize" => "Integer",
39
+ "pvfree" => "Integer",
40
+ "pvused" => "Integer",
41
+ "pvmdafree" => "Integer",
42
+ "vgsize" => "Integer",
43
+ "vgfree" => "Integer",
44
+ "vgmda_free" => "Integer",
45
+ "chunksize" => "Integer",
46
+ "segstart" => "Integer",
47
+ "segsize" => "Integer",
48
+ "vgmdafree" => "Integer",
49
+ # Weird one, can be "auto" or size32
50
+ "lvreadahead" => "String"
51
+ }
52
+
53
+ lvm_source = ARGV[0]
54
+
55
+ version = File.readlines(lvm_source + VERSION_FILE)[0].split(' ')[0]
56
+
57
+ lvs = []
58
+ lvssegs = []
59
+ pvs = []
60
+ pvssegs = []
61
+ vgs = []
62
+ File.readlines(lvm_source + COLUMNS_FILE).each do |line|
63
+ # eg: FIELD(LVS, lv, STR, "LV UUID", lvid.id[1], 38, uuid, "lv_uuid", "Unique identifier")
64
+ if line =~ %r{^FIELD\((.*)\)$}
65
+ fields = $1.split(', ')
66
+ fields.each { |f| f.gsub!(%r{^"}, ''); f.gsub!(%r{"$}, '') }
67
+ p fields if debug
68
+ app = fields[0]
69
+ general_type = fields[2]
70
+ specific_type = fields[6]
71
+ column = fields[7]
72
+ method = fields[7].dup
73
+ description = fields[8]
74
+ p app, general_type, specific_type, column, method, description if debug
75
+
76
+ if general_type == "NUM"
77
+ attribute_type = TYPE_CONVERSION_MAP[specific_type]
78
+ if attribute_type.nil?
79
+ puts "Oops, missing type conversion data of column '#{attribute}' use by '#{app}' which says its going to return a '#{specific_type}'"
80
+ puts "Figure out the missing type and rerun."
81
+ exit 1
82
+ end
83
+ else
84
+ attribute_type = "String"
85
+ end
86
+
87
+ # our shorter nicer method names, according to the man page these can be
88
+ # dropped when passing column names as arguments as well, but i found a few
89
+ # with issues (seg_start).
90
+ case app
91
+ when "LVS"
92
+ method.sub!(%r{^lv_}, '')
93
+ when "SEGS"
94
+ method.sub!(%r{^seg_}, '')
95
+ when "PVS"
96
+ method.sub!(%r{^pv_}, '')
97
+ when "PVSEGS"
98
+ method.sub!(%r{^pvseg_}, '')
99
+ when "VGS"
100
+ method.sub!(%r{^vg_}, '')
101
+ end
102
+
103
+ attribute = {
104
+ :method => method,
105
+ :column => column,
106
+ :type_hint => attribute_type,
107
+ :description => description
108
+ }
109
+
110
+ case app
111
+ when "LVS"
112
+ lvs << attribute
113
+ when "SEGS"
114
+ lvssegs << attribute
115
+ when "PVS"
116
+ pvs << attribute
117
+ when "PVSEGS"
118
+ pvssegs << attribute
119
+ when "VGS"
120
+ vgs << attribute
121
+ end
122
+ end
123
+ end
124
+
125
+ # we use vg_uuid as our crossover attribute that links vg->lv and vg->pv
126
+ attribute = { :method => "vg_uuid",
127
+ :column => "vg_uuid",
128
+ :type_hint => "String",
129
+ :description => "For VolumeGroup to LogicalVolume relationship." }
130
+ lvs << attribute
131
+ attribute = { :method => "vg_uuid",
132
+ :column => "vg_uuid",
133
+ :type_hint => "String",
134
+ :description => "For VolumeGroup to PhysicalVolume relationship." }
135
+ pvs << attribute
136
+
137
+ # and we link lv->lvsegment, pv->pvsegment
138
+ attribute = { :method => "lv_uuid",
139
+ :column => "lv_uuid",
140
+ :type_hint => "String",
141
+ :description => "For LogicalVolume to LogicalVolumeSegment relationship." }
142
+ lvssegs << attribute
143
+ attribute = { :method => "pv_uuid",
144
+ :column => "pv_uuid",
145
+ :type_hint => "String",
146
+ :description => "For PhysicalVolume to PhysicalVolumeSegment relationship." }
147
+ pvssegs << attribute
148
+
149
+ lvs.sort! {|x,y| x[:column] <=> y[:column]}
150
+ lvssegs.sort! {|x,y| x[:column] <=> y[:column]}
151
+ pvs.sort! {|x,y| x[:column] <=> y[:column]}
152
+ pvssegs.sort! {|x,y| x[:column] <=> y[:column]}
153
+ vgs.sort! {|x,y| x[:column] <=> y[:column]}
154
+
155
+ FileUtils.mkdir(version)
156
+
157
+ disclaimer=<<go
158
+ # These are column to object attribute mappings
159
+ # generated by #{$0} based on
160
+ # #{lvm_source}/lib/report/columns.h
161
+ go
162
+
163
+ File.open("#{version}/lvs.yaml", "w") { |f| f.write(disclaimer); f.write(lvs.to_yaml) }
164
+ File.open("#{version}/lvsseg.yaml", "w") { |f| f.write(disclaimer); f.write(lvssegs.to_yaml)}
165
+ File.open("#{version}/pvs.yaml", "w") { |f| f.write(disclaimer); f.write(pvs.to_yaml) }
166
+ File.open("#{version}/pvsseg.yaml", "w") { |f| f.write(disclaimer); f.write(pvssegs.to_yaml)}
167
+ File.open("#{version}/vgs.yaml", "w") { |f| f.write(disclaimer); f.write(vgs.to_yaml) }
168
+
169
+ puts "Done."
@@ -0,0 +1,24 @@
1
+ require 'yaml'
2
+
3
+ module LVM
4
+ module Attributes
5
+ VERSION = '0.0.1'
6
+
7
+ def load(version, name)
8
+ cwd = File.dirname(__FILE__)
9
+
10
+ # was going to be symlinks, but rubygems didn't seem to want to package
11
+ # them
12
+ if version == "2.02.28"
13
+ version = "2.02.27"
14
+ elsif ((31..39).map { |x| "2.02.#{x}" }).include?(version)
15
+ version = "2.02.30"
16
+ end
17
+
18
+ file = File.join(cwd, "attributes", version, name)
19
+
20
+ return YAML.load_file(file)
21
+ end
22
+ module_function :load
23
+ end # module Attributes
24
+ end # module LVM
@@ -0,0 +1,72 @@
1
+ # These are column to object attribute mappings
2
+ # generated by ./generate_field_data based on
3
+ # /home/iscsidev/LVM2.2.02.26/lib/report/columns.h
4
+ ---
5
+ - :method: copy_percent
6
+ :type_hint: Float
7
+ :column: copy_percent
8
+ :description: For mirrors and pvmove
9
+ - :method: attr
10
+ :type_hint: String
11
+ :column: lv_attr
12
+ :description: Various attributes - see man page.
13
+ - :method: kernel_major
14
+ :type_hint: String
15
+ :column: lv_kernel_major
16
+ :description: Currently assigned major number or -1 if LV is not active.
17
+ - :method: kernel_minor
18
+ :type_hint: String
19
+ :column: lv_kernel_minor
20
+ :description: Currently assigned minor number or -1 if LV is not active.
21
+ - :method: major
22
+ :type_hint: Integer
23
+ :column: lv_major
24
+ :description: Persistent major number or -1 if not persistent.
25
+ - :method: minor
26
+ :type_hint: Integer
27
+ :column: lv_minor
28
+ :description: Persistent minor number or -1 if not persistent.
29
+ - :method: name
30
+ :type_hint: String
31
+ :column: lv_name
32
+ :description: Name. LVs created for internal use are enclosed in brackets.
33
+ - :method: size
34
+ :type_hint: Integer
35
+ :column: lv_size
36
+ :description: Size of LV in current units.
37
+ - :method: tags
38
+ :type_hint: String
39
+ :column: lv_tags
40
+ :description: Tags
41
+ - :method: uuid
42
+ :type_hint: String
43
+ :column: lv_uuid
44
+ :description: Unique identifier
45
+ - :method: mirror_log
46
+ :type_hint: String
47
+ :column: mirror_log
48
+ :description: For mirrors
49
+ - :method: modules
50
+ :type_hint: String
51
+ :column: modules
52
+ :description: Kernel device-mapper modules required for this LV.
53
+ - :method: move_pv
54
+ :type_hint: String
55
+ :column: move_pv
56
+ :description: For pvmove
57
+ - :method: origin
58
+ :type_hint: String
59
+ :column: origin
60
+ :description: For snapshots
61
+ - :method: seg_count
62
+ :type_hint: Integer
63
+ :column: seg_count
64
+ :description: Number of segments in LV.
65
+ - :method: snap_percent
66
+ :type_hint: Float
67
+ :column: snap_percent
68
+ :description: For snapshots
69
+ - :method: vg_uuid
70
+ :type_hint: String
71
+ :column: vg_uuid
72
+ :description: For VolumeGroup to LogicalVolume relationship.
@@ -0,0 +1,56 @@
1
+ # These are column to object attribute mappings
2
+ # generated by ./generate_field_data based on
3
+ # /home/iscsidev/LVM2.2.02.26/lib/report/columns.h
4
+ ---
5
+ - :method: chunk_size
6
+ :type_hint: Integer
7
+ :column: chunk_size
8
+ :description: For snapshots
9
+ - :method: chunksize
10
+ :type_hint: Integer
11
+ :column: chunksize
12
+ :description: For snapshots
13
+ - :method: devices
14
+ :type_hint: String
15
+ :column: devices
16
+ :description: Underlying devices used with starting extent numbers.
17
+ - :method: lv_uuid
18
+ :type_hint: String
19
+ :column: lv_uuid
20
+ :description: For LogicalVolume to LogicalVolumeSegment relationship.
21
+ - :method: region_size
22
+ :type_hint: Integer
23
+ :column: region_size
24
+ :description: For mirrors
25
+ - :method: regionsize
26
+ :type_hint: Integer
27
+ :column: regionsize
28
+ :description: For mirrors
29
+ - :method: size
30
+ :type_hint: Integer
31
+ :column: seg_size
32
+ :description: Size of segment in current units.
33
+ - :method: start
34
+ :type_hint: Integer
35
+ :column: seg_start
36
+ :description: Offset within the LV to the start of the segment in current units.
37
+ - :method: tags
38
+ :type_hint: String
39
+ :column: seg_tags
40
+ :description: Tags
41
+ - :method: segtype
42
+ :type_hint: String
43
+ :column: segtype
44
+ :description: Type of LV segment
45
+ - :method: stripe_size
46
+ :type_hint: Integer
47
+ :column: stripe_size
48
+ :description: For stripes
49
+ - :method: stripes
50
+ :type_hint: Integer
51
+ :column: stripes
52
+ :description: Number of stripes or mirror legs.
53
+ - :method: stripesize
54
+ :type_hint: Integer
55
+ :column: stripesize
56
+ :description: For stripes