Puppet: Get MAC address for specified ethernet interface - puppet

I'm trying to populate a config file with a MAC address for a specified ethernet adapter.
The name of the ethernet adapter (e.g. eth1) is a parameter of my defined type. When I try to populate a config file through puppet with an erb template which accesses the macaddress facter fact, that gives me the mac address for the eth0 interface, which is the wrong one (in this instance).
How can I create a variable in my defined type which takes the value of facter macaddress_ethernetinterface where ethernetinterface is defined by a parameter of the defined type?

There is a whole family of macaddress facts, one for each interface.
notify { "eth1 has ${macaddress_eth1}": }
In your template, you can access the variable name that includes a parameter (say, $interface) like
<%= scope.lookupvar("macaddress_#{ #interface }") %>
Future versions of Facter will supply a hash that will allow looking up MAC addresses per interface.

Related

How to create an array of interface of different size in system verilog

I have a configurable module which contains an interface for one of the ports. I use a generate statement and a for loop to create different configuration of each module instance and I bring the interface ports out in an array. My issue is the individual interfaces are different based of the config of each module instance. Is there a way to configure each interface in the array individually? This is how I correctly configure the interface
test_if #(.NUM_CUTS(NUM_CUTS_WRITE_CLIENT),.AW(AW_WRITE_CLIENT),.DW(DW_WRITE_CLIENT)) mem_test_if [NUM_OF_MEMS-1:0]();
Is it possible to do something like this with an array of interfaces
test_if #(.NUM_CUTS(2),.AW(AW_WRITE_CLIENT),.DW(DW_WRITE_CLIENT)) mem_test_if [0]();
test_if #(.NUM_CUTS(4),.AW(AW_WRITE_CLIENT),.DW(DW_WRITE_CLIENT)) mem_test_if [1]();
test_if #(.NUM_CUTS(6),.AW(AW_WRITE_CLIENT),.DW(DW_WRITE_CLIENT)) mem_test_if [2]();
I don't want to have to instantiate each module instance separately outside of the generate statement.
You should be able to do this nested inside your generate
for(genvar MEM=0;MEM<NO_OF_MEMS;MEM++) begin : ID
test_if #(.NUM_CUTS((MEM+1)*2),.AW(AW_WRITE_CLIENT),.DW(DW_WRITE_CLIENT)) mem_test_if();
end

Conditionally ignore parameter in Terraform if its value is not provided?

I am using "google_sql_database_instance" resource to create a cloud instance with private IP only and taking the value for _private_network_ from variables file or command line argument or no value provided at all.
All I am trying to achieve is, create private IP instance only if private_network is provided and include _private_network_ parameter only if its value is provided. The problem here is this variable doesn't accept empty string ("") as it validates the bellow regular expression.
"projects/((?:(?:[-a-z0-9]{1,63}\\.)*(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?):)?(?:[0-9]{1,19}|(?:[a-z0-9](?:[-a-z0-9]{0,61}[a-z0-9])?)))/global/networks/((?:[a-z](?:[-a-z0-9]*[a-z0-9])?))$".
How would I make a module which is configurable (create private IP instance only if private_network is provided otherwise ignore the parameter completely) and does not compulsorily asks for the value of _private_network_ variable?
The old approach to this would be to pass an empty string ("") to the parameter and the provider would ignore it by convention.
Unfortunately this isn't done everywhere across all providers yet so if you are unable to pass an empty string due to validation on the parameter then you're stuck for now.
The options you have are to raise a pull request for the provider allowing you to pass an empty string, create a second module that differs only by whether it has a private network, or wait for Terraform 0.12 which will introduce the null value that will then make Terraform core ignore the parameter entirely.
The last option is the best one in my opinion but if you have an urgent need (currently no expected release date for 0.12 other than when it's ready) then I'd split the module into two for now to get you able to achieve this and then you can drop the private clone of the module and use the null value when 0.12 is released and you have upgraded to it.

DBus object path: where to find it?

I'm trying to implement some function of AVRCP protocol. Here the documentation:
http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/media-api.txt
what I don't understand is how to retreive the object path of my player:
Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/playerX
I'm not sure if it is returned from some DBus methods or I have to manually build it using the bluetooth address and the local device.
I'm not sure if it is returned from some DBus methods or I have to
manually build it using the bluetooth address and the local device.
The former. You(the application I assume) do not need build this object path, the path would return by some DBus methods.
Here the object meaning:
Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/playerX
[variable prefix] was null basically.
{hci0,hci1,...} was which of your Bluetooth chip, basically it should be hci0.
/dev_XX_XX_XX_XX_XX_XX remote device mac address.
/playerX which player of your target.
You do not need pay much attention of the object path's material, it just a string actually(combined by stack according to specific format)
You may refer:
Properties
boolean Connected [readonly]
object Player [readonly, optional]
Addressed Player object path.

Collect values from other puppet classes

I'm trying to implement automatic monitoring using nagios/icinga and puppet.
Hosts and basic services are working but now I want to implement different checks for services based on hostgroups. While I could setup the hostgroups in hiera I want to be able to do the following:
Apply a class for each service (like ssh, http) which only "exports" a hostgroup-name (like "ssh-servers" and "http-servers"
and also apply a base class which "collects" these names, joins them to a string and exports a nagios_host resource like this:
##nagios_host { $::fqdn:
ensure => present,
use => "generic-host",
alias => $::hostname,
address => $::ipaddress,
hostgroups => $hostgroups, # this should be something like "ssh-servers, http-servers"
}
I'm just starting with puppet and looked at virtual resources and exported resources but I'm not sure how to apply this correctly. Is this even possible?
The export/import paradigm does not lend itself well to this type of data gathering. If you want to take advantage of it, you will need to define resource types that Just Work when gathered on the Nagios server from all the agent catalogs.
Your mileage might very well increase if you try and rely on PuppetDB queries instead. You get much more control this way.

puppet resource command with title munge

I've created a puppet resource for interfaces. Most of the interface names on my switch are lowercase with the exception of Ethernet interfaces, so I munged the interface name to hopefully reduce errors in the manifest; e.g.:
manifest:
cisco_interface { 'Ethernet1/1': description => 'foo' }
type/cisco_interface.rb:
newparam(:name) do
munge { |value|
value.downcase
}
end
My provider code also downcases the interface names when I collect the list of interfaces with self.instances.
Okay, so this works great when I test with the manifest, but not so great with the puppet resource command which only works when I call it with the name already downcased:
switch# puppet resource cisco_interface 'Ethernet1/1'
cisco_interface { 'Ethernet1/1':
ensure => 'absent',
}
switch# puppet resource cisco_interface 'ethernet1/1'
cisco_interface { 'ethernet1/1':
ensure => 'present',
description => 'foo',
}
The puppet resource command name field seems to just be a simple filter so I think I'm stuck, but I thought I'd seen other resource types munging title values like this.
Is it possible to munge the title values in a way that works for both scenarios?
If not then I'm not sure whether it would be better to leave it case-sensitive since that is what users will see in the switch config, or to "help" them avoid errors in the manifest.
You are correct about what is happening here, puppet currently requires that the name passed into the command line exactly matches the name according to the type. It's buried a couple levels deep, but look at the find and resource_name methods of the RAL.
It doesn't seem to me like this would be a major change, so you might want to log a defect or make the change yourself!

Resources