ruby-lvm 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data.tar.gz.sig +0 -0
  2. data/History.txt +10 -2
  3. data/Manifest.txt +18 -17
  4. data/README.txt +22 -9
  5. data/Rakefile +3 -2
  6. data/Todo.txt +7 -8
  7. data/examples/create_snapshot.rb +20 -8
  8. data/examples/error_handling.rb +8 -2
  9. data/examples/show_lvm_config.rb +40 -0
  10. data/lib/lvm.rb +67 -24
  11. data/lib/lvm/external.rb +25 -30
  12. data/lib/lvm/logical_volume.rb +9 -0
  13. data/lib/lvm/logical_volume_segment.rb +5 -0
  14. data/lib/lvm/logical_volumes.rb +37 -0
  15. data/lib/lvm/physical_volume.rb +5 -0
  16. data/lib/lvm/physical_volume_segment.rb +5 -0
  17. data/lib/lvm/physical_volumes.rb +37 -0
  18. data/lib/lvm/userland.rb +5 -0
  19. data/lib/lvm/volume_group.rb +5 -0
  20. data/lib/lvm/volume_groups.rb +46 -0
  21. data/lib/lvm/volumes.rb +16 -0
  22. data/lib/lvm/wrapper.rb +53 -0
  23. data/lib/lvm/wrapper/constants.rb +11 -0
  24. data/lib/lvm/wrapper/lvs.rb +127 -0
  25. data/lib/lvm/wrapper/lvsseg.rb +59 -0
  26. data/lib/lvm/wrapper/pvs.rb +84 -0
  27. data/lib/lvm/wrapper/pvsseg.rb +57 -0
  28. data/lib/lvm/wrapper/vgs.rb +112 -0
  29. metadata +109 -90
  30. metadata.gz.sig +0 -0
  31. data/examples/show_volumes.rb +0 -26
  32. data/helpers/generate_field_data.rb +0 -117
  33. data/lib/lvm/attrib/lvs.yaml +0 -88
  34. data/lib/lvm/attrib/pvs.yaml +0 -46
  35. data/lib/lvm/attrib/vgs.yaml +0 -55
  36. data/lib/lvm/lv.rb +0 -19
  37. data/lib/lvm/lvmanager.rb +0 -95
  38. data/lib/lvm/lvs.rb +0 -143
  39. data/lib/lvm/lvseg.rb +0 -14
  40. data/lib/lvm/proc.rb +0 -39
  41. data/lib/lvm/pv.rb +0 -15
  42. data/lib/lvm/pvmanager.rb +0 -22
  43. data/lib/lvm/pvs.rb +0 -109
  44. data/lib/lvm/pvseg.rb +0 -14
  45. data/lib/lvm/vg.rb +0 -15
  46. data/lib/lvm/vgmanager.rb +0 -68
  47. data/lib/lvm/vgs.rb +0 -123
@@ -1,88 +0,0 @@
1
- # these are column to object attribute mappings
2
- # generated by generate_field_data.rb based on
3
- # /home/iscsidev/LVM2.2.02.26/lib/report/columns.h
4
- ---
5
- - :method: chunk_size
6
- :option: chunk_size
7
- :type_hint: Integer
8
- - :method: chunksize
9
- :option: chunksize
10
- :type_hint: Integer
11
- - :method: copy_percent
12
- :option: copy_percent
13
- :type_hint: Float
14
- - :method: devices
15
- :option: devices
16
- :type_hint: String
17
- - :method: attr
18
- :option: lv_attr
19
- :type_hint: String
20
- - :method: kernel_major
21
- :option: lv_kernel_major
22
- :type_hint: String
23
- - :method: kernel_minor
24
- :option: lv_kernel_minor
25
- :type_hint: String
26
- - :method: major
27
- :option: lv_major
28
- :type_hint: Integer
29
- - :method: minor
30
- :option: lv_minor
31
- :type_hint: Integer
32
- - :method: name
33
- :option: lv_name
34
- :type_hint: String
35
- - :method: size
36
- :option: lv_size
37
- :type_hint: Integer
38
- - :method: tags
39
- :option: lv_tags
40
- :type_hint: String
41
- - :method: uuid
42
- :option: lv_uuid
43
- :type_hint: String
44
- - :method: mirror_log
45
- :option: mirror_log
46
- :type_hint: String
47
- - :method: modules
48
- :option: modules
49
- :type_hint: String
50
- - :method: move_pv
51
- :option: move_pv
52
- :type_hint: String
53
- - :method: origin
54
- :option: origin
55
- :type_hint: String
56
- - :method: region_size
57
- :option: region_size
58
- :type_hint: Integer
59
- - :method: regionsize
60
- :option: regionsize
61
- :type_hint: Integer
62
- - :method: seg_count
63
- :option: seg_count
64
- :type_hint: Integer
65
- - :method: seg_size
66
- :option: seg_size
67
- :type_hint: Integer
68
- - :method: seg_start
69
- :option: seg_start
70
- :type_hint: Integer
71
- - :method: seg_tags
72
- :option: seg_tags
73
- :type_hint: String
74
- - :method: segtype
75
- :option: segtype
76
- :type_hint: String
77
- - :method: snap_percent
78
- :option: snap_percent
79
- :type_hint: Float
80
- - :method: stripe_size
81
- :option: stripe_size
82
- :type_hint: Integer
83
- - :method: stripes
84
- :option: stripes
85
- :type_hint: Integer
86
- - :method: stripesize
87
- :option: stripesize
88
- :type_hint: Integer
@@ -1,46 +0,0 @@
1
- # these are column to object attribute mappings
2
- # generated by generate_field_data.rb based on
3
- # /home/iscsidev/LVM2.2.02.26/lib/report/columns.h
4
- ---
5
- - :method: dev_size
6
- :option: dev_size
7
- :type_hint: Integer
8
- - :method: pe_start
9
- :option: pe_start
10
- :type_hint: Integer
11
- - :method: attr
12
- :option: pv_attr
13
- :type_hint: String
14
- - :method: fmt
15
- :option: pv_fmt
16
- :type_hint: String
17
- - :method: free
18
- :option: pv_free
19
- :type_hint: Integer
20
- - :method: name
21
- :option: pv_name
22
- :type_hint: String
23
- - :method: pe_alloc_count
24
- :option: pv_pe_alloc_count
25
- :type_hint: Integer
26
- - :method: pe_count
27
- :option: pv_pe_count
28
- :type_hint: Integer
29
- - :method: size
30
- :option: pv_size
31
- :type_hint: Integer
32
- - :method: tags
33
- :option: pv_tags
34
- :type_hint: String
35
- - :method: used
36
- :option: pv_used
37
- :type_hint: Integer
38
- - :method: uuid
39
- :option: pv_uuid
40
- :type_hint: String
41
- - :method: pvseg_size
42
- :option: pvseg_size
43
- :type_hint: Integer
44
- - :method: pvseg_start
45
- :option: pvseg_start
46
- :type_hint: Integer
@@ -1,55 +0,0 @@
1
- # these are column to object attribute mappings
2
- # generated by generate_field_data.rb based on
3
- # /home/iscsidev/LVM2.2.02.26/lib/report/columns.h
4
- ---
5
- - :method: lv_count
6
- :option: lv_count
7
- :type_hint: Integer
8
- - :method: max_lv
9
- :option: max_lv
10
- :type_hint: Integer
11
- - :method: max_pv
12
- :option: max_pv
13
- :type_hint: Integer
14
- - :method: pv_count
15
- :option: pv_count
16
- :type_hint: Integer
17
- - :method: snap_count
18
- :option: snap_count
19
- :type_hint: Integer
20
- - :method: attr
21
- :option: vg_attr
22
- :type_hint: String
23
- - :method: extent_count
24
- :option: vg_extent_count
25
- :type_hint: Integer
26
- - :method: extent_size
27
- :option: vg_extent_size
28
- :type_hint: Integer
29
- - :method: fmt
30
- :option: vg_fmt
31
- :type_hint: String
32
- - :method: free
33
- :option: vg_free
34
- :type_hint: Integer
35
- - :method: free_count
36
- :option: vg_free_count
37
- :type_hint: Integer
38
- - :method: name
39
- :option: vg_name
40
- :type_hint: String
41
- - :method: seqno
42
- :option: vg_seqno
43
- :type_hint: Integer
44
- - :method: size
45
- :option: vg_size
46
- :type_hint: Integer
47
- - :method: sysid
48
- :option: vg_sysid
49
- :type_hint: String
50
- - :method: tags
51
- :option: vg_tags
52
- :type_hint: String
53
- - :method: uuid
54
- :option: vg_uuid
55
- :type_hint: String
@@ -1,19 +0,0 @@
1
- module LVMWrapper
2
- class LogicalVolume
3
- def initialize(args)
4
- @attributes = args
5
-
6
- # so many attributes.. we let the caller define them :)
7
- meta = class << self; self; end
8
- args.each_key do |name|
9
- meta.send(:define_method, name) { @attributes[name] }
10
- end
11
- end
12
-
13
- # helper methods
14
- def open?
15
- @attributes[:device_open]
16
- end
17
-
18
- end # class
19
- end # module
@@ -1,95 +0,0 @@
1
- require 'lvm/lv'
2
- require 'lvm/lvs'
3
-
4
- module LVMWrapper
5
- class LogicalVolumeManager
6
-
7
- def initialize(lvm)
8
- @lvm = lvm
9
- end
10
-
11
- # lvchange Change the attributes of logical volume(s)
12
- # lvconvert Change logical volume layout
13
- # lvdisplay Display information about a logical volume
14
- # lvextend Add space to a logical volume
15
- #*lvmchange With the device mapper, this is obsolete and
16
- # does nothing.
17
- #*lvmdiskscan List devices that may be used as physical
18
- # volumes
19
- #*lvmsadc Collect activity data
20
- #*lvmsar Create activity report
21
- # lvreduce Reduce the size of a logical volume
22
- # lvrename Rename a logical volume
23
- # lvresize Resize a logical volume
24
- # lvscan List all logical volumes in
25
- # all volume groups
26
-
27
- # We take the options listed by 'lvm <cmd>' as symbols and pass them as is
28
- # to lvm. We let LVM opt parsing handle any issues.
29
- def create(args)
30
- vgname = args[:vgname] || nil
31
- pvpath = args[:pvpath]
32
-
33
- raise ArgumentError if vgname.nil?
34
-
35
- args.delete(:vgname)
36
- args.delete(:pvpath)
37
-
38
- @lvm.cmd("lvcreate #{args_to_long_opts(args)} #{vgname} #{pvpath}")
39
- end
40
-
41
- def remove(args)
42
- lvname = args[:name] || nil
43
- vgname = args[:vgname] || nil
44
-
45
- raise ArgumentError if (lvname.nil? or vgname.nil?)
46
-
47
- args.delete(:name)
48
- args.delete(:vgname)
49
-
50
- @lvm.cmd("lvremove --force #{args_to_long_opts(args)} #{vgname}/#{lvname}")
51
- end
52
-
53
- def snapshot(args)
54
- origin = args[:origin] || nil
55
-
56
- raise ArgumentError if origin.nil?
57
-
58
- args.delete(:origin)
59
-
60
- @lvm.cmd("lvcreate --snapshot #{args_to_long_opts(args)} #{origin}")
61
- end
62
-
63
- # ruby hash of key values to long options
64
- def args_to_long_opts(args)
65
- opts = []
66
- args.each do |key,value|
67
- opts << "--#{key.to_s} #{value}"
68
- end
69
- opts.join(" ")
70
- end
71
-
72
- def lookup(lvname,vgname)
73
- raw_data = @lvm.cmd("#{LVS.command} #{vgname}/#{lvname}")
74
- LVS.parse(raw_data)[0]
75
- end
76
-
77
- def [](lvname,vgname)
78
- lookup(lvname,vgname)
79
- end
80
-
81
- def list(vgname)
82
- raw_data = @lvm.cmd("#{LVS.command} #{vgname}")
83
- lvs = LVS.parse(raw_data)
84
- if block_given?
85
- lvs.each do |lv|
86
- yield lv
87
- end
88
- else
89
- lvs
90
- end
91
- end
92
- alias lvs list
93
-
94
- end # class
95
- end # module
@@ -1,143 +0,0 @@
1
- module LVMWrapper
2
- class LVS
3
- require 'yaml'
4
-
5
- BASE_COMMAND = 'lvs --verbose --separator=, --noheadings --nosuffix --units=b --unbuffered --options %s'
6
- #,vg_uuid'
7
- ATTRIBUTES = 'attrib/lvs.yaml'
8
-
9
- EMPTY = '-'
10
-
11
- # lv_attr attribute handling constants
12
- # roughly by order referenced in lib/report/report.c:292 (_lvstatus_disp)
13
- #
14
- VOLUME_TYPE = {
15
- 'p' => :pvmove,
16
- 'c' => :conversion,
17
- 'M' => :mirror_not_synced,
18
- 'm' => :mirror,
19
- 'i' => :mirror_image,
20
- 'I' => :mirror_image_not_synced,
21
- 'l' => :mirror_log,
22
- 'v' => :virtual,
23
- 'o' => :origin,
24
- 's' => :snapshot,
25
- 'S' => :invalid_snapshot,
26
- # custom, empty is a standard volume
27
- '-' => :normal
28
- }
29
- PERMISSIONS = {
30
- 'w' => :writeable,
31
- 'r' => :readonly,
32
- # custom, from reading source
33
- '-' => :locked_by_pvmove,
34
- }
35
- ALLOCATION_POLICY = {
36
- 'c' => :contiguous,
37
- 'l' => :cling,
38
- 'n' => :normal,
39
- 'a' => :anywhere,
40
- 'i' => :inherited,
41
- 'C' => :contiguous_locked,
42
- 'L' => :cling_locked,
43
- 'N' => :normal_locked,
44
- 'A' => :anywhere_locked,
45
- 'I' => :inherited_locked
46
- }
47
- FIXED_MINOR = {
48
- # code says its a boolean
49
- 'm' => true
50
- }
51
- STATE = {
52
- 's' => :suspended,
53
- 'a' => :active,
54
- 'i' => :inactive_with_table,
55
- 'd' => :inactive_without_table,
56
- 'S' => :suspended_snapshot,
57
- 'I' => :invalid_snapshot
58
- }
59
- DEVICE_OPEN = {
60
- # code says its a boolean
61
- 'o' => true
62
- }
63
-
64
- def self.command
65
- opts = []
66
- attributes = YAML.load_file(File.dirname(__FILE__) + '/' + ATTRIBUTES)
67
- attributes.each do |a|
68
- opts << a[:option]
69
- end
70
-
71
- BASE_COMMAND % opts.join(",")
72
- end
73
-
74
- def self.parse_lv_attr(lv_attr)
75
- ret = {}
76
- # translate them into nice symbols and a couple booleans
77
- ret[:volume_type] = VOLUME_TYPE[lv_attr[0].chr]
78
- ret[:permissions] = PERMISSIONS[lv_attr[1].chr]
79
- ret[:allocation_policy] = ALLOCATION_POLICY[lv_attr[2].chr]
80
- ret[:fixed_minor] = FIXED_MINOR[lv_attr[3].chr] ? true : false
81
- ret[:state] = STATE[lv_attr[4].chr]
82
- ret[:device_open] = DEVICE_OPEN[lv_attr[5].chr] ? true : false
83
- ret
84
- end
85
-
86
- # Parses the output of self.command
87
- def self.parse(output)
88
- volumes = []
89
-
90
- # lvs columns will become lv attributes
91
- attributes = YAML.load_file(File.dirname(__FILE__) + '/' + ATTRIBUTES)
92
-
93
- output.split("\n").each do |line|
94
- line.strip!
95
- # each line of output is comma separated values
96
- values = line.split(",")
97
- # empty values to nil
98
- values.map! do |value|
99
- if value.empty?
100
- nil
101
- else
102
- value
103
- end
104
- end
105
-
106
- args = {}
107
- # match up attribute => value
108
- values.size.times do |i|
109
- method = attributes[i][:method].to_sym
110
- value = values[i]
111
- # use our hints first for type conversion
112
- if attributes[i][:type_hint] == "Integer"
113
- value = value.to_i
114
- elsif attributes[i][:type_hint] == "Float"
115
- value = value.to_f
116
- end
117
- args[method] = value
118
- end
119
-
120
- # LVSEG
121
-
122
- # now we force some types to ints since we've requested them as bytes
123
- # without a suffix
124
- args[:size] = args[:size].to_i
125
-
126
- # we resolve the attributes line to nicer symbols
127
- args.merge!(parse_lv_attr(args[:attr]))
128
-
129
- # finally build our object
130
- volume = LogicalVolume.new(args)
131
-
132
- if block_given?
133
- yield volume
134
- else
135
- volumes << volume
136
- end
137
- end
138
-
139
- volumes
140
- end # parse
141
-
142
- end # class
143
- end # module