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

fixing merge conflicts

This commit is contained in:
Kyle Rames 2013-02-04 09:12:40 -06:00
commit 93e004215f
25 changed files with 419 additions and 150 deletions

View file

@ -7,9 +7,9 @@ fog is the Ruby cloud services library, top to bottom:
* Mocks make testing and integrating a breeze.
[![Build Status](https://secure.travis-ci.org/fog/fog.png?branch=master)](http://travis-ci.org/fog/fog)
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/fog/fog)
[![Gem Version](https://fury-badge.herokuapp.com/rb/fog.png)](http://badge.fury.io/rb/fog)
[![Dependency Status](https://gemnasium.com/fog/fog.png)](https://gemnasium.com/fog/fog)
[![Code Climate](https://codeclimate.com/github/fog/fog.png)](https://codeclimate.com/github/fog/fog)
## Getting Started

View file

@ -85,7 +85,7 @@ module Fog
@host = options[:host] || "dynamodb.#{@region}.amazonaws.com"
@path = options[:path] || '/'
@persistent = options[:persistent] || false
@port = options[:port] || '80' #443
@port = options[:port] || '443'
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)

View file

@ -11,7 +11,7 @@ module Fog
attribute :platform
attribute :operating_system, :aliases => "operatingsystem"
attribute :min_mem_size, :aliases => "minimummemorysize"
attribute :minimum_memory_size, :aliases => "minimummemorysize"
attribute :minimum_disk_size, :aliases => "minimumdisksize"
attribute :instance_cost, :aliases => "instancecost"
attribute :license_cost, :aliases => "licensecost"

View file

@ -24,8 +24,10 @@ module Fog
collection :flavors
model :image
collection :images
model :attachments
model :attachment
collection :attachments
model :network
collection :networks
request_path 'fog/rackspace/requests/compute_v2'
request :list_servers
@ -62,6 +64,11 @@ module Fog
request :set_metadata_item
request :delete_metadata_item
request :list_networks
request :get_network
request :create_network
request :delete_network
class Mock
include Fog::Rackspace::MockData
@ -127,8 +134,13 @@ module Fog
rescue Excon::Errors::HTTPStatusError => error
raise ServiceError.slurp error
end
unless response.body.empty?
begin
response.body = Fog::JSON.decode(response.body)
rescue MultiJson::DecodeError => e
response.body = {}
end
end
response
end

View file

@ -31,7 +31,6 @@ module Fog
request :create_user
request :update_user
request :delete_user
request :get_credentials
class Mock
def request

View file

@ -4,11 +4,11 @@ module Fog
def data
@@data ||= Hash.new do |hash, key|
hash[key] = begin
#Compute V2
flavor_id = Fog.credentials[:rackspace_flavor_id].to_s ||= Fog::Mock.random_numbers(1)
image_id = Fog.credentials[:rackspace_image_id] ||= Fog::Rackspace::MockData.uuid
image_name = Fog::Mock.random_letters(6)
network_id = Fog::Rackspace::MockData.uuid
flavor = {
"OS-FLV-DISABLED:disabled" => false,
@ -78,6 +78,11 @@ module Fog
"updated" => "2012-02-28T19:39:05Z"
}
network = {
'id' => network_id,
'label' => 'network label',
'cidr' => '192.168.0.0/24'
}
#Block Storage
volume_type1_id = Fog::Mock.random_numbers(3).to_i
@ -101,6 +106,7 @@ module Fog
:flavors => {flavor_id => flavor},
:images => {image_id => image},
:servers => {},
:networks => { network_id => network },
#Block Storage
:volumes => {},

View file

@ -0,0 +1,27 @@
module Fog
module Compute
class RackspaceV2
class Network < Fog::Model
identity :id
attribute :label
attribute :cidr
def save
requires :label, :cidr
data = service.create_network(label, cidr)
merge_attributes(data.body['network'])
true
end
def destroy
requires :identity
service.delete_network(identity)
true
end
end
end
end
end

View file

@ -0,0 +1,23 @@
require 'fog/rackspace/models/compute_v2/network'
module Fog
module Compute
class RackspaceV2
class Networks < Fog::Collection
model Fog::Compute::RackspaceV2::Network
def all
data = service.list_networks.body['networks']
load(data)
end
def get(id)
data = service.get_network(id).body['network']
new(data)
rescue Fog::Compute::RackspaceV2::NotFound
nil
end
end
end
end
end

View file

@ -131,12 +131,12 @@ module Fog
# @return [String] The image Id.
# @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Images-d1e4435.html
attribute :image_id, :aliases => 'image', :squash => 'id'
# @!attribute [r] password
# @return [String] Password for system adminstrator account.
# @note This value is ONLY populated on server creation.
attr_reader :password
def initialize(attributes={})
@service = attributes[:service]
super
@ -167,11 +167,11 @@ module Fog
# Saves the server.
# Creates server if it is new, otherwise it will update server attributes name, accessIPv4, and accessIPv6.
# @return [Boolean] true if server has started saving
def save
def save(options = {})
if persisted?
update
else
create
create(options)
end
true
end
@ -187,14 +187,17 @@ module Fog
# * State Transitions
# * BUILD -> ACTIVE
# * BUILD -> ERROR (on error)
def create
def create(options)
requires :name, :image_id, :flavor_id
options = {}
options[:disk_config] = disk_config unless disk_config.nil?
options[:metadata] = metadata.to_hash unless @metadata.nil?
options[:personality] = personality unless personality.nil?
if options[:networks]
options[:networks].map! { |id| { :uuid => id } }
end
data = service.create_server(name, image_id, flavor_id, 1, 1, options)
merge_attributes(data.body['server'])
true

View file

@ -8,9 +8,9 @@ module Fog
model Fog::DNS::Rackspace::Zone
def all
def all(options={})
clear
data = service.list_domains.body['domains']
data = service.list_domains(options).body['domains']
load(data)
end
@ -23,6 +23,30 @@ module Fog
load(data)
end
alias :each_zone_this_page :each
def each
if !block_given?
self
else
body = service.list_domains.body
subset = dup.all
subset.each_zone_this_page {|f| yield f}
if body.has_key?('links')
while !body['links'].select{|l| l['rel'] == 'next'}.empty?
url = body['links'].select{|l| l['rel'] == 'next'}.first['href']
query = url.match(/\?(.+)/)
parsed = CGI.parse($1)
body = service.list_domains(:offset => parsed['offset'], :limit => parsed['limit']).body
subset = dup.all(:offset => parsed['offset'], :limit => parsed['limit'])
subset.each_zone_this_page {|f| yield f}
end
end
self
end
end
def get(zone_id)
if zone_id.nil? or zone_id.to_s.empty?
return nil

View file

@ -17,14 +17,15 @@ module Fog
def get(id)
requires :user
data = retrieve_credentials.find{ |credential| credential['id'] == id }
data = retrieve_credentials.find { |credential| credential['apiKey'] == id }
data && new(data)
end
private
def retrieve_credentials
data = service.list_credentials(user.identity).body['credentials']
raw_credentials = service.list_credentials(user.identity).body['credentials']
raw_credentials.map { |c| c['RAX-KSKEY:apiKeyCredentials'] }
end
end
end

View file

@ -0,0 +1,36 @@
module Fog
module Compute
class RackspaceV2
class Real
def create_network(label, cidr)
data = {
'network' => {
'label' => label,
'cidr' => cidr
}
}
request(
:method => 'POST',
:body => Fog::JSON.encode(data),
:path => "os-networksv2",
:expects => 200
)
end
end
class Mock
def create_network(label, cidr)
network_id = Fog::Rackspace::MockData.uuid
self.data[:networks][network_id] = {
'id' => network_id,
'label' => label,
'cidr' => cidr
}
response(:body => { 'network' => self.data[:networks][network_id] })
end
end
end
end
end

View file

@ -51,6 +51,10 @@ module Fog
data['server']['OS-DCF:diskConfig'] = options[:disk_config] unless options[:disk_config].nil?
data['server']['metadata'] = options[:metadata] unless options[:metadata].nil?
data['server']['personality'] = options[:personality] unless options[:personality].nil?
data['server']['networks'] = options[:networks] || [
{ :uuid => '00000000-0000-0000-0000-000000000000' },
{ :uuid => '11111111-1111-1111-1111-111111111111' }
]
request(
:body => Fog::JSON.encode(data),

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class RackspaceV2
class Real
def delete_network(id)
request(:method => 'DELETE', :path => "os-networksv2/#{id}", :expects => 202)
end
end
class Mock
def delete_network(id)
unless self.data[:networks].has_key?(id)
raise Fog::Compute::RackspaceV2::NotFound
end
response(:body => '', :status => 202)
end
end
end
end
end

View file

@ -0,0 +1,21 @@
module Fog
module Compute
class RackspaceV2
class Real
def get_network(id)
request(:method => 'GET', :path => "os-networksv2/#{id}", :expects => 200)
end
end
class Mock
def get_network(id)
unless self.data[:networks].has_key?(id)
raise Fog::Compute::RackspaceV2::NotFound
end
response(:body => { 'network' => self.data[:networks][id] })
end
end
end
end
end

View file

@ -0,0 +1,18 @@
module Fog
module Compute
class RackspaceV2
class Real
def list_networks
request(:method => 'GET', :path => 'os-networksv2', :expects => 200)
end
end
class Mock
def list_networks
networks = self.data[:networks].values
response(:body => { 'networks' => networks })
end
end
end
end
end

View file

@ -1,15 +0,0 @@
module Fog
module Rackspace
class Identity
class Real
def get_credentials(user_id)
request(
:expects => [200, 203],
:method => 'GET',
:path => "users/#{user_id}/OS-KSADM/credentials/RAX-KSKEY:apiKeyCredentials"
)
end
end
end
end
end

View file

@ -94,7 +94,7 @@ module Fog
@connection_options = options[:connection_options] || {}
authenticate
@persistent = options[:persistent] || false
Excon.ssl_verify_peer = false if options[:rackspace_servicenet] == true
Excon.defaults[:ssl_verify_peer] = false if options[:rackspace_servicenet] == true
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

View file

@ -39,7 +39,7 @@ module Fog
def device_change attributes
devices = []
if (nics = attributes[:interfaces])
devices << nics.map { |nic| create_interface(nic, nics.index(nic)) }
devices << nics.map { |nic| create_interface(nic, nics.index(nic), :add, attributes) }
end
if (disks = attributes[:volumes])
@ -49,7 +49,22 @@ module Fog
devices.flatten
end
def create_interface nic, index = 0, operation = :add
def create_nic_backing nic, attributes
raw_network = get_raw_network(nic.network, attributes[:datacenter])
if raw_network.kind_of? RbVmomi::VIM::DistributedVirtualPortgroup
RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(
:port => RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
:portgroupKey => raw_network.key,
:switchUuid => raw_network.config.distributedVirtualSwitch.uuid
)
)
else
RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(:deviceName => nic.network)
end
end
def create_interface nic, index = 0, operation = :add, attributes = {}
{
:operation => operation,
:device => nic.type.new(
@ -59,7 +74,7 @@ module Fog
:label => nic.name,
:summary => nic.summary,
},
:backing => RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(:deviceName => nic.network),
:backing => create_nic_backing(nic, attributes),
:addressType => 'generated')
}
end

View file

@ -33,7 +33,7 @@ module Fog
{
:name => nic.deviceInfo.label,
:mac => nic.macAddress,
:network => nic.backing.network.name,
:network => nic.backing.respond_to?("network") ? nic.backing.network.name : nic.backing.port.portgroupKey,
:status => nic.connectable.status,
:summary => nic.deviceInfo.summary,
:type => nic.class,

View file

@ -0,0 +1,10 @@
Shindo.tests('Fog::Compute::RackspaceV2 | network', ['rackspace']) do
service = Fog::Compute::RackspaceV2.new
options = {
:label => "fog_network_#{Time.now.to_i.to_s}",
:cidr => '192.168.0.0/24'
}
model_tests(service.networks, options, true)
end

View file

@ -0,0 +1,10 @@
Shindo.tests('Fog::Compute::RackspaceV2 | networks', ['rackspace']) do
service = Fog::Compute::RackspaceV2.new
options = {
:label => "fog_network_#{Time.now.to_i.to_s}",
:cidr => '192.168.0.0/24'
}
collection_tests(service.networks, options, true)
end

View file

@ -5,12 +5,21 @@ Shindo.tests('Fog::Rackspace::Identity | credentials', ['rackspace']) do
service = Fog::Rackspace::Identity.new
user = service.users.all.first
tests('success') do
tests("#all").succeeds do
user.credentials.all
credentials = user.credentials.all
credentials.all? { |c| c.username && c.apiKey }
end
tests("#get").succeeds do
credential = user.credentials.all.first
user.credentials.get(credential.identity)
list_credential = user.credentials.all.first
credential = user.credentials.get(list_credential.identity)
credential.username && credential.apiKey
end
end
tests("failure").returns(nil) do
user.credentials.get('i am a credential that does not exist')
end
end

View file

@ -0,0 +1,49 @@
Shindo.tests('Fog::Compute::RackspaceV2 | network_tests', ['rackspace']) do
service = Fog::Compute.new(:provider => 'Rackspace', :version => 'V2')
network_format = {
'id' => String,
'label' => String,
'cidr' => Fog::Nullable::String
}
get_network_format = {
'network' => network_format
}
list_networks_format = {
'networks' => [network_format]
}
tests('success') do
network_id = nil
tests('#create_network').formats(get_network_format) do
service.create_network("fog_#{Time.now.to_i.to_s}", '192.168.0.0/24').body.tap do |r|
network_id = r['network']['id']
end
end
tests('#list_networks').formats(list_networks_format) do
service.list_networks.body
end
tests('#get_network').formats(get_network_format) do
service.get_network(network_id).body
end
tests('#delete_network').succeeds do
service.delete_network(network_id)
end
end
test('failure') do
tests('#get_network').raises(Fog::Compute::RackspaceV2::NotFound) do
service.get_network(0)
end
tests('#delete_network').raises(Fog::Compute::RackspaceV2::NotFound) do
service.delete_network(0)
end
end
end

View file

@ -99,9 +99,5 @@ Shindo.tests('Fog::Rackspace::Identity | users', ['rackspace']) do
tests('#list_credentials').formats(CREDENTIALS_FORMAT) do
service.list_credentials(credential_id).body
end
tests('#get_credentials').formats(CREDENTIAL_FORMAT) do
service.get_credentials(credential_id).body
end
end
end