Remove un-used cliout2list provider function
Since the addition of the OpenStack provider for security groups, this function in not used. Change-Id: Ib9d7de38ee510c8ddb5725b2ac4a775028e75dc9
This commit is contained in:
parent
2e5e936595
commit
04a47ab6f1
|
@ -207,35 +207,4 @@ class Puppet::Provider::Nova < Puppet::Provider::Openstack
|
|||
end
|
||||
end
|
||||
|
||||
# deprecated: nova cli to list
|
||||
def self.cliout2list(output)
|
||||
#don't proceed with empty output
|
||||
if output.empty?
|
||||
return []
|
||||
end
|
||||
lines = []
|
||||
output.each_line do |line|
|
||||
#ignore lines starting with '+'
|
||||
if not line.match("^\\+")
|
||||
#split line at '|' and remove useless information
|
||||
line = line.gsub(/^\| /, "").gsub(/ \|$/, "").gsub(/[\n]+/, "")
|
||||
line = line.split("|").map do |el|
|
||||
el.strip().gsub(/^-$/, "")
|
||||
end
|
||||
#check every element for list
|
||||
line = line.map do |el|
|
||||
el = str2list(el)
|
||||
end
|
||||
lines.push(line)
|
||||
end
|
||||
end
|
||||
#create a list of hashes and return the list
|
||||
hash_list = []
|
||||
header = lines[0]
|
||||
lines[1..-1].each do |line|
|
||||
hash_list.push(Hash[header.zip(line)])
|
||||
end
|
||||
return hash_list
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -145,144 +145,4 @@ describe Puppet::Provider::Nova do
|
|||
expect(res).to eq({"a"=>"b"})
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when parsing cli output' do
|
||||
|
||||
it 'should return a list with hashes' do
|
||||
output = <<-EOT
|
||||
+----+-------+-------------------+
|
||||
| Id | Name | Availability Zone |
|
||||
+----+-------+-------------------+
|
||||
| 1 | haha | haha2 |
|
||||
| 2 | haha2 | - |
|
||||
+----+-------+-------------------+
|
||||
EOT
|
||||
res = klass.cliout2list(output)
|
||||
expect(res).to eq([{"Id"=>"1", "Name"=>"haha", "Availability Zone"=>"haha2"},
|
||||
{"Id"=>"2", "Name"=>"haha2", "Availability Zone"=>""}])
|
||||
end
|
||||
|
||||
it 'should return a list with hashes' do
|
||||
output = <<-EOT
|
||||
+----+-------+-------------------+-------+--------------------------------------------------+
|
||||
| Id | Name | Availability Zone | Hosts | Metadata |
|
||||
+----+-------+-------------------+-------+--------------------------------------------------+
|
||||
| 16 | agg94 | my_-zone1 | | 'a=b', 'availability_zone= my_-zone1', 'x_q-r=y' |
|
||||
+----+-------+-------------------+-------+--------------------------------------------------+
|
||||
EOT
|
||||
res = klass.cliout2list(output)
|
||||
expect(res).to eq([{"Id"=>"16",
|
||||
"Name"=>"agg94",
|
||||
"Availability Zone"=>"my_-zone1",
|
||||
"Hosts"=>"",
|
||||
"Metadata"=> {
|
||||
"a"=>"b",
|
||||
"availability_zone"=>" my_-zone1",
|
||||
"x_q-r"=>"y"
|
||||
}
|
||||
}])
|
||||
end
|
||||
|
||||
it 'should return a empty list' do
|
||||
output = <<-EOT
|
||||
+----+------+-------------------+
|
||||
| Id | Name | Availability Zone |
|
||||
+----+------+-------------------+
|
||||
+----+------+-------------------+
|
||||
EOT
|
||||
res = klass.cliout2list(output)
|
||||
expect(res).to eq([])
|
||||
end
|
||||
|
||||
it 'should return a empty list because no input available' do
|
||||
output = <<-EOT
|
||||
EOT
|
||||
res = klass.cliout2list(output)
|
||||
expect(res).to eq([])
|
||||
end
|
||||
|
||||
it 'should return a list with hashes' do
|
||||
output = <<-EOT
|
||||
+----+----------------+-------------------+
|
||||
| Id | Name | Availability Zone |
|
||||
+----+----------------+-------------------+
|
||||
| 6 | my | zone1 |
|
||||
| 8 | my2 | - |
|
||||
+----+----------------+-------------------+
|
||||
EOT
|
||||
res = klass.cliout2list(output)
|
||||
expect(res).to eq([{"Id"=>"6", "Name"=>"my", "Availability Zone"=>"zone1"},
|
||||
{"Id"=>"8", "Name"=>"my2", "Availability Zone"=>""}])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when parsing cli output with cells enabled' do
|
||||
|
||||
it 'should return a list with hashes' do
|
||||
output = <<-EOT
|
||||
+-------------+----------------+-------------------+
|
||||
| Id | Name | Availability Zone |
|
||||
+-------------+----------------+-------------------+
|
||||
| api!cell@1 | api!cell@haha | haha2 |
|
||||
| api!cell@2 | api!cell@haha2 | - |
|
||||
+-------------+----------------+-------------------+
|
||||
EOT
|
||||
res = klass.cliout2list(output)
|
||||
expect(res).to eq([{"Id"=>"api!cell@1", "Name"=>"api!cell@haha", "Availability Zone"=>"haha2"},
|
||||
{"Id"=>"api!cell@2", "Name"=>"api!cell@haha2", "Availability Zone"=>""}])
|
||||
end
|
||||
|
||||
it 'should return a list with hashes' do
|
||||
output = <<-EOT
|
||||
+-------------+----------------+-------------------+-------+--------------------------------------------------+
|
||||
| Id | Name | Availability Zone | Hosts | Metadata |
|
||||
+-------------+----------------+-------------------+-------+--------------------------------------------------+
|
||||
| api!cell@16 | api!cell@agg94 | my_-zone1 | | 'a=b', 'availability_zone= my_-zone1', 'x_q-r=y' |
|
||||
+-------------+----------------+-------------------+-------+--------------------------------------------------+
|
||||
EOT
|
||||
res = klass.cliout2list(output)
|
||||
expect(res).to eq([{"Id"=>"api!cell@16",
|
||||
"Name"=>"api!cell@agg94",
|
||||
"Availability Zone"=>"my_-zone1",
|
||||
"Hosts"=>"",
|
||||
"Metadata"=> {
|
||||
"a"=>"b",
|
||||
"availability_zone"=>" my_-zone1",
|
||||
"x_q-r"=>"y"
|
||||
}
|
||||
}])
|
||||
end
|
||||
|
||||
it 'should return a empty list' do
|
||||
output = <<-EOT
|
||||
+----+------+-------------------+
|
||||
| Id | Name | Availability Zone |
|
||||
+----+------+-------------------+
|
||||
+----+------+-------------------+
|
||||
EOT
|
||||
res = klass.cliout2list(output)
|
||||
expect(res).to eq([])
|
||||
end
|
||||
|
||||
it 'should return a empty list because no input available' do
|
||||
output = <<-EOT
|
||||
EOT
|
||||
res = klass.cliout2list(output)
|
||||
expect(res).to eq([])
|
||||
end
|
||||
|
||||
it 'should return a list with hashes' do
|
||||
output = <<-EOT
|
||||
+-------------+-------------------------+-------------------+
|
||||
| Id | Name | Availability Zone |
|
||||
+-------------+-------------------------+-------------------+
|
||||
| api!cell@6 | api!cell@my | zone1 |
|
||||
| api!cell@8 | api!cell@my2 | - |
|
||||
+-------------+-------------------------+-------------------+
|
||||
EOT
|
||||
res = klass.cliout2list(output)
|
||||
expect(res).to eq([{"Id"=>"api!cell@6", "Name"=>"api!cell@my", "Availability Zone"=>"zone1"},
|
||||
{"Id"=>"api!cell@8", "Name"=>"api!cell@my2", "Availability Zone"=>""}])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue