1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[terremark] cleanup existing and add stuff for connecting ips/services and delete methods

This commit is contained in:
geemus (Wesley Beary) 2010-04-05 17:18:50 -07:00
parent f5b28f8cfa
commit 4421d86953
19 changed files with 505 additions and 17 deletions

View file

@ -3,12 +3,18 @@ module Fog
def self.new(options={})
require 'fog/terremark/requests/add_internet_service'
require 'fog/terremark/requests/add_node_service'
require 'fog/terremark/requests/create_internet_service'
require 'fog/terremark/requests/delete_internet_service'
require 'fog/terremark/requests/delete_node_service'
require 'fog/terremark/requests/delete_vapp'
require 'fog/terremark/requests/deploy_vapp'
require 'fog/terremark/requests/get_catalog'
require 'fog/terremark/requests/get_catalog_item'
require 'fog/terremark/requests/get_organization'
require 'fog/terremark/requests/get_organizations'
require 'fog/terremark/requests/get_public_ips'
require 'fog/terremark/requests/get_task'
require 'fog/terremark/requests/get_tasks_list'
require 'fog/terremark/requests/get_vapp'
@ -66,6 +72,65 @@ module Fog
@cookie = get_organizations.headers['Set-Cookie']
end
# TODO: bust cache on organization creation?
def default_organization_id
@default_organization_id ||= begin
org_list = get_organizations.body['OrgList']
if org_list.length == 1
org_list.first['href'].split('/').last.to_i
else
nil
end
end
end
def default_vdc_id
if default_organization_id
@default_vdc_id ||= begin
vdcs = get_organization(default_organization_id).body['Links'].select {|link|
link['type'] == 'application/vnd.vmware.vcloud.vdc+xml'
}
if vdcs.length == 1
vdcs.first['href'].split('/').last.to_i
else
nil
end
end
else
nil
end
end
def default_network_id
if default_vdc_id
@default_network_id ||= begin
networks = get_vdc(default_vdc_id).body['AvailableNetworks']
if networks.length == 1
networks.first['href'].split('/').last.to_i
else
nil
end
end
else
nil
end
end
def default_public_ip_id
if default_vdc_id
@default_public_ip_id ||= begin
ips = get_public_ips(default_vdc_id).body['PublicIpAddresses']
if ips.length == 1
ips.first['Href'].split('/').last.to_i
else
nil
end
end
else
nil
end
end
private
def request(params)

View file

@ -0,0 +1,28 @@
module Fog
module Parsers
module Terremark
class GetPublicIps< Fog::Parsers::Base
def reset
@ip_address = {}
@response = { 'PublicIpAddresses' => [] }
end
def end_element(name)
case name
when 'Href', 'Name'
@ip_address[name] = @value
when 'Id'
@ip_address[name] = @value.to_i
when 'PublicIPAddress'
@response['PublicIpAddresses'] << @ip_address
@ip_address = {}
end
end
end
end
end
end

View file

@ -0,0 +1,63 @@
module Fog
module Parsers
module Terremark
class InternetService < Fog::Parsers::Base
def reset
@in_public_ip_address = false
@response = { 'PublicIpAddress' => {} }
end
def start_element(name, attributes)
@value = ''
case name
when 'Href'
data = {}
until attributes.empty?
data[attributes.shift] = attributes.shift
end
if @in_public_ip_address
@response['PublicIpAddress'][name] = data
else
@response[name] = data
end
when 'PublicIpAddress'
@in_public_ip_address = true
end
end
def end_element(name)
case name
when 'Description', 'Protocol'
@response[name] = @value
when 'Enabled'
if @value == 'false'
@response[name] = false
else
@response[name] = true
end
when 'Id'
if @in_public_ip_address
@response['PublicIpAddress'][name] = @value.to_i
else
@response[name] = @value.to_i
end
when 'Name'
if @in_public_ip_address
@response['PublicIpAddress'][name] = @value
else
@response[name] = @value
end
when 'Port', 'Timeout'
@response[name] = @value.to_i
when 'PublicIpAddress'
@in_public_ip_address = false
end
end
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Parsers
module Terremark
class NodeService < Fog::Parsers::Base
def reset
@response = {}
end
def end_element(name)
case name
when 'Description', 'Href', 'IpAddress', 'Name', 'Protocol'
@response[name] = @value
when 'Enabled'
if @value == 'false'
@response[name] = false
else
@response[name] = true
end
when 'Id', 'Port'
@response[name] = @value.to_i
end
end
end
end
end
end

View file

@ -0,0 +1,63 @@
module Fog
module Terremark
class Real
require 'fog/terremark/parsers/internet_service'
# Reserve requested resources and deploy vApp
#
# ==== Parameters
# * ip_id<~Integer> - Id of ip to add service to
# * name<~String> - Name of service
# * protocol<~String> - Protocol of service
# * port<~Integer> - Port of service
# * options<~Hash>:
# * Enabled<~Boolean>: defaults to true
# * Description<~String>: optional description
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'endTime'<~String> - endTime of task
# * 'href'<~String> - link to task
# * 'startTime'<~String> - startTime of task
# * 'status'<~String> - status of task
# * 'type'<~String> - type of task
# * 'Owner'<~String> -
# * 'href'<~String> - href of owner
# * 'name'<~String> - name of owner
# * 'type'<~String> - type of owner
def add_internet_service(ip_id, name, protocol, port, options = {})
unless options.has_key?('Enabled')
options['Enabled'] = true
end
data = <<-DATA
<InternetService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpress-1.0:request:createInternetService">
<Name>#{name}</Name>
<Protocol>#{protocol.upcase}</Protocol>
<Port>#{port}</Port>
<Enabled>#{options['Enabled']}</Enabled>
<Description>#{options['Description']}</Description>
</InternetService>
DATA
request(
:body => data,
:expects => 200,
:headers => {'Content-Type' => 'application/xml'},
:method => 'POST',
:parser => Fog::Parsers::Terremark::InternetService.new,
:path => "publicIps/#{ip_id}/internetServices"
)
end
end
class Mock
def add_internet_service(ip_id)
raise MockNotImplemented.new("Contributions welcome!")
end
end
end
end

View file

@ -0,0 +1,63 @@
module Fog
module Terremark
class Real
require 'fog/terremark/parsers/node_service'
# Reserve requested resources and deploy vApp
#
# ==== Parameters
# * service_id<~String> - Id of service to add node to
# * ip<~String> - Private ip of server to add to node
# * name<~String> - Name of service
# * port<~Integer> - Port of service
# * options<~Hash>:
# * Enabled<~Boolean>: defaults to true
# * Description<~String>: optional description
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'endTime'<~String> - endTime of task
# * 'href'<~String> - link to task
# * 'startTime'<~String> - startTime of task
# * 'status'<~String> - status of task
# * 'type'<~String> - type of task
# * 'Owner'<~String> -
# * 'href'<~String> - href of owner
# * 'name'<~String> - name of owner
# * 'type'<~String> - type of owner
def add_node_service(service_id, ip, name, port, options = {})
unless options.has_key?('Enabled')
options['Enabled'] = true
end
data = <<-DATA
<NodeService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpress-1.0:request:createNodeService">
<IpAddress>#{ip}</IpAddress>
<Name>#{name}</Name>
<Port>#{port}</Port>
<Enabled>#{options['Enabled']}</Enabled>
<Description>#{options['Description']}</Description>
</NodeService>
DATA
request(
:body => data,
:expects => 200,
:headers => {'Content-Type' => 'application/xml'},
:method => 'POST',
:parser => Fog::Parsers::Terremark::InternetService.new,
:path => "internetServices/#{service_id}/nodes"
)
end
end
class Mock
def add_node_service(ip)
raise MockNotImplemented.new("Contributions welcome!")
end
end
end
end

View file

@ -0,0 +1,63 @@
module Fog
module Terremark
class Real
require 'fog/terremark/parsers/internet_service'
# Reserve requested resources and deploy vApp
#
# ==== Parameters
# * vdc_id<~Integer> - Id of vDc to add internet service to
# * name<~String> - Name of service
# * protocol<~String> - Protocol of service
# * port<~Integer> - Port of service
# * options<~Hash>:
# * Enabled<~Boolean>: defaults to true
# * Description<~String>: optional description
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'endTime'<~String> - endTime of task
# * 'href'<~String> - link to task
# * 'startTime'<~String> - startTime of task
# * 'status'<~String> - status of task
# * 'type'<~String> - type of task
# * 'Owner'<~String> -
# * 'href'<~String> - href of owner
# * 'name'<~String> - name of owner
# * 'type'<~String> - type of owner
def create_internet_service(vdc_id, name, protocol, port, options = {})
unless options.has_key?('Enabled')
options['Enabled'] = true
end
data = <<-DATA
<InternetService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpress-1.0:request:createInternetService">
<Name>#{name}</Name>
<Protocol>#{protocol.upcase}</Protocol>
<Port>#{port}</Port>
<Enabled>#{options['Enabled']}</Enabled>
<Description>#{options['Description']}</Description>
</InternetService>
DATA
request(
:body => data,
:expects => 200,
:headers => {'Content-Type' => 'application/xml'},
:method => 'POST',
:parser => Fog::Parsers::Terremark::InternetService.new,
:path => "vdc/#{vdc_id}/internetServices"
)
end
end
class Mock
def create_internet_service(vdc_id)
raise MockNotImplemented.new("Contributions welcome!")
end
end
end
end

View file

@ -0,0 +1,40 @@
module Fog
module Terremark
class Real
# Destroy an internet service
#
# ==== Parameters
# * internet_service_id<~Integer> - Id of service to destroy
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# FIXME
# * 'CatalogItems'<~Array>
# * 'href'<~String> - linke to item
# * 'name'<~String> - name of item
# * 'type'<~String> - type of item
# * 'description'<~String> - Description of catalog
# * 'name'<~String> - Name of catalog
def delete_internet_service(internet_service_id)
request(
:expects => 200,
:method => 'DELETE',
:path => "InternetServices/#{internet_service_id}"
)
end
end
class Mock
def delete_internet_service(internet_service_id)
raise MockNotImplemented.new("Contributions welcome!")
end
end
end
end

View file

@ -0,0 +1,40 @@
module Fog
module Terremark
class Real
# Destroy a node
#
# ==== Parameters
# * node_service_id<~Integer> - Id of node to destroy
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# FIXME
# * 'CatalogItems'<~Array>
# * 'href'<~String> - linke to item
# * 'name'<~String> - name of item
# * 'type'<~String> - type of item
# * 'description'<~String> - Description of catalog
# * 'name'<~String> - Name of catalog
def delete_node_service(node_service_id)
request(
:expects => 200,
:method => 'DELETE',
:path => "nodeServices/#{node_service_id}"
)
end
end
class Mock
def delete_node_service(node_id)
raise MockNotImplemented.new("Contributions welcome!")
end
end
end
end

View file

@ -26,7 +26,7 @@ module Fog
:expects => 202,
:method => 'POST',
:parser => Fog::Parsers::Terremark::Task.new,
:path => "/vApp/#{vapp_id}/action/deploy"
:path => "vApp/#{vapp_id}/action/deploy"
)
end
@ -34,7 +34,7 @@ module Fog
class Mock
def deploy_vapp(task_id)
def deploy_vapp(vapp_id)
raise MockNotImplemented.new("Contributions welcome!")
end

View file

@ -0,0 +1,37 @@
module Fog
module Terremark
class Real
require 'fog/terremark/parsers/get_public_ips'
# Get list of public ips
#
# ==== Parameters
# * vdc_id<~Integer> - Id of vdc to find public ips for
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'PublicIpAddresses'<~Array>
# * 'href'<~String> - linke to item
# * 'name'<~String> - name of item
def get_public_ips(vdc_id)
request(
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Terremark::GetPublicIps.new,
:path => "vdc/#{vdc_id}/publicIps"
)
end
end
class Mock
def get_public_ips(vdc_id)
raise MockNotImplemented.new("Contributions welcome!")
end
end
end
end

View file

@ -30,7 +30,7 @@ module Fog
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Terremark::Task.new,
:path => "/task/#{task_id}"
:path => "task/#{task_id}"
)
end

View file

@ -23,7 +23,7 @@ module Fog
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Terremark::GetTasksList.new,
:path => "/tasksList/#{tasks_list_id}"
:path => "tasksList/#{tasks_list_id}"
)
end

View file

@ -33,7 +33,7 @@ module Fog
:expects => 200,
:method => 'GET',
:parser => Fog::Parsers::Terremark::Vapp.new,
:path => "/vapp/#{vapp_id}"
:path => "vapp/#{vapp_id}"
)
end

View file

@ -23,12 +23,8 @@ module Fog
# * 'name'<~String> - Name of catalog
def instantiate_vapp_template(name)
# FIXME: much cheating to commence
organization_id = get_organizations.body['OrgList'].first['href'].split('/').last
organization = get_organization(organization_id).body
vdc_id = organization['Links'].select {|link| link['type'] == 'application/vnd.vmware.vcloud.vdc+xml'}.first['href'].split('/').last
vdc = get_vdc(vdc_id).body
network_id = vdc['AvailableNetworks'].first['href'].split('/').last
vdc_id = default_vdc_id
network_id = default_network_id
catalog_item = 12 # Ubuntu JeOS 9.10 (64-bit)
# case UNRESOLVED:
@ -101,7 +97,7 @@ DATA
:headers => { 'Content-Type' => 'application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml' },
:method => 'POST',
:parser => Fog::Parsers::Terremark::InstantiateVappTemplate.new,
:path => "/vdc/#{vdc_id}/action/instantiatevAppTemplate"
:path => "vdc/#{vdc_id}/action/instantiatevAppTemplate"
)
end

View file

@ -26,7 +26,7 @@ module Fog
:expects => 202,
:method => 'POST',
:parser => Fog::Parsers::Terremark::Task.new,
:path => "/vApp/#{vapp_id}/power/action/powerOff"
:path => "vApp/#{vapp_id}/power/action/powerOff"
)
end

View file

@ -26,7 +26,7 @@ module Fog
:expects => 202,
:method => 'POST',
:parser => Fog::Parsers::Terremark::Task.new,
:path => "/vApp/#{vapp_id}/power/action/powerOn"
:path => "vApp/#{vapp_id}/power/action/powerOn"
)
end

View file

@ -26,7 +26,7 @@ module Fog
:expects => 202,
:method => 'POST',
:parser => Fog::Parsers::Terremark::Task.new,
:path => "/vApp/#{vapp_id}/power/action/reset"
:path => "vApp/#{vapp_id}/power/action/reset"
)
end

View file

@ -26,7 +26,7 @@ module Fog
:expects => 202,
:method => 'POST',
:parser => Fog::Parsers::Terremark::Task.new,
:path => "/vApp/#{vapp_id}/power/action/shutdown"
:path => "vApp/#{vapp_id}/power/action/shutdown"
)
end