Module: Cucumber::Chef::Helpers::Utility

Defined in:
lib/cucumber/chef/helpers/utility.rb

Overview

Author: Stephen Nelson-Smith <[email protected]>

   Author: Zachary Patten <[email protected]>
Copyright: Copyright (c) 2011-2012 Atalanta Systems Ltd
  License: Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Instance Method Summary collapse

Instance Method Details

#generate_ipObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cucumber/chef/helpers/utility.rb', line 33

def generate_ip
  octets = [ 192..192,
             168..168,
             0..254,
             1..254 ]
  ip = ""
  for x in 1..4 do
    ip += octets[x-1].to_a[rand(octets[x-1].count)].to_s
    ip += "." if x != 4
  end
  ip
end

#generate_macObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cucumber/chef/helpers/utility.rb', line 48

def generate_mac
  digits = [ %w( 0 ),
             %w( 0 ),
             %w( 0 ),
             %w( 0 ),
             %w( 5 ),
             %w( e ),
             %w( 0 1 2 3 4 5 6 7 8 9 a b c d e f ),
             %w( 0 1 2 3 4 5 6 7 8 9 a b c d e f ),
             %w( 5 6 7 8 9 a b c d e f ),
             %w( 3 4 5 6 7 8 9 a b c d e f ),
             %w( 0 1 2 3 4 5 6 7 8 9 a b c d e f ),
             %w( 0 1 2 3 4 5 6 7 8 9 a b c d e f ) ]
  mac = ""
  for x in 1..12 do
    mac += digits[x-1][rand(digits[x-1].count)]
    mac += ":" if (x.modulo(2) == 0) && (x != 12)
  end
  mac
end

#log(name, message) ⇒ Object



26
27
28
29
# File 'lib/cucumber/chef/helpers/utility.rb', line 26

def log(name, message)
  STDOUT.puts("\033[34m  >>> \033[1m#{name}\033[0m\033[34m #{message}\033[0m")
  STDOUT.flush if STDOUT.respond_to?(:flush)
end