Class: ProjectFifo

Inherits:
Object
  • Object
show all
Defined in:
lib/project-fifo.rb,
lib/project-fifo/vm.rb,
lib/project-fifo/dataset.rb,
lib/project-fifo/iprange.rb,
lib/project-fifo/package.rb,
lib/project-fifo/resource.rb

Defined Under Namespace

Classes: Dataset, Iprange, Package, Resource, VM

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, username, password) ⇒ ProjectFifo

Returns a new instance of ProjectFifo.



14
15
16
17
18
19
20
21
# File 'lib/project-fifo.rb', line 14

def initialize(endpoint, username, password)
  @endpoint = endpoint
  @username = username
  @password = password
  @ssh_keys = nil
  @verbose = true
  @rest = RestClient::Resource.new(endpoint, :headers => { :content_type => 'application/json', :accept => :json })
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



12
13
14
# File 'lib/project-fifo.rb', line 12

def endpoint
  @endpoint
end

#passwordObject (readonly)

Returns the value of attribute password.



12
13
14
# File 'lib/project-fifo.rb', line 12

def password
  @password
end

#ssh_keysObject (readonly)

Returns the value of attribute ssh_keys.



12
13
14
# File 'lib/project-fifo.rb', line 12

def ssh_keys
  @ssh_keys
end

#tokenObject (readonly)

Returns the value of attribute token.



12
13
14
# File 'lib/project-fifo.rb', line 12

def token
  @token
end

#usernameObject (readonly)

Returns the value of attribute username.



12
13
14
# File 'lib/project-fifo.rb', line 12

def username
  @username
end

Instance Method Details

#connectObject



23
24
25
26
27
28
29
# File 'lib/project-fifo.rb', line 23

def connect()
  response = post('sessions', { 'user' => @username, 'password' => @password })
  @token = response["session"]
  @ssh_keys = response["metadata"]["jingles"]["ssh_keys"]
  @rest.headers[:x_snarl_token] = @token
  response
end

#datasetsObject



51
52
53
# File 'lib/project-fifo.rb', line 51

def datasets
  @datasets ||= ProjectFifo::Dataset.new(self)
end

#delete(path_part, additional_headers = {}, &block) ⇒ Object



43
44
45
# File 'lib/project-fifo.rb', line 43

def delete(path_part, additional_headers = {}, &block)
  api_request { @rest[path_part].delete(additional_headers, &block) }
end

#get(path_part, additional_headers = {}, &block) ⇒ Object



35
36
37
# File 'lib/project-fifo.rb', line 35

def get(path_part, additional_headers = {}, &block)
  api_request { @rest[path_part].get(additional_headers, &block) }
end

#iprangesObject



59
60
61
# File 'lib/project-fifo.rb', line 59

def ipranges
  @ipranges ||= ProjectFifo::Iprange.new(self)
end

#packagesObject



55
56
57
# File 'lib/project-fifo.rb', line 55

def packages
  @packages ||= ProjectFifo::Package.new(self)
end

#post(path_part, payload, additional_headers = {}, &block) ⇒ Object



31
32
33
# File 'lib/project-fifo.rb', line 31

def post(path_part, payload, additional_headers = {}, &block)
  api_request { @rest[path_part].post(payload.to_json, additional_headers, &block) }
end

#put(path_part, payload, additional_headers = {}, &block) ⇒ Object



39
40
41
# File 'lib/project-fifo.rb', line 39

def put(path_part, payload, additional_headers = {}, &block)
  api_request { @rest[path_part].put(payload.to_json, additional_headers, &block) }
end

#vmsObject



47
48
49
# File 'lib/project-fifo.rb', line 47

def vms
  @vms ||= ProjectFifo::VM.new(self)
end