Module: RightScale::CommonParser

Included in:
AgentController, AgentDeployer
Defined in:
lib/right_agent/scripts/common_parser.rb

Instance Method Summary collapse

Instance Method Details

#agent_type(type, name) ⇒ Object

Determine agent type

Parameters

type(String)

Agent type

name(String)

Agent name

Return

(String)

Agent type



147
148
149
150
151
152
153
154
155
156
# File 'lib/right_agent/scripts/common_parser.rb', line 147

def agent_type(type, name)
  unless type
    if name =~ /^(.*)_[0-9]+$/
      type = Regexp.last_match(1)
    else
      type = name || "instance"
    end
  end
  type
end

#parse_common(opts, options) ⇒ Object

Parse common options between rad and rnac

Parameters

opts(OptionParser)

Options parser with options to be parsed

options(Hash)

Storage for options that are parsed

Return

true

Always return true



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/right_agent/scripts/common_parser.rb', line 41

def parse_common(opts, options)

  opts.on("--test") do 
    options[:user] = 'test'
    options[:pass] = 'testing'
    options[:vhost] = '/right_net'
    options[:test] = true
    options[:pid_dir] = Dir.tmpdir
    options[:base_id] = "#{rand(1000000)}"
    options[:options][:log_dir] = Dir.tmpdir
  end

  opts.on("-i", "--identity ID") do |id|
    options[:base_id] = id
  end

  opts.on("-t", "--token TOKEN") do |t|
    options[:token] = t
  end

  opts.on("-S", "--secure-identity") do
    options[:secure_identity] = true
  end

  opts.on("-x", "--prefix PREFIX") do |p|
    options[:prefix] = p
  end

  opts.on("--url URL") do |url|
    uri = URI.parse(url)
    options[:user]  = uri.user     if uri.user
    options[:pass]  = uri.password if uri.password
    options[:host]  = uri.host
    options[:port]  = uri.port     if uri.port
    options[:vhost] = uri.path     if (uri.path && !uri.path.empty?)
  end
  
  opts.on("-u", "--user USER") do |user|
    options[:user] = user
  end

  opts.on("-p", "--pass PASSWORD") do |pass|
    options[:pass] = pass
  end

  opts.on("-v", "--vhost VHOST") do |vhost|
    options[:vhost] = vhost
  end

  opts.on("-P", "--port PORT") do |port|
    options[:port] = port
  end

  opts.on("-h", "--host HOST") do |host|
    options[:host] = host
  end

  opts.on('--type TYPE') do |t|
    options[:agent_type] = t
  end

  opts.on_tail("--help") do
    puts Usage.scan(__FILE__)
    exit
  end

  opts.on_tail("--version") do
    puts version
    exit
  end
  true
end

#resolve_identity(options) ⇒ Object

Generate agent identity from options Build identity from base_id, token, prefix and agent name

Parameters

options(Hash)

Hash containing identity components

Return

options(Hash)


122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/right_agent/scripts/common_parser.rb', line 122

def resolve_identity(options)
  options[:agent_type] = agent_type(options[:agent_type], options[:agent_name])
  if options[:base_id]
    base_id = options[:base_id].to_i
    if base_id.abs.to_s != options[:base_id]
      puts "** Identity needs to be a positive integer"
      exit(1)
    end
    token = if options[:secure_identity]
      RightScale::SecureIdentity.derive(base_id, options[:token])
    else
      options[:token]
    end
    options[:identity] = AgentIdentity.new(options[:prefix] || 'rs', options[:agent_type], base_id, token).to_s
  end
end