summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/alt_fqdns.rb17
-rw-r--r--lib/puppet/parser/functions/tripleo_swift_devices.rb39
-rw-r--r--lib/puppet/provider/sriov_vf_config/numvfs.rb57
-rw-r--r--lib/puppet/type/sriov_vf_config.rb10
4 files changed, 120 insertions, 3 deletions
diff --git a/lib/facter/alt_fqdns.rb b/lib/facter/alt_fqdns.rb
index 8a4d59b..216beef 100644
--- a/lib/facter/alt_fqdns.rb
+++ b/lib/facter/alt_fqdns.rb
@@ -14,9 +14,9 @@
# under the License.
[
'external',
- 'internalapi',
+ 'internal_api',
'storage',
- 'storagemgmt',
+ 'storage_mgmt',
'tenant',
'management',
].each do |network|
@@ -24,10 +24,21 @@
setcode do
external_hostname_parts = [
Facter.value(:hostname),
- network,
+ network.gsub('_', ''),
Facter.value(:domain),
].reject { |part| part.nil? || part.empty? }
external_hostname_parts.join(".")
end
end
end
+# map ctlplane network to management fqdn
+Facter.add('fqdn_ctlplane') do
+ setcode do
+ hostname_parts = [
+ Facter.value(:hostname),
+ 'management',
+ Facter.value(:domain),
+ ].reject { |part| part.nil? || part.empty? }
+ hostname_parts.join(".")
+ end
+end
diff --git a/lib/puppet/parser/functions/tripleo_swift_devices.rb b/lib/puppet/parser/functions/tripleo_swift_devices.rb
new file mode 100644
index 0000000..b320d62
--- /dev/null
+++ b/lib/puppet/parser/functions/tripleo_swift_devices.rb
@@ -0,0 +1,39 @@
+# Build Swift devices list from the parts, e.g. for:
+# raw_disk_prefix = 'r1z1-'
+# swift_storage_node_ips = ['192.168.1.12', '192.168.1.13']
+# raw_disks = [':%PORT%/device1', ':%PORT%/device2']
+#
+# devices will be ['r1z1-192.168.1.12:%PORT%/device1',
+# 'r1z1-192.168.1.12:%PORT%/device2'
+# 'r1z1-192.168.1.13:%PORT%/device1'
+# 'r1z1-192.168.1.13:%PORT%/device2']
+module Puppet::Parser::Functions
+ newfunction(:tripleo_swift_devices, :arity =>3, :type => :rvalue,
+ :doc => ("Build list of swift devices the TripleO way:" +
+ "from a raw disk prefix, a list of swift storage" +
+ "node IPs, and a list of raw disks.")) do |args|
+
+ raw_disk_prefix = args[0]
+ swift_node_ips = args[1]
+ raw_disks = args[2]
+
+ unless raw_disk_prefix.is_a?(String)
+ raise Puppet::ParseError, "tripleo_swift_devices: Argument 'raw_disk_prefix' must be a string. The value given was: #{raw_disk_prefix}"
+ end
+ unless swift_node_ips.is_a?(Array)
+ raise Puppet::ParseError, "tripleo_swift_devices: Argument 'swift_node_ips' must be an array. The value given was: #{swift_node_ips}"
+ end
+ unless raw_disks.is_a?(Array)
+ raise Puppet::ParseError, "tripleo_swift_devices: Argument 'raw_disks' must be an array. The value given was: #{raw_disks}"
+ end
+
+ devices = []
+ for ip in swift_node_ips do
+ for disk in raw_disks do
+ devices << "#{raw_disk_prefix}#{ip}#{disk}"
+ end
+ end
+
+ return devices
+ end
+end
diff --git a/lib/puppet/provider/sriov_vf_config/numvfs.rb b/lib/puppet/provider/sriov_vf_config/numvfs.rb
new file mode 100644
index 0000000..cfa663c
--- /dev/null
+++ b/lib/puppet/provider/sriov_vf_config/numvfs.rb
@@ -0,0 +1,57 @@
+Puppet::Type.type(:sriov_vf_config).provide(:numvfs) do
+ desc <<-EOT
+ The file /sys/class/net/<sriov_interface_name>/device/sriov_numvfs will be
+ present when a physical PCIe device supports SR-IOV. A number written to
+ this file will enable the specified number of VFs. This provider shall read
+ the file and ensure that the value is zero, before writing the number of
+ VFs that should be enabled. If the VFs needs to be disabled then we shall
+ write a zero to this file.
+ EOT
+
+ def create
+ if File.file?(sriov_numvfs_path)
+ _set_numvfs
+ else
+ fail("#{sriov_numvfs_path} doesn't exist. Check if #{sriov_get_interface} is a valid network interface supporting SR-IOV")
+ end
+ end
+
+ def destroy
+ if File.file?(sriov_numvfs_path)
+ File.write(sriov_numvfs_path,"0")
+ end
+ end
+
+ def exists?
+ if File.file?(sriov_numvfs_path)
+ cur_value = File.read(sriov_numvfs_path)
+ if cur_value.to_i == sriov_numvfs_value
+ return true
+ end
+ end
+ return false
+ end
+
+ def _set_numvfs
+ # During an update, the content of file sriov_numvfs_path has to be set
+ # to 0 (ZERO), before writing the actual value
+ cur_value = File.read(sriov_numvfs_path)
+ if cur_value != 0
+ File.write(sriov_numvfs_path,"0")
+ end
+ File.write(sriov_numvfs_path,sriov_numvfs_value)
+ end
+
+ def sriov_numvfs_path
+ "/sys/class/net/#{sriov_get_interface}/device/sriov_numvfs"
+ end
+
+ def sriov_get_interface
+ resource[:name].split(':', 2).first
+ end
+
+ def sriov_numvfs_value
+ resource[:name].split(':', 2).last.to_i
+ end
+
+end
diff --git a/lib/puppet/type/sriov_vf_config.rb b/lib/puppet/type/sriov_vf_config.rb
new file mode 100644
index 0000000..09a3671
--- /dev/null
+++ b/lib/puppet/type/sriov_vf_config.rb
@@ -0,0 +1,10 @@
+Puppet::Type.newtype(:sriov_vf_config) do
+
+ ensurable
+
+ newparam(:name) do
+ desc "sriov_numvfs conf as <physical_network>:<number_of_vfs> format"
+ newvalues(/^[a-z0-9\-_]+:[0-9]+$/)
+ end
+
+end