| 1 |
# Copyright (C) 2016 Mirantis Inc. |
| 2 |
# |
| 3 |
# Author: Matthew Mosesohn <[email protected]> |
| 4 |
# |
| 5 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 |
# not use this file except in compliance with the License. You may obtain |
| 7 |
# a copy of the License at |
| 8 |
# |
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, software |
| 12 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 |
# License for the specific language governing permissions and limitations |
| 15 |
# under the License. |
| 16 |
# |
| 17 |
# nova_security_group type |
| 18 |
# |
| 19 |
# == Parameters |
| 20 |
# [*name*] |
| 21 |
# Name for the host |
| 22 |
# Required |
| 23 |
# |
| 24 |
# [*ensure*] |
| 25 |
# Marks status of service(s) on a given host. |
| 26 |
# Possible values are enabled, disabled, purged |
| 27 |
# Optional |
| 28 |
# |
| 29 |
# [*service_name*] |
| 30 |
# Name of a given service. Defaults to "undef", which modifies all. |
| 31 |
# Optional |
| 32 |
# |
| 33 |
|
| 34 |
|
| 35 |
require 'puppet' |
| 36 |
|
| 37 |
Puppet::Type.newtype(:nova_service) do |
| 38 |
|
| 39 |
@doc = "Manage status of nova services on hosts." |
| 40 |
|
| 41 |
ensurable |
| 42 |
|
| 43 |
# Require the nova-api service to be running |
| 44 |
autorequire(:anchor) do |
| 45 |
['nova::service::end'] |
| 46 |
end |
| 47 |
|
| 48 |
newparam(:name, :namevar => true) do |
| 49 |
desc 'Name of host' |
| 50 |
validate do |value| |
| 51 |
if not value.is_a? String |
| 52 |
raise ArgumentError, "name parameter must be a String" |
| 53 |
end |
| 54 |
unless value =~ /^[a-zA-Z0-9\-_.]+$/ |
| 55 |
raise ArgumentError, "#{value} is not a valid name" |
| 56 |
end |
| 57 |
end |
| 58 |
end |
| 59 |
|
| 60 |
newproperty(:ids) do |
| 61 |
desc 'The unique Ids of the compute service' |
| 62 |
validate do |v| |
| 63 |
raise ArgumentError, 'This is a read only property' |
| 64 |
end |
| 65 |
end |
| 66 |
|
| 67 |
newproperty(:service_name, :array_matching => :all) do |
| 68 |
desc "String or Array of services on a host to modify" |
| 69 |
validate do |value| |
| 70 |
raise( |
| 71 |
ArgumentError, |
| 72 |
'service_name parameter must be String or Array' |
| 73 |
) unless [String, Array].any? { |type| value.is_a? type } |
| 74 |
end |
| 75 |
defaultto [] |
| 76 |
end |
| 77 |
|
| 78 |
end |