Class: Fog::Compute::Terremark::Server
- Inherits:
-
Model
- Object
- Model
- Fog::Compute::Terremark::Server
- Defined in:
- lib/fog/compute/terremark/models/server.rb
Defined Under Namespace
Modules: VAppStatus
Instance Method Summary collapse
- #create_internet_services(internet_spec) ⇒ Object
- #delete_internet_services ⇒ Object
- #destroy ⇒ Object
- #graceful_restart ⇒ Object
- #internet_services ⇒ Object
- #off? ⇒ Boolean
- #on? ⇒ Boolean
- #power_off ⇒ Object
- #power_on(_options = {}) ⇒ Object
- #power_reset ⇒ Object
- #PublicIpAddress ⇒ Object
-
#ready? ⇒ Boolean
{ “0” => “Being created”, “2” => “Powered Off”, “4” => “Powered On”}.
- #reload ⇒ Object
- #save ⇒ Object
- #shutdown ⇒ Object
Instance Method Details
#create_internet_services(internet_spec) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/fog/compute/terremark/models/server.rb', line 128 def create_internet_services(internet_spec) public_ip_info = nil internet_service_id = nil internet_spec.each do |proto, ports| for port in ports if not public_ip_info #Create the first internet service and allocate public IP inet_services = service.internetservices.create({ "Name" => self.name, "Protocol" => proto, "Port" => port, }) internet_service_id = inet_services.Id public_ip_info = inet_services.PublicIpAddress else #create additional services to existing Public IP inet_services = service.internetservices.create({ "public_ip_address_id" => public_ip_info["Id"], "Name" => self.name, "Protocol" => proto, "Port" => port, } ) internet_service_id = inet_services.Id end #Create the associate node service to the server service.nodeservices.create({"Name" => self.name, "IpAddress" => self.IpAddress, "Port" => port, "InternetServiceId" => internet_service_id }) end end true end |
#delete_internet_services ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/fog/compute/terremark/models/server.rb', line 55 def delete_internet_services #Find the internet service while (inet_service = internet_services.pop) do nodes = service.nodeservices.all(inet_service.Id) #Delete all the associated nodes nodes.select { |item| item.destroy } #Clear out the services inet_service.destroy(delete_public_ip = !(internet_services.size > 0)) end true end |
#destroy ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/compute/terremark/models/server.rb', line 29 def destroy case self.status when VAppStatus::BEING_CREATED, VAppStatus::BEING_DEPLOYED return false when VAppStatus::POWERED_ON service.power_off(self.id).body wait_for { off? } end #Failsafe .. Always check if we are ready wait_for { ready? } service.delete_vapp(self.id) true end |
#graceful_restart ⇒ Object
121 122 123 124 125 126 |
# File 'lib/fog/compute/terremark/models/server.rb', line 121 def graceful_restart requires :id shutdown wait_for { off? } power_on end |
#internet_services ⇒ Object
51 52 53 |
# File 'lib/fog/compute/terremark/models/server.rb', line 51 def internet_services @internet_services ||= service.internetservices.all.select { |item| item.Name == self.name } end |
#off? ⇒ Boolean
78 79 80 |
# File 'lib/fog/compute/terremark/models/server.rb', line 78 def off? status == VAppStatus::POWERED_OFF end |
#on? ⇒ Boolean
74 75 76 |
# File 'lib/fog/compute/terremark/models/server.rb', line 74 def on? status == VAppStatus::POWERED_ON end |
#power_off ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/fog/compute/terremark/models/server.rb', line 93 def power_off requires :id begin service.power_off(id) rescue Excon::Errors::InternalServerError => e # Frankly we shoudln't get here ... raise e unless e.to_s =~ /because it is already powered off/ end true end |
#power_on(_options = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fog/compute/terremark/models/server.rb', line 82 def power_on( = {}) requires :id begin service.power_on(id) rescue Excon::Errors::InternalServerError => e # Frankly we shoudln't get here ... raise e unless e.to_s =~ /because it is already powered on/ end true end |
#power_reset ⇒ Object
115 116 117 118 119 |
# File 'lib/fog/compute/terremark/models/server.rb', line 115 def power_reset requires :id service.power_reset(id) true end |
#PublicIpAddress ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/fog/compute/terremark/models/server.rb', line 43 def PublicIpAddress @PublicIpAddress ||= if internet_services.size > 0 internet_services[0].PublicIpAddress["Name"] end @PublicIpAddress end |
#ready? ⇒ Boolean
{ “0” => “Being created”, “2” => “Powered Off”, “4” => “Powered On”}
70 71 72 |
# File 'lib/fog/compute/terremark/models/server.rb', line 70 def ready? status == VAppStatus::POWERED_OFF end |
#reload ⇒ Object
25 26 27 |
# File 'lib/fog/compute/terremark/models/server.rb', line 25 def reload merge_attributes(service.get_vapp(id).body) end |
#save ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/fog/compute/terremark/models/server.rb', line 166 def save requires :name if powerOn end data = service.instantiate_vapp_template( server_name=name, vapp_template=image, ={ "ssh_key_fingerprint" => sshkeyFingerPrint, "cpus" => vcpus, "memory" => memory }) merge_attributes(data.body) wait_for { ready? } #Optional, incase further configuration required. if powerOn power_on wait_for { ready? } end true end |
#shutdown ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/fog/compute/terremark/models/server.rb', line 104 def shutdown requires :id begin service.power_shutdown(id) rescue Excon::Errors::InternalServerError => e # Frankly we shoudln't get here ... raise e unless e.to_s =~ /because it is already powered off/ end true end |