Class: Deployment

Inherits:
Object
  • Object
show all
Extended by:
RightScale::Api::BaseExtend, RightScale::Api::TaggableExtend
Includes:
RightScale::Api::Base, RightScale::Api::Taggable
Defined in:
lib/rest_connection/rightscale/deployment.rb

Overview

API 1.0

Instance Attribute Summary

Attributes included from RightScale::Api::Base

#params

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RightScale::Api::BaseExtend

[], create, deny_methods, filters, find, find_all, find_by, find_by_cloud_id, find_by_id, find_by_nickname, find_by_nickname_speed, find_with_filter, resource_plural_name, resource_singular_name

Methods included from RightScale::Api::BaseConnection

#connection

Methods included from RightScale::Api::TaggableExtend

find_by_tags

Methods included from RightScale::Api::Taggable

#add_tags, #clear_tags, #get_info_tags, #get_tags_by_namespace, #remove_info_tags, #remove_tags, #remove_tags_by_namespace, #set_info_tags, #set_tags_by_namespace, #set_tags_to, #tags

Methods included from RightScale::Api::Base

#[], #[]=, #initialize, #method_missing, #resource_plural_name, #resource_singular_name, #rs_id, #save

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RightScale::Api::Base

Class Method Details

.create(opts) ⇒ Object



44
45
46
47
48
49
# File 'lib/rest_connection/rightscale/deployment.rb', line 44

def self.create(opts)
  location = connection.post(self.resource_plural_name, self.resource_singular_name.to_sym => opts)
  newrecord = self.new('href' => location)
  newrecord.reload
  newrecord
end

.filtersObject



33
34
35
# File 'lib/rest_connection/rightscale/deployment.rb', line 33

def self.filters
  [:description, :nickname]
end

Instance Method Details

#cloneObject



105
106
107
108
# File 'lib/rest_connection/rightscale/deployment.rb', line 105

def clone
  deploy_href = URI.parse(self.href)
  Deployment.new(:href => connection.post(deploy_href.path + "/duplicate"))
end

#destroy(wait_for_servers = nil) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/rest_connection/rightscale/deployment.rb', line 110

def destroy(wait_for_servers = nil)
  deploy_href = URI.parse(self.href)
  if wait_for_servers
    servers_no_reload.each { |s| s.wait_for_state("stopped") }
  end
  connection.delete(deploy_href.path)
end

#duplicateObject



101
102
103
# File 'lib/rest_connection/rightscale/deployment.rb', line 101

def duplicate
  clone
end

#reloadObject



37
38
39
40
41
42
# File 'lib/rest_connection/rightscale/deployment.rb', line 37

def reload
  uri = URI.parse(self.href)
  @params ? @params.merge!(connection.get(uri.path)) : @params = connection.get(uri.path)
  @params['cloud_id'] = cloud_id
  @params
end

#serversObject



94
95
96
97
98
99
# File 'lib/rest_connection/rightscale/deployment.rb', line 94

def servers
  # this populates extra information about the servers
  servers_no_reload.each do |s|
    s.reload
  end
end

#servers_no_reloadObject



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
# File 'lib/rest_connection/rightscale/deployment.rb', line 61

def servers_no_reload
  connection.logger("WARNING: No Servers in the Deployment!") if @params['servers'].empty?

  cloud_id = nil
  @params["tags"].each do |hash|
    if hash["name"] =~ /info:cloud=(\d+)/
      cloud_id = $1
      break
    end
  end

  unless @params['servers'].reduce(true) { |bool,s| bool && s.is_a?(ServerInterface) }
    @params['servers'].map! do |s|
      # Create a temporary, legacy type server for each server in deployment.
      id = s['href'].match(/(\d{6,})$/)[0]
      serv = Server[id.to_i]

      # Query for settings.  AWS servers will return valid details, Generics won't.
      cloud_id = nil
      begin
        settings = serv.first.settings
        cloud_id = settings['cloud_id']
        puts "Cloud id #{cloud_id} found for server #{id.to_s}, assuming AWS server"
      rescue
        puts "Settings not returned from server #{id.to_s}, using API 1.0 call, assuming Generic server"
      end

      # Now we pass on cloud_id, it will be nil for generic servers, of a valid number for AWS servers
      ServerInterface.new(cloud_id, s, self.rs_id)
    end
end
end

#set_input(name, value) ⇒ Object



56
57
58
59
# File 'lib/rest_connection/rightscale/deployment.rb', line 56

def set_input(name, value)
  deploy_href = URI.parse(self.href)
  connection.put(deploy_href.path, :deployment => {:parameters => {name => value} })
end

#set_inputs(hash = {}) ⇒ Object



51
52
53
54
# File 'lib/rest_connection/rightscale/deployment.rb', line 51

def set_inputs(hash = {})
  deploy_href = URI.parse(self.href)
  connection.put(deploy_href.path, :deployment => {:parameters => hash })
end

#start_allObject



118
119
120
121
# File 'lib/rest_connection/rightscale/deployment.rb', line 118

def start_all
  deploy_href = URI.parse(self.href)
  connection.post(deploy_href.path + "/start_all")
end

#stop_allObject



123
124
125
126
# File 'lib/rest_connection/rightscale/deployment.rb', line 123

def stop_all
  deploy_href = URI.parse(self.href)
  connection.post(deploy_href.path + "/stop_all")
end