Skip to content

Instantly share code, notes, and snippets.

@krames
Last active January 4, 2016 17:59
Show Gist options
  • Select an option

  • Save krames/8657901 to your computer and use it in GitHub Desktop.

Select an option

Save krames/8657901 to your computer and use it in GitHub Desktop.
Creating agent tokens

Create Service

1.9.3-p392 :001 > service = Fog::Rackspace::Monitoring.new
 => #<Fog::Rackspace::Monitoring::Real:70314002500360 @rackspace_api_key="e3578b3eb4ef454ca9381c08c8767b97" @rackspace_userna...

Create new token using new

1.9.3-p392 :002 > token = service.agent_tokens.new
 =>   <Fog::Rackspace::Monitoring::AgentToken
    id=nil,
    label=nil,
    token=nil
  >
1.9.3-p392 :003 > token.label = "test-token"
 => "test-token"
1.9.3-p392 :004 > token.token = "23kj42lj4l2j34j2;3lj"
 => "23kj42lj4l2j34j2;3lj"
1.9.3-p392 :005 > token.save
 => true

Create token using create

1.9.3-p392 :006 > token2 = service.agent_tokens.create :label => 'my-second-token', :token => 'sadfadsfasdfasdfa'
 =>   <Fog::Rackspace::Monitoring::AgentToken
    id="4527beed9250f0eff20d4ace75536a66524c0df808f3d9236c980c99fd4d7503.772045",
    label="my-second-token",
    token="sadfadsfasdfasdfa"
  >

The create_agent_token method is only called when the token object is saved. You can do that either using new and then saving the token using save or more commonly you would just use the create method which calls new and then save under the covers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment