Puppet Version: Demonstrated on 6.14.0 Puppet Server Version: N/A - validated locally OS Name/Version: Tested with both CentOS 7 and MacOS 10.15.7 Given the following implementation of a Ruby language data type located at moduleroot/lib/puppet/datatypes/schedule.rb:
Puppet::DataTypes.create_type('Mytype::Schedule') do |
interface <<-PUPPET |
attributes => { |
"name" => Mytype::Name, |
"soak_time" => { |
type => Timespan, |
value => Timespan('hours' => 3), |
}, |
"start_time" => Timestamp, |
} |
PUPPET |
My intent was to provide a default value for the soak_time attribute so that if a value isn't provided then we would default to a Timespan of 3 hours. When I declare an instance of this type without a soak_time value, I get the following error:
Evaluation Error: Error while evaluating a Type-Name, The expression <Timespan('hours' => 3)> is not a valid type specification. |
I thought that perhaps I was declaring that object incorrectly, so I tried to following declarations for the right side of the 'value' key in the code above and received the following errors: Timespan('0-03:00:00')
Evaluation Error: Error while evaluating a Type-Name, The expression <Timespan('0-03:00:00')> is not a valid type specification. |
Timespan.new('0-03:00:00')
Evaluation Error: Error while evaluating a Type-Name, The expression <Timespan.new('03:00:00')> is not a valid type specification. |
'0-03:00:00'
Evaluation Error: Error while evaluating a Type-Name, attribute Mytype::Schedule[soak_time] value has wrong type, expects a Timespan value, got String |
Timespan['0-03:00:00']
Error while evaluating a Type-Name, attribute Mytype::Schedule[soak_time] value has wrong type, expects a Timespan value, got Type[Timespan] |
Puppet::Pops::Time::Timespan.parse('0-03:00:00')
Error while evaluating a Type-Name, The expression <Puppet::Pops::Time::Timespan.parse('0-03:00:00')> is not a valid type specification. |
At this point I tried to be clever and instantiate a variable holding a Timespan object, and then pass that in to the interface HEREDOC string:
Puppet::DataTypes.create_type('Mytype::Schedule') do |
@timespan = Puppet::Pops::Time::Timespan.parse('0-03:00:00') |
interface <<-PUPPET |
attributes => { |
"name" => Mytype::Name, |
"soak_time" => { |
type => Timespan, |
value => @timespan, |
}, |
"start_time" => Timestamp, |
} |
PUPPET |
|
load_file 'puppet_x/Mytype/schedule' |
|
implementation_class PuppetX::Mytype::Schedule |
end |
**That gets you this DIFFERENT error:
Evaluation Error: Error while evaluating a Type-Name, Data Type Load Error for type 'Mytype::Schedule': can't modify frozen #<Class:#<Puppet::DataTypes::TypeBuilderAPI:0x00007fedbc9bfdf0> |
Desired Behavior: A default value for the data type that contains a Timespan object Actual Behavior: So many errors.... For fun you can view the Slack conversation I had with Henrik Lindberg at this link: https://puppetcommunity.slack.com/archives/C0W1X7ZAL/p1603473374140600 |