Class: DeploymentMonk
- Inherits:
-
Object
- Object
- DeploymentMonk
- Defined in:
- lib/virtualmonkey/deployment_monk.rb
Instance Attribute Summary collapse
-
#common_inputs ⇒ Object
Returns the value of attribute common_inputs.
-
#deployments ⇒ Object
Returns the value of attribute deployments.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#variables_for_cloud ⇒ Object
Returns the value of attribute variables_for_cloud.
Instance Method Summary collapse
- #destroy_all ⇒ Object
- #from_tag ⇒ Object
- #generate_variations(options = {}) ⇒ Object
- #get_deployments ⇒ Object
-
#initialize(tag, server_templates = [], extra_images = []) ⇒ DeploymentMonk
constructor
A new instance of DeploymentMonk.
- #load_common_inputs(file) ⇒ Object
Constructor Details
#initialize(tag, server_templates = [], extra_images = []) ⇒ DeploymentMonk
Returns a new instance of DeploymentMonk.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/virtualmonkey/deployment_monk.rb', line 16 def initialize(tag, server_templates = [], extra_images = []) @clouds = ["1","2","3","4", "232"] @cloud_names = { "1" => "ec2-east", "2" => "ec2-eu", "3" => "ec2-west", "4" => "ec2-ap", "232" => "rackspace"} @tag = tag @deployments = from_tag @server_templates = [] @common_inputs = {} @variables_for_cloud = {} raise "Need either populated deployments or passed in server_template ids" if server_templates.empty? && @deployments.empty? if server_templates.empty? puts "loading server templates from servers in the first deployment" @deployments.first.servers.each do |s| server_templates << s.server_template_href.split(/\//).last.to_i end end server_templates.each do |st| @server_templates << ServerTemplate.find(st.to_i) end @image_count = 0 @server_templates.each do |st| new_st = ServerTemplateInternal.new(:href => st.href) st.multi_cloud_images = new_st.multi_cloud_images @image_count = st.multi_cloud_images.size if st.multi_cloud_images.size > @image_count end end |
Instance Attribute Details
#common_inputs ⇒ Object
Returns the value of attribute common_inputs.
5 6 7 |
# File 'lib/virtualmonkey/deployment_monk.rb', line 5 def common_inputs @common_inputs end |
#deployments ⇒ Object
Returns the value of attribute deployments.
7 8 9 |
# File 'lib/virtualmonkey/deployment_monk.rb', line 7 def deployments @deployments end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
8 9 10 |
# File 'lib/virtualmonkey/deployment_monk.rb', line 8 def tag @tag end |
#variables_for_cloud ⇒ Object
Returns the value of attribute variables_for_cloud.
6 7 8 |
# File 'lib/virtualmonkey/deployment_monk.rb', line 6 def variables_for_cloud @variables_for_cloud end |
Instance Method Details
#destroy_all ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/virtualmonkey/deployment_monk.rb', line 117 def destroy_all @deployments.each do |v| v.reload v.servers.each { |s| s.stop } end @deployments.each { |v| v.destroy } @deployments = [] end |
#from_tag ⇒ Object
10 11 12 13 14 |
# File 'lib/virtualmonkey/deployment_monk.rb', line 10 def from_tag variations = Deployment.find_by(:nickname) {|n| n =~ /^#{@tag}/ } puts "loading #{variations.size} deployments matching your tag" return variations end |
#generate_variations(options = {}) ⇒ Object
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 |
# File 'lib/virtualmonkey/deployment_monk.rb', line 43 def generate_variations( = {}) if [:mci_override] && ![:mci_override].empty? @image_count = [:mci_override].size end @image_count.times do |index| @clouds.each do |cloud| if @variables_for_cloud[cloud] == nil puts "variables not found for cloud #{cloud} skipping.." next end dep_tempname = "#{@tag}-#{@cloud_names[cloud]}-#{rand(1000000)}-" dep_image_list = [] new_deploy = Deployment.create(:nickname => dep_tempname) @deployments << new_deploy @server_templates.each do |st| server_params = { :nickname => "tempserver-#{rand(1000000)}-#{st.nickname}", :deployment_href => new_deploy.href, :server_template_href => st.href, :cloud_id => cloud #:ec2_image_href => image['image_href'], #:instance_type => image['aws_instance_type'] } server = Server.create(server_params.merge(@variables_for_cloud[cloud])) # since the create call does not set the parameters, we need to set them separate if server.respond_to?(:set_inputs) server.set_inputs(@variables_for_cloud[cloud]['parameters']) else @variables_for_cloud[cloud]['parameters'].each do |key,val| server.set_input(key,val) end end # uses a special internal call for setting the MCI on the server if [:mci_override] && ![:mci_override].empty? use_this_image = [:mci_override][index] dep_image_list << MultiCloudImage.find([:mci_override][index]).name.gsub(/ /,'_') elsif st.multi_cloud_images[index] dep_image_list << st.multi_cloud_images[index]['name'].gsub(/ /,'_') use_this_image = st.multi_cloud_images[index]['href'] else use_this_image = st.multi_cloud_images[0]['href'] end #RsInternal.set_server_multi_cloud_image(server.href, use_this_image) sint = ServerInternal.new(:href => server.href) sint.set_multi_cloud_image(use_this_image) # finally, set the spot price unless [:no_spot] server.reload server.settings if server.ec2_instance_type =~ /small/ server.max_spot_price = "0.085" elsif server.ec2_instance_type =~ /large/ server.max_spot_price = "0.38" end server.pricing = "spot" server.parameters = {} server.save end end new_deploy.nickname = dep_tempname + dep_image_list.uniq.join("_AND_") new_deploy.save @common_inputs.each do |key,val| new_deploy.set_input(key,val) end end end end |
#get_deployments ⇒ Object
126 127 128 129 130 |
# File 'lib/virtualmonkey/deployment_monk.rb', line 126 def get_deployments deployments = [] @deployments.each { |v| deployments << v.nickname } deployments end |
#load_common_inputs(file) ⇒ Object
113 114 115 |
# File 'lib/virtualmonkey/deployment_monk.rb', line 113 def load_common_inputs(file) @common_inputs.merge! JSON.parse(IO.read(file)) end |