PageRenderTime 54ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/chef/resource/route.rb

https://github.com/adamhjk/chef
Ruby | 140 lines | 104 code | 18 blank | 18 comment | 0 complexity | 4ddee02b064472f8673847471baa95c1 MD5 | raw file
Possible License(s): Apache-2.0
  1. #
  2. # Author:: Bryan McLellan (btm@loftninjas.org)
  3. # Author:: Tyler Cloke (<tyler@opscode.com>)
  4. # Copyright:: Copyright (c) 2009 Bryan McLellan
  5. # License:: Apache License, Version 2.0
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. require 'chef/resource'
  20. class Chef
  21. class Resource
  22. class Route < Chef::Resource
  23. identity_attr :target
  24. state_attrs :netmask, :gateway
  25. def initialize(name, run_context=nil)
  26. super
  27. @resource_name = :route
  28. @target = name
  29. @action = [:add]
  30. @allowed_actions.push(:add, :delete)
  31. @netmask = nil
  32. @gateway = nil
  33. @metric = nil
  34. @device = nil
  35. @route_type = :host
  36. @networking = nil
  37. @networking_ipv6 = nil
  38. @hostname = nil
  39. @domainname = nil
  40. @domain = nil
  41. end
  42. def networking(arg=nil)
  43. set_or_return(
  44. :networking,
  45. arg,
  46. :kind_of => String
  47. )
  48. end
  49. def networking_ipv6(arg=nil)
  50. set_or_return(
  51. :networking_ipv6,
  52. arg,
  53. :kind_of => String
  54. )
  55. end
  56. def hostname(arg=nil)
  57. set_or_return(
  58. :hostname,
  59. arg,
  60. :kind_of => String
  61. )
  62. end
  63. def domainname(arg=nil)
  64. set_or_return(
  65. :domainname,
  66. arg,
  67. :kind_of => String
  68. )
  69. end
  70. def domain(arg=nil)
  71. set_or_return(
  72. :domain,
  73. arg,
  74. :kind_of => String
  75. )
  76. end
  77. def target(arg=nil)
  78. set_or_return(
  79. :target,
  80. arg,
  81. :kind_of => String
  82. )
  83. end
  84. def netmask(arg=nil)
  85. set_or_return(
  86. :netmask,
  87. arg,
  88. :kind_of => String
  89. )
  90. end
  91. def gateway(arg=nil)
  92. set_or_return(
  93. :gateway,
  94. arg,
  95. :kind_of => String
  96. )
  97. end
  98. def metric(arg=nil)
  99. set_or_return(
  100. :metric,
  101. arg,
  102. :kind_of => Integer
  103. )
  104. end
  105. def device(arg=nil)
  106. set_or_return(
  107. :device,
  108. arg,
  109. :kind_of => String
  110. )
  111. end
  112. def route_type(arg=nil)
  113. real_arg = arg.kind_of?(String) ? arg.to_sym : arg
  114. set_or_return(
  115. :route_type,
  116. real_arg,
  117. :equal_to => [ :host, :net ]
  118. )
  119. end
  120. end
  121. end
  122. end