Class: Fog::Compute::Joyent::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/joyent/compute.rb,
lib/fog/joyent/requests/compute/get_key.rb,
lib/fog/joyent/requests/compute/get_image.rb,
lib/fog/joyent/requests/compute/list_keys.rb,
lib/fog/joyent/requests/compute/create_key.rb,
lib/fog/joyent/requests/compute/delete_key.rb,
lib/fog/joyent/requests/compute/get_dataset.rb,
lib/fog/joyent/requests/compute/get_machine.rb,
lib/fog/joyent/requests/compute/get_package.rb,
lib/fog/joyent/requests/compute/list_images.rb,
lib/fog/joyent/requests/compute/list_datasets.rb,
lib/fog/joyent/requests/compute/list_machines.rb,
lib/fog/joyent/requests/compute/list_networks.rb,
lib/fog/joyent/requests/compute/list_packages.rb,
lib/fog/joyent/requests/compute/list_machine_tags.rb,
lib/fog/joyent/requests/compute/delete_machine_snapshot.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



102
103
104
105
# File 'lib/fog/joyent/compute.rb', line 102

def initialize(options = {})
  @joyent_username = options[:joyent_username]
  @joyent_password = options[:joyent_password]
end

Class Method Details

.dataObject



92
93
94
95
96
# File 'lib/fog/joyent/compute.rb', line 92

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {}
  end
end

Instance Method Details

#create_key(params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/joyent/requests/compute/create_key.rb', line 8

def create_key(params)
  name = params[:name]
  key = params[:key]

  record = {
    "name" => name,
    "key" => key,
    "created" => Time.now.utc,
    "updated" => Time.now.utc
  }

  self.data[:keys][name] = record

  response = Excon::Response.new
  response.status = 201
  response.body = record
  response
end

#dataObject



98
99
100
# File 'lib/fog/joyent/compute.rb', line 98

def data
  self.class.data
end

#delete_key(keyname) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/fog/joyent/requests/compute/delete_key.rb', line 5

def delete_key(keyname)
  if self.data[:keys].delete(keyname)
    response = Excon::Response.new
    response.status = 204
    response
  else
    raise Excon::Errors::NotFound, "Not Found"
  end
end

#get_dataset(id) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/fog/joyent/requests/compute/get_dataset.rb', line 5

def get_dataset(id)
  if ds = self.data[:datasets][id]
    res = Excon::Response.new
    res.status = 200
    res.body = ds
  else
    raise Excon::Errors::NotFound
  end
end

#get_image(id) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/fog/joyent/requests/compute/get_image.rb', line 5

def get_image(id)
  if ds = self.data[:datasets][id]
    res = Excon::Response.new
    res.status = 200
    res.body = ds
  else
    raise Excon::Errors::NotFound
  end
end

#get_key(keyid) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/fog/joyent/requests/compute/get_key.rb', line 5

def get_key(keyid)
  if key = self.data[:keys][keyid]
    response = Excon::Response.new
    response.status = 200
    response.body = key
    response
  else
    raise Excon::Errors::NotFound
  end
end

#get_machine(uuid) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/fog/joyent/requests/compute/get_machine.rb', line 5

def get_machine(uuid)
  if machine = self.data[:machines][uuid]
    res = Excon::Response.new
    res.status = 200
    res.body = machine
    res
  else
    raise Excon::Errors::NotFound, "Not Found"
  end
end

#get_package(name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/joyent/requests/compute/get_package.rb', line 7

def get_package(name)
  if pkg = self.data[:packages][name]
    response = Excon::Response.new
    response.body = pkg
    response.status = 200
    response
  else
    raise Excon::Errors::NotFound
  end
end

#list_datasetsObject



5
6
7
8
9
10
# File 'lib/fog/joyent/requests/compute/list_datasets.rb', line 5

def list_datasets
  res = Excon::Response.new
  res.status = 200
  res.body = self.data[:datasets].values
  res
end

#list_imagesObject



5
6
7
8
9
10
# File 'lib/fog/joyent/requests/compute/list_images.rb', line 5

def list_images
  res = Excon::Response.new
  res.status = 200
  res.body = self.data[:datasets].values
  res
end

#list_keysObject



5
6
7
8
9
10
# File 'lib/fog/joyent/requests/compute/list_keys.rb', line 5

def list_keys
  response = Excon::Response.new
  response.status = 200
  response.body = self.data[:keys].values
  response
end

#list_machines(options = {}) ⇒ Object



5
6
7
8
9
10
# File 'lib/fog/joyent/requests/compute/list_machines.rb', line 5

def list_machines(options={})
  res = Excon::Response.new
  res.status = 200
  res.body = self.data[:machines].values
  res
end

#list_networks(options = {}) ⇒ Object



5
6
7
8
9
10
# File 'lib/fog/joyent/requests/compute/list_networks.rb', line 5

def list_networks(options={})
  res = Excon::Response.new
  res.status = 200
  res.body = self.data[:networks].values
  res
end

#list_packagesObject



5
6
7
8
9
10
# File 'lib/fog/joyent/requests/compute/list_packages.rb', line 5

def list_packages
  response = Excon::Response.new()
  response.status = 200
  response.body = self.data[:packages].values
  response
end

#request(opts) ⇒ Object



107
108
109
# File 'lib/fog/joyent/compute.rb', line 107

def request(opts)
  raise "Not Implemented"
end