Module: Puppet::Provider::Scli::ClassMethods

Defined in:
lib/puppet/provider/scli.rb

Instance Method Summary collapse

Instance Method Details

#consul_delete_key(key) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/puppet/provider/scli.rb', line 95

def consul_delete_key(key)
  Puppet.debug("ScaleIO #{key} removing consul key #{key}")
  consul_kv = Puppet::Type.type(:consul_kv).new(
      :name => "#{key}",
      :value => '1').provider
  tries = consul_kv.send('destroy') # retrive current try value
end

#consul_max_tries(key, max_tries) ⇒ Object

Increment the consul key by 1, until max_tries is reached. If max_tries is reached, Puppet run will fail



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/puppet/provider/scli.rb', line 74

def consul_max_tries(key, max_tries)
  consul_kv = Puppet::Type.type(:consul_kv).new(
      :name => "#{key}",
      :value => '1').provider
  tries = consul_kv.send('value') # retrive current try value

  tries = tries.empty? ? 1 : tries.to_i + 1
  if (tries >= max_tries)
    raise Puppet::Error, "Reached max_tries (#{tries}) for #{key}"
  end

  Puppet.debug("ScaleIO #{key} incrementing try number to #{tries}")

  # Update the key
  consul_kv = Puppet::Type.type(:consul_kv).new(
      :name => "#{key}",
      :value => "#{tries}").provider
  consul_kv.send('create')
  Puppet.debug("Key should be here")
end

#convert_size_to_bytes(size) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/puppet/provider/scli.rb', line 37

def convert_size_to_bytes(size)
  size_bytes = 0
  if size =~ /\((\d+) ([a-zA-Z]+)\)/i
    size_bytes = $1.to_i * (1024 ** 0) if $2 == 'Bytes'
    size_bytes = $1.to_i * (1024 ** 1) if $2 == 'KB'
    size_bytes = $1.to_i * (1024 ** 2) if $2 == 'MB'
    size_bytes = $1.to_i * (1024 ** 3) if $2 == 'GB'
    size_bytes = $1.to_i * (1024 ** 4) if $2 == 'TB'
    size_bytes = $1.to_i * (1024 ** 5) if $2 == 'PB'

    Puppet.debug("math #{$1.to_i} * #{(1024 ** 0)}") if $2 == 'Bytes'
    Puppet.debug("math #{$1.to_i} * #{(1024 ** 1)}") if $2 == 'KB'
    Puppet.debug("math #{$1.to_i} * #{(1024 ** 2)}") if $2 == 'MB'
    Puppet.debug("math #{$1.to_i} * #{(1024 ** 3)}") if $2 == 'GB'
    Puppet.debug("math #{$1.to_i} * #{(1024 ** 4)}") if $2 == 'TB'
    Puppet.debug("math #{$1.to_i} * #{(1024 ** 5)}") if $2 == 'PB'
  end
  return size_bytes
end

#port_open?(ip, port, seconds = 1) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/puppet/provider/scli.rb', line 58

def port_open?(ip, port, seconds=1)
  # => checks if a port is open or not on a remote host
  Timeout::timeout(seconds) do
    begin
      TCPSocket.new(ip, port).close
      true
    rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError
      false
    end
  end
rescue Timeout::Error
  false
end

#scli(*args) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/puppet/provider/scli.rb', line 7

def scli(*args)
  begin
    result = scli_wrap(args)
  rescue Puppet::ExecutionFailure => e
    raise Puppet::Error, "scli command #{args} had an error -> #{e.inspect}"
  end
  result
end

#scli_query_properties(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/puppet/provider/scli.rb', line 16

def scli_query_properties(*args)
  Puppet.debug("Querying scaleio properties #{args}")
  query_result = scli('--query_properties', *args).split("\n")
  group_name = ''
  properties = {}

  query_result.each do |line|
    if line =~ /^No objects returned/i
      return properties
    elsif line =~ /^([^\s]+)\s([^:]+)/
      group_name = $2
      properties[group_name] = Hash.new { |hash, key| hash[key] = {} }
    else
      line =~ /^\s+([^\s]+)\s+(.*)$/
      properties[group_name][$1] = $2
    end
  end
  Puppet.debug("Queried scaleio properties #{properties}")
  properties
end