mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Abillity to List Images and List SSH Keys
This commit is contained in:
parent
a816990270
commit
07f4267d8e
9 changed files with 188 additions and 3 deletions
22
lib/fog/terremark/models/shared/image.rb
Normal file
22
lib/fog/terremark/models/shared/image.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Terremark
|
||||
module Shared
|
||||
|
||||
class Image < Fog::Model
|
||||
|
||||
identity :id
|
||||
|
||||
attribute :name
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def href=(new_href)
|
||||
self.id = new_href.split('/').last.to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
48
lib/fog/terremark/models/shared/images.rb
Normal file
48
lib/fog/terremark/models/shared/images.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/terremark/models/shared/image'
|
||||
|
||||
module Fog
|
||||
module Terremark
|
||||
module Shared
|
||||
|
||||
|
||||
module Mock
|
||||
def images(options = {})
|
||||
Fog::Terremark::Shared::Images.new(options.merge(:connection => self))
|
||||
end
|
||||
end
|
||||
|
||||
module Real
|
||||
def images(options = {})
|
||||
Fog::Terremark::Shared::Images.new(options.merge(:connection => self))
|
||||
end
|
||||
end
|
||||
|
||||
class Images < Fog::Collection
|
||||
|
||||
|
||||
model Fog::Terremark::Shared::Image
|
||||
|
||||
def all
|
||||
data = connection.get_catalog(vdc_id).body['CatalogItems'].select do |entity|
|
||||
entity['type'] == "application/vnd.vmware.vcloud.catalogItem+xml"
|
||||
end
|
||||
load(data)
|
||||
end
|
||||
|
||||
|
||||
def vdc_id
|
||||
@vdc_id ||= connection.default_vdc_id
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def vdc_id=(new_vdc_id)
|
||||
@vdc_id = new_vdc_id
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -22,6 +22,9 @@ module Fog
|
|||
connection.servers(:vdc_id => id)
|
||||
end
|
||||
|
||||
def images
|
||||
connection.images(:vdc_id => id)
|
||||
end
|
||||
private
|
||||
|
||||
def href=(new_href)
|
||||
|
|
|
@ -14,9 +14,17 @@ module Fog
|
|||
case name
|
||||
when 'CatalogItem'
|
||||
catalog_item = {}
|
||||
until attributes.empty?
|
||||
catalog_item[attributes.shift] = attributes.shift
|
||||
attributes.each do |attrib|
|
||||
i = 0
|
||||
while i < attrib.size
|
||||
catalog_item[attrib[i]] = attrib[i+1]
|
||||
i += 2
|
||||
end
|
||||
catalog_item["id"] = catalog_item["href"].split('/').last
|
||||
end
|
||||
# until attributes.empty?
|
||||
# catalog_item[attributes.shift] = attributes.shift
|
||||
# end
|
||||
@response['CatalogItems'] << catalog_item
|
||||
when 'Catalog'
|
||||
catalog = {}
|
||||
|
|
56
lib/fog/terremark/parsers/shared/get_keys_list.rb
Normal file
56
lib/fog/terremark/parsers/shared/get_keys_list.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
|
||||
module Fog
|
||||
module Parsers
|
||||
module Terremark
|
||||
module Shared
|
||||
|
||||
class GetKeysList < Fog::Parsers::Base
|
||||
|
||||
def reset
|
||||
@response = { 'Keys' => [] }
|
||||
@key = {}
|
||||
end
|
||||
|
||||
def start_element(name, attributes)
|
||||
super
|
||||
case name
|
||||
when 'Id', 'Href', 'Name', 'IsDefault','FingerPrint'
|
||||
data = {}
|
||||
until attributes.empty?
|
||||
data[attributes.shift] = attributes.shift
|
||||
end
|
||||
@key[name] = data
|
||||
when 'Key'
|
||||
until attributes.empty?
|
||||
@key[attributes.shift] = attributes.shift
|
||||
end
|
||||
when 'Keys'
|
||||
keys_list = {}
|
||||
until attributes.empty?
|
||||
if attributes.first.is_a?(Array)
|
||||
attribute = attributes.shift
|
||||
keys_list[attribute.first] = attribute.last
|
||||
else
|
||||
keys_list[attributes.shift] = attributes.shift
|
||||
end
|
||||
end
|
||||
@response['href'] = keys_list['href']
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'Id', 'Href', 'Name', 'IsDefault','FingerPrint'
|
||||
@key[name] = value
|
||||
when 'Key'
|
||||
@response['Keys'] << @key
|
||||
@key = {}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
39
lib/fog/terremark/requests/shared/get_keys_list.rb
Normal file
39
lib/fog/terremark/requests/shared/get_keys_list.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
module Fog
|
||||
module Terremark
|
||||
module Shared
|
||||
module Real
|
||||
include Common
|
||||
|
||||
# Get list of SSH keys for an organization
|
||||
#
|
||||
# ==== Parameters
|
||||
# * organization_id<~Integer> - Id of organization to lookup
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'description'<~String> - Description of organization
|
||||
# * 'links'<~Array> - An array of links to entities in the organization
|
||||
# * 'href'<~String> - location of link
|
||||
# * 'name'<~String> - name of link
|
||||
# * 'rel'<~String> - action to perform
|
||||
# * 'type'<~String> - type of link
|
||||
def get_keys_list(organization_id)
|
||||
org_path = @path
|
||||
@path="/api/extensions/v1.6/"
|
||||
response = request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Terremark::Shared::GetKeysList.new,
|
||||
:path => "org/#{organization_id}/keys"
|
||||
)
|
||||
#Restore original path
|
||||
@path = org_path
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -23,6 +23,9 @@ module Fog
|
|||
unless name.length < 15
|
||||
raise ArgumentError.new('Name must be fewer than 15 characters')
|
||||
end
|
||||
unless options['ssh_key_fingerprint']
|
||||
raise ArgumentError.new("SSH Key Fingerprint is a compulsary parameter")
|
||||
end
|
||||
options['cpus'] ||= 1
|
||||
options['memory'] ||= 512
|
||||
options['network_id'] ||= default_network_id
|
||||
|
@ -34,6 +37,7 @@ module Fog
|
|||
<VAppTemplate href="#{@scheme}://#{@host}/#{@path}/vAppTemplate/#{vapp_template}" />
|
||||
<InstantiationParams xmlns:vmw="http://www.vmware.com/schema/ovf">
|
||||
<ProductSection xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:q1="http://www.vmware.com/vcloud/v0.8"/>
|
||||
<Property xmlns="http://schemas.dmtf.org/ovf/envelope/1" ovf:key="sshKeyFingerprint" ovf:value="#{options['ssh_key_fingerprint']}" />
|
||||
<VirtualHardwareSection xmlns:q1="http://www.vmware.com/vcloud/v0.8">
|
||||
<Item xmlns="http://schemas.dmtf.org/ovf/envelope/1">
|
||||
<InstanceID xmlns="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData">1</InstanceID>
|
||||
|
|
|
@ -236,6 +236,8 @@ module Fog
|
|||
require 'fog/terremark/models/shared/networks'
|
||||
require 'fog/terremark/models/shared/server'
|
||||
require 'fog/terremark/models/shared/servers'
|
||||
require 'fog/terremark/models/shared/image'
|
||||
require 'fog/terremark/models/shared/images'
|
||||
require 'fog/terremark/models/shared/task'
|
||||
require 'fog/terremark/models/shared/tasks'
|
||||
require 'fog/terremark/models/shared/vdc'
|
||||
|
@ -249,6 +251,7 @@ module Fog
|
|||
require 'fog/terremark/parsers/shared/get_organizations'
|
||||
require 'fog/terremark/parsers/shared/get_public_ips'
|
||||
require 'fog/terremark/parsers/shared/get_tasks_list'
|
||||
require 'fog/terremark/parsers/shared/get_keys_list'
|
||||
require 'fog/terremark/parsers/shared/get_vapp_template'
|
||||
require 'fog/terremark/parsers/shared/get_vdc'
|
||||
require 'fog/terremark/parsers/shared/instantiate_vapp_template'
|
||||
|
@ -278,6 +281,7 @@ module Fog
|
|||
require 'fog/terremark/requests/shared/get_public_ips'
|
||||
require 'fog/terremark/requests/shared/get_task'
|
||||
require 'fog/terremark/requests/shared/get_tasks_list'
|
||||
require 'fog/terremark/requests/shared/get_keys_list'
|
||||
require 'fog/terremark/requests/shared/get_vapp'
|
||||
require 'fog/terremark/requests/shared/get_vapp_template'
|
||||
require 'fog/terremark/requests/shared/get_vdc'
|
||||
|
|
|
@ -7,7 +7,8 @@ module Fog
|
|||
|
||||
module Defaults
|
||||
HOST = 'services.vcloudexpress.terremark.com'
|
||||
PATH = '/api/v0.8'
|
||||
PATH = '/api/v0.8a-ext1.6'
|
||||
#PATH = '/api/'
|
||||
PORT = 443
|
||||
SCHEME = 'https'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue