Module: RightScale::CommonParser
- Included in:
- AgentController, AgentDeployer
- Defined in:
- lib/right_agent/scripts/common_parser.rb
Instance Method Summary collapse
-
#agent_type(type, name) ⇒ Object
Determine agent type.
-
#parse_common(opts, options) ⇒ Object
Parse common options between rad and rnac.
-
#resolve_identity(options) ⇒ Object
Generate agent identity from options Build identity from base_id, token, prefix and agent name.
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, ) opts.on("--test") do [:user] = 'test' [:pass] = 'testing' [:vhost] = '/right_net' [:test] = true [:pid_dir] = Dir.tmpdir [:base_id] = "#{rand(1000000)}" [:options][:log_dir] = Dir.tmpdir end opts.on("-i", "--identity ID") do |id| [:base_id] = id end opts.on("-t", "--token TOKEN") do |t| [:token] = t end opts.on("-S", "--secure-identity") do [:secure_identity] = true end opts.on("-x", "--prefix PREFIX") do |p| [:prefix] = p end opts.on("--url URL") do |url| uri = URI.parse(url) [:user] = uri.user if uri.user [:pass] = uri.password if uri.password [:host] = uri.host [:port] = uri.port if uri.port [:vhost] = uri.path if (uri.path && !uri.path.empty?) end opts.on("-u", "--user USER") do |user| [:user] = user end opts.on("-p", "--pass PASSWORD") do |pass| [:pass] = pass end opts.on("-v", "--vhost VHOST") do |vhost| [:vhost] = vhost end opts.on("-P", "--port PORT") do |port| [:port] = port end opts.on("-h", "--host HOST") do |host| [:host] = host end opts.on('--type TYPE') do |t| [: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() [:agent_type] = agent_type([:agent_type], [:agent_name]) if [:base_id] base_id = [:base_id].to_i if base_id.abs.to_s != [:base_id] puts "** Identity needs to be a positive integer" exit(1) end token = if [:secure_identity] RightScale::SecureIdentity.derive(base_id, [:token]) else [:token] end [:identity] = AgentIdentity.new([:prefix] || 'rs', [:agent_type], base_id, token).to_s end end |