-
Notifications
You must be signed in to change notification settings - Fork 30
flush out logical volume support #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# LinuxAdmin Physical Volume Representation | ||
# | ||
# Copyright (C) 2013 Red Hat Inc. | ||
# Licensed under the MIT License | ||
|
||
class LinuxAdmin | ||
class PhysicalVolume < LinuxAdmin | ||
# physical volume device name | ||
attr_accessor :device_name | ||
|
||
# volume group name | ||
attr_accessor :volume_group | ||
|
||
# physical volume size in kilobytes | ||
attr_accessor :size | ||
|
||
# other fields available | ||
# internal physical volume number (obsolete) | ||
# physical volume status | ||
# physical volume (not) allocatable | ||
# current number of logical volumes on this physical volume | ||
# physical extent size in kilobytes | ||
# total number of physical extents | ||
# free number of physical extents | ||
# allocated number of physical extents | ||
|
||
def initialize(args = {}) | ||
@device_name = args[:device_name] | ||
@volume_group = args[:volume_group] | ||
@size = args[:size] | ||
end | ||
|
||
def self.scan | ||
@pvs ||= begin | ||
vgs = VolumeGroup.scan | ||
pvs = [] | ||
|
||
out = run(cmd(:pvdisplay), | ||
:return_output => true, | ||
:params => { '-c' => nil}) | ||
|
||
out.each_line do |line| | ||
fields = line.split(':') | ||
vgname = fields[1] | ||
vg = vgs.find { |vg| vg.name == vgname} | ||
|
||
pvs << PhysicalVolume.new(:device_name => fields[0], | ||
:volume_group => vg, | ||
:size => fields[2].to_i) | ||
end | ||
|
||
pvs | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# LinuxAdmin Volume Group Representation | ||
# | ||
# Copyright (C) 2013 Red Hat Inc. | ||
# Licensed under the MIT License | ||
|
||
class LinuxAdmin | ||
class VolumeGroup < LinuxAdmin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @movitto Same as above |
||
# volume group name | ||
attr_accessor :name | ||
|
||
# other fields available | ||
# volume group access | ||
# volume group status | ||
# internal volume group number | ||
# maximum number of logical volumes | ||
# current number of logical volumes | ||
# open count of all logical volumes in this volume group | ||
# maximum logical volume size | ||
# maximum number of physical volumes | ||
# current number of physical volumes | ||
# actual number of physical volumes | ||
# size of volume group in kilobytes | ||
# physical extent size | ||
# total number of physical extents for this volume group | ||
# allocated number of physical extents for this volume group | ||
# free number of physical extents for this volume group | ||
# uuid of volume group | ||
|
||
def initialize(args = {}) | ||
@name = args[:name] | ||
end | ||
|
||
def self.scan | ||
@vgs ||= begin | ||
vgs = [] | ||
|
||
out = run(cmd(:vgdisplay), | ||
:return_output => true, | ||
:params => { '-c' => nil}) | ||
|
||
out.each_line do |line| | ||
fields = line.split(':') | ||
vgs << VolumeGroup.new(:name => fields[0]) | ||
end | ||
|
||
vgs | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'spec_helper' | ||
|
||
describe LinuxAdmin::LogicalVolume do | ||
before(:each) do | ||
LinuxAdmin::Distro.stub(:local). | ||
and_return(LinuxAdmin::Distros::Test.new) | ||
|
||
@logical_volumes = <<eos | ||
/dev/vg_foobar/lv_swap:vg_foobar:3:1:-1:2:4128768:63:-1:0:-1:253:0 | ||
/dev/vg_foobar/lv_root:vg_foobar:3:1:-1:1:19988480:305:-1:0:-1:253:1 | ||
eos | ||
|
||
@groups = <<eos | ||
vg_foobar:r/w:772:-1:0:2:2:-1:0:1:1:12058624:32768:368:368:0:tILZUF-IspH-H90I-pT5j-vVFl-b76L-zWx3CW | ||
eos | ||
end | ||
|
||
after(:each) do | ||
# reset local copies of volumes / groups | ||
LinuxAdmin::LogicalVolume.instance_variable_set(:@lvs, nil) | ||
LinuxAdmin::PhysicalVolume.instance_variable_set(:@pvs, nil) | ||
LinuxAdmin::VolumeGroup.instance_variable_set(:@vgs, nil) | ||
end | ||
|
||
describe "#scan" do | ||
it "uses lvdisplay" do | ||
LinuxAdmin::LogicalVolume.should_receive(:run). | ||
with(LinuxAdmin.cmd(:lvdisplay), | ||
:return_output => true, | ||
:params => { '-c' => nil}). | ||
and_return(@logical_volumes) | ||
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups) # stub out call to vgdisplay | ||
LinuxAdmin::LogicalVolume.scan | ||
end | ||
|
||
it "returns local logical volumes" do | ||
LinuxAdmin::LogicalVolume.should_receive(:run).and_return(@logical_volumes) | ||
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups) | ||
lvs = LinuxAdmin::LogicalVolume.scan | ||
|
||
lvs[0].should be_an_instance_of(LinuxAdmin::LogicalVolume) | ||
lvs[0].name.should == '/dev/vg_foobar/lv_swap' | ||
lvs[0].sectors.should == 4128768 | ||
|
||
lvs[1].should be_an_instance_of(LinuxAdmin::LogicalVolume) | ||
lvs[1].name.should == '/dev/vg_foobar/lv_root' | ||
lvs[1].sectors.should == 19988480 | ||
end | ||
|
||
it "resolves volume group references" do | ||
LinuxAdmin::LogicalVolume.should_receive(:run).and_return(@logical_volumes) | ||
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups) | ||
lvs = LinuxAdmin::LogicalVolume.scan | ||
lvs[0].volume_group.should be_an_instance_of(LinuxAdmin::VolumeGroup) | ||
lvs[0].volume_group.name.should == 'vg_foobar' | ||
lvs[1].volume_group.should be_an_instance_of(LinuxAdmin::VolumeGroup) | ||
lvs[1].volume_group.name.should == 'vg_foobar' | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'spec_helper' | ||
|
||
describe LinuxAdmin::PhysicalVolume do | ||
before(:each) do | ||
LinuxAdmin::Distro.stub(:local). | ||
and_return(LinuxAdmin::Distros::Test.new) | ||
|
||
@physical_volumes = <<eos | ||
/dev/vda2:vg_foobar:24139776:-1:8:8:-1:32768:368:0:368:pxR32D-YkC2-PfHe-zOwb-eaGD-9Ar0-mAOl9u | ||
eos | ||
|
||
@groups = <<eos | ||
vg_foobar:r/w:772:-1:0:2:2:-1:0:1:1:12058624:32768:368:368:0:tILZUF-IspH-H90I-pT5j-vVFl-b76L-zWx3CW | ||
eos | ||
end | ||
|
||
after(:each) do | ||
# reset local copies of volumes / groups | ||
LinuxAdmin::LogicalVolume.instance_variable_set(:@lvs, nil) | ||
LinuxAdmin::PhysicalVolume.instance_variable_set(:@pvs, nil) | ||
LinuxAdmin::VolumeGroup.instance_variable_set(:@vgs, nil) | ||
end | ||
|
||
describe "#scan" do | ||
it "uses pvdisplay" do | ||
LinuxAdmin::PhysicalVolume.should_receive(:run). | ||
with(LinuxAdmin.cmd(:pvdisplay), | ||
:return_output => true, | ||
:params => { '-c' => nil}). | ||
and_return(@physical_volumes) | ||
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups) # stub out call to vgdisplay | ||
LinuxAdmin::PhysicalVolume.scan | ||
end | ||
|
||
it "returns local physical volumes" do | ||
LinuxAdmin::PhysicalVolume.should_receive(:run).and_return(@physical_volumes) | ||
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups) | ||
pvs = LinuxAdmin::PhysicalVolume.scan | ||
|
||
pvs[0].should be_an_instance_of(LinuxAdmin::PhysicalVolume) | ||
pvs[0].device_name.should == '/dev/vda2' | ||
pvs[0].size.should == 24139776 | ||
end | ||
|
||
it "resolves volume group references" do | ||
LinuxAdmin::PhysicalVolume.should_receive(:run).and_return(@physical_volumes) | ||
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups) | ||
pvs = LinuxAdmin::PhysicalVolume.scan | ||
pvs[0].volume_group.should be_an_instance_of(LinuxAdmin::VolumeGroup) | ||
pvs[0].volume_group.name.should == 'vg_foobar' | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'spec_helper' | ||
|
||
describe LinuxAdmin::VolumeGroup do | ||
before(:each) do | ||
LinuxAdmin::Distro.stub(:local). | ||
and_return(LinuxAdmin::Distros::Test.new) | ||
|
||
@groups = <<eos | ||
vg_foobar:r/w:772:-1:0:2:2:-1:0:1:1:12058624:32768:368:368:0:tILZUF-IspH-H90I-pT5j-vVFl-b76L-zWx3CW | ||
eos | ||
end | ||
|
||
after(:each) do | ||
# reset local copies of volumes / groups | ||
LinuxAdmin::LogicalVolume.instance_variable_set(:@lvs, nil) | ||
LinuxAdmin::PhysicalVolume.instance_variable_set(:@pvs, nil) | ||
LinuxAdmin::VolumeGroup.instance_variable_set(:@vgs, nil) | ||
end | ||
|
||
describe "#scan" do | ||
it "uses vgdisplay" do | ||
LinuxAdmin::VolumeGroup.should_receive(:run). | ||
with(LinuxAdmin.cmd(:vgdisplay), | ||
:return_output => true, | ||
:params => { '-c' => nil}). | ||
and_return(@groups) | ||
LinuxAdmin::VolumeGroup.scan | ||
end | ||
|
||
it "returns local volume groups" do | ||
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups) | ||
vgs = LinuxAdmin::VolumeGroup.scan | ||
|
||
vgs[0].should be_an_instance_of(LinuxAdmin::VolumeGroup) | ||
vgs[0].name.should == 'vg_foobar' | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@movitto I just noticed we're subclassing in many places... are we doing that for the methods from Common? If so, can't we just use include/extend to gain that behavior?