Class: Kiel::Cloud::Mock
- Inherits:
-
Object
- Object
- Kiel::Cloud::Mock
- Defined in:
- lib/kiel/cloud/mock.rb
Overview
Implementation of the Cloud access-Interface The implementation assumes that a cloud provider provides machine images, used to start machines, that this images can a not unique set of tags and a unique id. Where the id is provided by the cloud provider tags are provided by the user. Kiel used the tags to store version informations to an image and uses this set of tags to identify an image.
The implementation assumes that a cloud provider allows to start a server with a machine image as parameter and that the resulting instance has a public dns_name to be reachable.
Instance Method Summary collapse
-
#calls ⇒ Object
–.
-
#dns_name(instance) ⇒ Object
returns the dns name from an instance.
-
#exists?(tags) ⇒ Boolean
returns true, if an image with the given tags exists.
-
#initialize(existing_images = [], dns_names = []) ⇒ Mock
constructor
existing_images
simulates an initial set of existing machine images,dns_names
provides a set of names that are assigned to newly created cloud instances. -
#running_instances ⇒ Object
–.
-
#start_instance(image_name) ⇒ Object
starts a server instance in the cloud, returning a handle to that instance.
-
#stop_instance(instance) ⇒ Object
stops the given instance.
-
#store_image(instance, tags) ⇒ Object
store the given
instance
under the givenimage_name
and add the hash oftags
to the image. -
#stored_images ⇒ Object
–.
Constructor Details
#initialize(existing_images = [], dns_names = []) ⇒ Mock
existing_images
simulates an initial set of existing machine images, dns_names
provides a set of names that are assigned to newly created cloud instances.
16 17 18 19 20 21 22 |
# File 'lib/kiel/cloud/mock.rb', line 16 def initialize existing_images = [], dns_names = [] @names = dns_names.dup @calls = [] @images = [ existing_images.dup ].flatten @running = [] @next_instance = 0 end |
Instance Method Details
#calls ⇒ Object
–
61 62 63 |
# File 'lib/kiel/cloud/mock.rb', line 61 def calls @calls end |
#dns_name(instance) ⇒ Object
returns the dns name from an instance
56 57 58 |
# File 'lib/kiel/cloud/mock.rb', line 56 def dns_name instance "#{instance}" end |
#exists?(tags) ⇒ Boolean
returns true, if an image with the given tags exists
51 52 53 |
# File 'lib/kiel/cloud/mock.rb', line 51 def exists? @images.detect { | image | image[ :tags ] == } end |
#running_instances ⇒ Object
–
66 67 68 |
# File 'lib/kiel/cloud/mock.rb', line 66 def running_instances @running end |
#start_instance(image_name) ⇒ Object
starts a server instance in the cloud, returning a handle to that instance. the image is either named by an image id :id => ‘image_id’ or by a set of tags that match for just one image :tags => { ‘image_type’ => ‘application’, ‘base’ => ‘34’ }
27 28 29 30 31 32 33 |
# File 'lib/kiel/cloud/mock.rb', line 27 def start_instance image_name raise ArgumentError, "image_name must contain exactly one identification" unless image_name.size == 1 @running << @next_instance @next_instance += 1 @running.last end |
#stop_instance(instance) ⇒ Object
stops the given instance.
44 45 46 47 48 |
# File 'lib/kiel/cloud/mock.rb', line 44 def stop_instance instance unless @running.delete( instance ) raise RuntimeError, "there is no instance #{instance} running" end end |
#store_image(instance, tags) ⇒ Object
store the given instance
under the given image_name
and add the hash of tags
to the image.
36 37 38 39 40 41 |
# File 'lib/kiel/cloud/mock.rb', line 36 def store_image instance, image = { id: instance, tags: } @calls << { func: :store_image, args: image } @images << image stop_instance instance end |
#stored_images ⇒ Object
–
71 72 73 |
# File 'lib/kiel/cloud/mock.rb', line 71 def stored_images @images end |