Class: Mccloud::Provider::Aws::Image
- Inherits:
-
Object
- Object
- Mccloud::Provider::Aws::Image
- Defined in:
- lib/mccloud/provider/aws/image.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#provider ⇒ Object
Returns the value of attribute provider.
Instance Method Summary collapse
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/mccloud/provider/aws/image.rb', line 6 def name @name end |
#provider ⇒ Object
Returns the value of attribute provider.
5 6 7 |
# File 'lib/mccloud/provider/aws/image.rb', line 5 def provider @provider end |
Instance Method Details
#package(selection = nil, options = nil) ⇒ Object
11 12 13 14 15 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 42 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 |
# File 'lib/mccloud/provider/aws/image.rb', line 11 def package(selection=nil,=nil) if selection.nil? env.ui.info "[Error] We need at least a name of a machine." exit end #f=Fog::Compute.new({ :region => "eu-west-1", :provider => "AWS"}) # i=f.create_image("i-c1ac2bb7","name","description") # f.images.all({ "Owner" => "self"}) # f.deregister_image("ami-796d5b0d") on_selected_machines(selection) do |id,vm| time=Time.new strtime=time.strftime("%Y-%m-%d-%H-%M-%S") name="" if ["name"].nil? name="#{vm.name}-#{strtime}" else name=["name"] end description="" if ["description"].nil? description="Autogenerated snapshot from machine #{vm.name}" else description=["description"] end filter=@environment.config.mccloud.filter fullname="#{@environment.config.mccloud.filter}#{name}" provider= @environment.config.providers[vm.provider] begin result=provider.create_image(id,name,description) imageId=result.body["imageId"] env.ui.info "[#{vm.name}] image #{imageId} with #{description} being created" unless ["dontwait"] sleep 3 counter=0 max_tries=5 #Pending state="pending" until state!="pending" do print "." sleep 2 image=provider.images.get(imageId) if image.nil? sleep 3 print "." else state=image.state end end env.ui.info "" env.ui.info "[#{vm.name}] creation done!" end rescue Fog::Service::Error => fogerror env.ui.info "[Error] #{fogerror}" end # vm.instance.start end end |
#raw ⇒ Object
8 9 |
# File 'lib/mccloud/provider/aws/image.rb', line 8 def raw end |
#register ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/mccloud/provider/aws/image.rb', line 81 def register #f=Fog::Compute.new({ :region => "eu-west-1", :provider => "AWS"}) # i=f.create_image("i-c1ac2bb7","name","description") # f.images.all({ "Owner" => "self"}) # f.deregister_image("ami-796d5b0d") env.ui.info "Looking for imageId: #{imageId}" @environment.config.providers.each do |name,provider| begin image=provider.images.get(imageId) if image.nil? env.ui.info "[#{name}] - ImageId #{imageId} not found" else env.ui.info "[#{name}] - ImageId #{imageId} found" env.ui.info "[#{name}] - Deregistering #{imageId} now" begin provider.deregister_image(imageId) rescue Fog::Service::Error => fogerror env.ui.info "[Error] #{fogerror}" end end end end end |