Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'upstream/master' into vpc-security-group

  • Loading branch information...
commit 40265911302d1c7fc68362d2ca5ad88881bc50e8 2 parents 69fee3f + 5e8f551
@maf23 maf23 authored
Showing with 851 additions and 31 deletions.
  1. +2 −2 fog.gemspec
  2. +5 −0 lib/fog/aws/compute.rb
  3. +1 −0  lib/fog/aws/models/compute/server.rb
  4. +58 −0 lib/fog/aws/models/compute/subnet.rb
  5. +99 −0 lib/fog/aws/models/compute/subnets.rb
  6. +5 −5 lib/fog/aws/models/compute/vpc.rb
  7. +10 −7 lib/fog/aws/models/dns/record.rb
  8. +51 −0 lib/fog/aws/parsers/compute/create_subnet.rb
  9. +24 −0 lib/fog/aws/parsers/compute/delete_subnet.rb
  10. +49 −0 lib/fog/aws/parsers/compute/describe_subnets.rb
  11. +79 −0 lib/fog/aws/requests/compute/create_subnet.rb
  12. +49 −0 lib/fog/aws/requests/compute/delete_subnet.rb
  13. +66 −0 lib/fog/aws/requests/compute/describe_subnets.rb
  14. +1 −1  lib/fog/aws/requests/storage/sync_clock.rb
  15. +7 −7 lib/fog/cloudstack.rb
  16. +8 −0 lib/fog/core/model.rb
  17. +15 −2 lib/fog/ovirt/compute.rb
  18. +1 −3 lib/fog/ovirt/models/compute/cluster.rb
  19. +22 −0 lib/fog/ovirt/models/compute/interface.rb
  20. +32 −0 lib/fog/ovirt/models/compute/interfaces.rb
  21. +28 −1 lib/fog/ovirt/models/compute/server.rb
  22. +11 −0 lib/fog/ovirt/models/compute/template.rb
  23. +23 −0 lib/fog/ovirt/requests/compute/add_interface.rb
  24. +25 −0 lib/fog/ovirt/requests/compute/destroy_interface.rb
  25. +17 −0 lib/fog/ovirt/requests/compute/list_networks.rb
  26. +20 −0 lib/fog/ovirt/requests/compute/list_template_interfaces.rb
  27. +20 −0 lib/fog/ovirt/requests/compute/list_vm_interfaces.rb
  28. +10 −0 lib/fog/ovirt/requests/compute/mock_files/nics.xml
  29. +25 −0 lib/fog/ovirt/requests/compute/update_interface.rb
  30. +5 −0 tests/aws/models/compute/subnet_tests.rb
  31. +6 −0 tests/aws/models/compute/subnets_tests.rb
  32. +36 −0 tests/aws/requests/compute/subnet_tests.rb
  33. +5 −3 tests/ovirt/compute_tests.rb
  34. +27 −0 tests/ovirt/models/compute/interface_tests.rb
  35. +9 −0 tests/ovirt/models/compute/interfaces_tests.rb
View
4 fog.gemspec
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
## List your runtime dependencies here. Runtime dependencies are those
## that are needed for an end user to actually USE your code.
s.add_dependency('builder')
- s.add_dependency('excon', '~>0.9.0')
+ s.add_dependency('excon', '~>0.10.0')
s.add_dependency('formatador', '~>0.2.0')
s.add_dependency('multi_json', '~>1.0')
s.add_dependency('mime-types')
@@ -54,7 +54,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('rdoc')
s.add_development_dependency('thor')
s.add_development_dependency('rspec', '~>1.3.1')
- s.add_development_dependency('rbovirt', '>=0.0.7')
+ s.add_development_dependency('rbovirt', '>=0.0.8')
s.add_development_dependency('shindo', '~>0.3.4')
s.add_development_dependency('virtualbox', '~>0.9.1')
s.add_development_dependency('fission')
View
5 lib/fog/aws/compute.rb
@@ -29,6 +29,8 @@ class AWS < Fog::Service
collection :volumes
model :spot_request
collection :spot_requests
+ model :subnet
+ collection :subnets
model :vpc
collection :vpcs
@@ -44,6 +46,7 @@ class AWS < Fog::Service
request :create_security_group
request :create_snapshot
request :create_spot_datafeed_subscription
+ request :create_subnet
request :create_tags
request :create_volume
request :create_vpc
@@ -52,6 +55,7 @@ class AWS < Fog::Service
request :delete_placement_group
request :delete_snapshot
request :delete_spot_datafeed_subscription
+ request :delete_subnet
request :delete_tags
request :delete_volume
request :delete_vpc
@@ -71,6 +75,7 @@ class AWS < Fog::Service
request :describe_spot_datafeed_subscription
request :describe_spot_instance_requests
request :describe_spot_price_history
+ request :describe_subnets
request :describe_tags
request :describe_volumes
request :describe_vpcs
View
1  lib/fog/aws/models/compute/server.rb
@@ -152,6 +152,7 @@ def save
'Placement.AvailabilityZone' => availability_zone,
'Placement.GroupName' => placement_group,
'Placement.Tenancy' => tenancy,
+ 'PrivateIpAddress' => private_ip_address,
'RamdiskId' => ramdisk_id,
'SecurityGroup' => groups,
'SecurityGroupId' => security_group_ids,
View
58 lib/fog/aws/models/compute/subnet.rb
@@ -0,0 +1,58 @@
+require 'fog/core/model'
+
+module Fog
+ module Compute
+ class AWS
+
+ class Subnet < Fog::Model
+
+ identity :subnet_id, :aliases => 'subnetId'
+ attribute :state
+ attribute :vpc_id, :aliases => 'vpcId'
+ attribute :cidr_block, :aliases => 'cidrBlock'
+ attribute :available_ip_address_count, :aliases => 'availableIpAddressCount'
+ attribute :availability_zone, :aliases => 'availabilityZone'
+ attribute :tag_set, :aliases => 'tagSet'
+
+
+ # Removes an existing subnet
+ #
+ # subnet.destroy
+ #
+ # ==== Returns
+ #
+ # True or false depending on the result
+ #
+
+ def destroy
+ requires :subnet_id
+
+ connection.delete_subnet(subnet_id)
+ true
+ end
+
+ # Create a subnet
+ #
+ # >> g = AWS.subnets.new(:vpc_id => "vpc-someId", :cidr_block => "10.0.0.0/24")
+ # >> g.save
+ #
+ # == Returns:
+ #
+ # requestId and a subnetSet object
+ #
+
+ def save
+ requires :vpc_id, :cidr_block
+ data = connection.create_subnet(vpc_id, cidr_block).body['subnetSet'].first
+ puts data
+ new_attributes = data.reject {|key,value| key == 'requestId'}
+ merge_attributes(new_attributes)
+ true
+
+ true
+ end
+
+ end
+ end
+ end
+end
View
99 lib/fog/aws/models/compute/subnets.rb
@@ -0,0 +1,99 @@
+require 'fog/core/collection'
+require 'fog/aws/models/compute/subnet'
+
+module Fog
+ module Compute
+ class AWS
+
+ class Subnets < Fog::Collection
+
+ attribute :filters
+
+ model Fog::Compute::AWS::Subnet
+
+ # Creates a new subnet
+ #
+ # AWS.subnets.new
+ #
+ # ==== Returns
+ #
+ # Returns the details of the new Subnet
+ #
+ #>> AWS.subnets.new
+ # <Fog::AWS::Compute::Subnet
+ # subnet_id=subnet-someId,
+ # state=[pending|available],
+ # vpc_id=vpc-someId
+ # cidr_block=someIpRange
+ # available_ip_address_count=someInt
+ # tagset=nil
+ # >
+ #
+
+ def initialize(attributes)
+ self.filters ||= {}
+ super
+ end
+
+ # Returns an array of all Subnets that have been created
+ #
+ # AWS.subnets.all
+ #
+ # ==== Returns
+ #
+ # Returns an array of all VPCs
+ #
+ #>> AWS.subnets.all
+ # <Fog::AWS::Compute::Subnet
+ # filters={}
+ # [
+ # subnet_id=subnet-someId,
+ # state=[pending|available],
+ # vpc_id=vpc-someId
+ # cidr_block=someIpRange
+ # available_ip_address_count=someInt
+ # tagset=nil
+ # ]
+ # >
+ #
+
+ def all(filters = filters)
+ unless filters.is_a?(Hash)
+ Fog::Logger.warning("all with #{filters.class} param is deprecated, use all('subnet-id' => []) instead [light_black](#{caller.first})[/]")
+ filters = {'subnet-id' => [*filters]}
+ end
+ self.filters = filters
+ data = connection.describe_subnets(filters).body
+ load(data['subnetSet'])
+ end
+
+ # Used to retrieve a Subnet
+ # subnet-id is required to get the associated VPC information.
+ #
+ # You can run the following command to get the details:
+ # AWS.subnets.get("subnet-12345678")
+ #
+ # ==== Returns
+ #
+ #>> AWS.subnets.get("subnet-12345678")
+ # <Fog::AWS::Compute::Subnet
+ # subnet_id=subnet-someId,
+ # state=[pending|available],
+ # vpc_id=vpc-someId
+ # cidr_block=someIpRange
+ # available_ip_address_count=someInt
+ # tagset=nil
+ # >
+ #
+
+ def get(subnet_id)
+ if subnet_id
+ self.class.new(:connection => connection).all('subnet-id' => subnet_id).first
+ end
+ end
+
+ end
+
+ end
+ end
+end
View
10 lib/fog/aws/models/compute/vpc.rb
@@ -6,13 +6,13 @@ class AWS
class VPC < Fog::Model
- identity :id, :aliases => 'vpcId'
+ identity :id, :aliases => 'vpcId'
attribute :state
- attribute :cidr_block, :aliases => 'cidrBlock'
- attribute :dhcp_options_id, :aliases => 'dhcpOptionsId'
- attribute :tags, :aliases => 'tagSet'
- attribute :tenancy, :aliases => 'instanceTenancy'
+ attribute :cidr_block, :aliases => 'cidrBlock'
+ attribute :dhcp_options_id, :aliases => 'dhcpOptionsId'
+ attribute :tags, :aliases => 'tagSet'
+ attribute :tenancy, :aliases => 'instanceTenancy'
def initialize(attributes={})
self.dhcp_options_id ||= "default"
View
17 lib/fog/aws/models/dns/record.rb
@@ -9,13 +9,14 @@ class Record < Fog::Model
deprecate :ip, :value
deprecate :ip=, :value=
- identity :name, :aliases => ['Name']
+ identity :name, :aliases => ['Name']
- attribute :value, :aliases => ['ResourceRecords']
- attribute :ttl, :aliases => ['TTL']
- attribute :type, :aliases => ['Type']
- attribute :status, :aliases => ['Status']
- attribute :created_at, :aliases => ['SubmittedAt']
+ attribute :value, :aliases => ['ResourceRecords']
+ attribute :ttl, :aliases => ['TTL']
+ attribute :type, :aliases => ['Type']
+ attribute :status, :aliases => ['Status']
+ attribute :created_at, :aliases => ['SubmittedAt']
+ attribute :alias_target, :aliases => ['AliasTarget']
def initialize(attributes={})
self.ttl ||= 3600
@@ -61,11 +62,13 @@ def zone=(new_zone)
end
def attributes_to_options(action)
- requires :name, :ttl, :type, :value, :zone
+ requires :name, :ttl, :type, :zone
+ requires_one :value, :alias_target
{
:action => action,
:name => name,
:resource_records => [*value],
+ :alias_target => symbolize_keys(alias_target),
:ttl => ttl,
:type => type
}
View
51 lib/fog/aws/parsers/compute/create_subnet.rb
@@ -0,0 +1,51 @@
+module Fog
+ module Parsers
+ module Compute
+ module AWS
+
+ class CreateSubnet < Fog::Parsers::Base
+
+ def reset
+ @subnet = { 'tagSet' => {} }
+ @response = { 'subnetSet' => [] }
+ @tag = {}
+ end
+
+ def start_element(name, attrs = [])
+ super
+ case name
+ when 'tagSet'
+ @in_tag_set = true
+ end
+ end
+
+ def end_element(name)
+ if @in_tag_set
+ case name
+ when 'item'
+ @subnet['tagSet'][@tag['key']] = @tag['value']
+ @tag = {}
+ when 'key', 'value'
+ @tag[name] = value
+ when 'tagSet'
+ @in_tag_set = false
+ end
+ else
+ case name
+ when 'subnetId', 'state', 'vpcId', 'cidrBlock', 'availableIpAddressCount', 'availabilityZone'
+ @subnet[name] = value
+ when 'subnet'
+ @response['subnetSet'] << @subnet
+ @subnet = { 'tagSet' => {} }
+ when 'requestId'
+ @response[name] = value
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+
View
24 lib/fog/aws/parsers/compute/delete_subnet.rb
@@ -0,0 +1,24 @@
+module Fog
+ module Parsers
+ module Compute
+ module AWS
+
+ class DeleteSubnet < Fog::Parsers::Base
+
+ def end_element(name)
+ case name
+ when 'requestId'
+ @response[name] = value
+ when 'return'
+ if value == 'true'
+ @response[name] = true
+ else
+ @response[name] = false
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
View
49 lib/fog/aws/parsers/compute/describe_subnets.rb
@@ -0,0 +1,49 @@
+module Fog
+ module Parsers
+ module Compute
+ module AWS
+
+ class DescribeSubnets < Fog::Parsers::Base
+
+ def reset
+ @subnet = { 'tagSet' => {} }
+ @response = { 'subnetSet' => [] }
+ @tag = {}
+ end
+
+ def start_element(name, attrs = [])
+ super
+ case name
+ when 'tagSet'
+ @in_tag_set = true
+ end
+ end
+
+ def end_element(name)
+ if @in_tag_set
+ case name
+ when 'item'
+ @subnet['tagSet'][@tag['key']] = @tag['value']
+ @tag = {}
+ when 'key', 'value'
+ @tag[name] = value
+ when 'tagSet'
+ @in_tag_set = false
+ end
+ else
+ case name
+ when 'subnetId', 'state', 'vpcId', 'cidrBlock', 'availableIpAddressCount', 'availabilityZone'
+ @subnet[name] = value
+ when 'item'
+ @response['subnetSet'] << @subnet
+ @subnet = { 'tagSet' => {} }
+ when 'requestId'
+ @response[name] = value
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
View
79 lib/fog/aws/requests/compute/create_subnet.rb
@@ -0,0 +1,79 @@
+module Fog
+ module Compute
+ class AWS
+ class Real
+
+ require 'fog/aws/parsers/compute/create_subnet'
+
+ # Creates a Subnet with the CIDR block you specify.
+ #
+ # ==== Parameters
+ # * vpcId<~String> - The ID of the VPC where you want to create the subnet.
+ # * cidrBlock<~String> - The CIDR block you want the Subnet to cover (e.g., 10.0.0.0/16).
+ # * options<~Hash>:
+ # * AvailabilityZone<~String> - The Availability Zone you want the subnet in. Default: AWS selects a zone for you (recommended)
+ #
+ # === Returns
+ # * response<~Excon::Response>:
+ # * body<~Hash>:
+ # * 'requestId'<~String> - Id of request
+ # * 'subnet'<~Array>:
+ # * 'subnetId'<~String> - The Subnet's ID
+ # * 'state'<~String> - The current state of the Subnet. ['pending', 'available']
+ # * 'cidrBlock'<~String> - The CIDR block the Subnet covers.
+ # * 'AvailableIpAddressCount'<~Integer> - The number of unused IP addresses in the subnet (the IP addresses for any stopped
+ # instances are considered unavailable)
+ # * 'AvailabilityZone'<~String> - The Availability Zone the subnet is in
+ # * 'tagSet'<~Array>: Tags assigned to the resource.
+ # * 'key'<~String> - Tag's key
+ # * 'value'<~String> - Tag's value
+ #
+ # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/2011-07-15/APIReference/ApiReference-query-CreateSubnet.html]
+ def create_subnet(vpcId, cidrBlock, options = {})
+ request({
+ 'Action' => 'CreateSubnet',
+ 'VpcId' => vpcId,
+ 'CidrBlock' => cidrBlock,
+ :parser => Fog::Parsers::Compute::AWS::CreateSubnet.new
+ }.merge!(options))
+
+ end
+ end
+
+ class Mock
+ def create_subnet(vpcId, cidrBlock, options = {})
+ av_zone = options['AvailabilityZone'].nil? ? 'us-east-1c' : options['AvailabilityZone']
+ Excon::Response.new.tap do |response|
+ if cidrBlock && vpcId
+ response.status = 200
+
+ response.body = {
+ 'requestId' => Fog::AWS::Mock.request_id,
+ 'subnetSet' => [
+ 'subnetId' => Fog::AWS::Mock.request_id,
+ 'state' => 'pending',
+ 'vpcId' => Fog::AWS::Mock.request_id,
+ 'cidrBlock' => cidrBlock,
+ 'availableIpAddressCount' => 16,
+ 'availabilityZone' => av_zone,
+ 'tagSet' => {}
+ ]
+ }
+ else
+ response.status = 400
+ response.body = {
+ 'Code' => 'InvalidParameterValue'
+ }
+ if cidrBlock.empty?
+ response.body['Message'] = "Invalid value '' for cidrBlock. Must be specified."
+ end
+ if vpcId.empty?
+ response.body['Message'] = "Invalid value '' for vpcId. Must be specified."
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
View
49 lib/fog/aws/requests/compute/delete_subnet.rb
@@ -0,0 +1,49 @@
+module Fog
+ module Compute
+ class AWS
+ class Real
+
+ require 'fog/aws/parsers/compute/delete_subnet'
+ # Deletes a subnet from a VPC. You must terminate all running instances in the subnet before deleting it, otherwise Amazon
+ # VPC returns an error
+ #
+ # ==== Parameters
+ # * subnet_id<~String> - The ID of the Subnet you want to delete.
+ #
+ # === Returns
+ # * response<~Excon::Response>:
+ # * body<~Hash>:
+ # * 'requestId'<~String> - Id of request
+ # * 'return'<~Boolean> - Returns true if the request succeeds.
+ #
+ # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/2011-07-15/APIReference/ApiReference-query-DeleteSubnet.html]
+ def delete_subnet(subnet_id)
+ request(
+ 'Action' => 'DeleteSubnet',
+ 'SubnetId' => subnet_id,
+ :parser => Fog::Parsers::Compute::AWS::DeleteSubnet.new
+ )
+ end
+ end
+
+ class Mock
+ def delete_subnet(subnet_id)
+ Excon::Response.new.tap do |response|
+ if subnet_id
+ response.status = 200
+
+ response.body = {
+ 'requestId' => Fog::AWS::Mock.request_id,
+ 'return' => true
+ }
+ else
+ message = 'MissingParameter => '
+ message << 'The request must contain the parameter subnet_id'
+ raise Fog::Compute::AWS::Error.new(message)
+ end
+ end
+ end
+ end
+ end
+ end
+end
View
66 lib/fog/aws/requests/compute/describe_subnets.rb
@@ -0,0 +1,66 @@
+module Fog
+ module Compute
+ class AWS
+ class Real
+
+ require 'fog/aws/parsers/compute/describe_subnets'
+
+ # Describe all or specified subnets
+ #
+ # ==== Parameters
+ # * filters<~Hash> - List of filters to limit results with
+ #
+ # === Returns
+ # * response<~Excon::Response>:
+ # * body<~Hash>:
+ # * 'requestId'<~String> - Id of request
+ # * 'subnetSet'<~Array>:
+ # * 'subnetId'<~String> - The Subnet's ID
+ # * 'state'<~String> - The current state of the Subnet. ['pending', 'available']
+ # * 'vpcId'<~String> - The ID of the VPC the subnet is in
+ # * 'cidrBlock'<~String> - The CIDR block the Subnet covers.
+ # * 'availableIpAddressCount'<~Integer> - The number of unused IP addresses in the subnet (the IP addresses for any
+ # stopped instances are considered unavailable)
+ # * 'availabilityZone'<~String> - The Availability Zone the subnet is in.
+ # * 'tagSet'<~Array>: Tags assigned to the resource.
+ # * 'key'<~String> - Tag's key
+ # * 'value'<~String> - Tag's value
+ # * 'instanceTenancy'<~String> - The allowed tenancy of instances launched into the Subnet.
+ #
+ # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/2011-07-15/APIReference/index.html?ApiReference-query-DescribeSubnets.html]
+ def describe_subnets(filters = {})
+ unless filters.is_a?(Hash)
+ Fog::Logger.warning("describe_subnets with #{filters.class} param is deprecated, use describe_subnets('subnet-id' => []) instead [light_black](#{caller.first})[/]")
+ filters = {'subnet-id' => [*filters]}
+ end
+ params = Fog::AWS.indexed_filters(filters)
+ request({
+ 'Action' => 'DescribeSubnets',
+ :idempotent => true,
+ :parser => Fog::Parsers::Compute::AWS::DescribeSubnets.new
+ }.merge!(params))
+ end
+ end
+
+ class Mock
+ def describe_subnets(filters = {})
+ Excon::Response.new.tap do |response|
+ response.status = 200
+ response.body = {
+ 'requestId' => Fog::AWS::Mock.request_id,
+ 'subnetSet' => [
+ 'subnetId' => Fog::AWS::Mock.request_id,
+ 'state' => 'pending',
+ 'vpcId' => Fog::AWS::Mock.request_id,
+ 'cidrBlock' => '10.255.255.0/24',
+ 'availableIpAddressCount' => 255,
+ 'availabilityZone' => 'us-east-1c',
+ 'tagSet' => {}
+ ]
+ }
+ end
+ end
+ end
+ end
+ end
+end
View
2  lib/fog/aws/requests/storage/sync_clock.rb
@@ -8,7 +8,7 @@ class Real
def sync_clock
response = begin
get_service
- rescue => error
+ rescue Excon::Errors::HTTPStatusError => error
error.response
end
Fog::Time.now = Time.parse(response.headers['Date'])
View
14 lib/fog/cloudstack.rb
@@ -7,20 +7,20 @@ module Cloudstack
extend Fog::Provider
service(:compute, 'cloudstack/compute','Compute')
-
- DIGEST = OpenSSL::Digest::Digest.new('sha1')
-
+
+ @@digest = OpenSSL::Digest::Digest.new('sha1')
+
def self.escape(string)
string = CGI::escape(string)
string = string.gsub("+","%20")
string
end
-
+
def self.signed_params(key,params)
query = params.to_a.sort.collect{|c| "#{c[0]}=#{escape(c[1].to_s)}"}.join('&').downcase
-
- signed_string = Base64.encode64(OpenSSL::HMAC.digest(DIGEST,key,query)).strip
-
+
+ signed_string = Base64.encode64(OpenSSL::HMAC.digest(@@digest,key,query)).strip
+
signed_string
end
end
View
8 lib/fog/core/model.rb
@@ -42,6 +42,14 @@ def to_json(options = {})
MultiJson.encode(attributes)
end
+ def symbolize_keys(hash)
+ return nil if hash.nil?
+ hash.inject({}) do |options, (key, value)|
+ options[(key.to_sym rescue key) || key] = value
+ options
+ end
+ end
+
def wait_for(timeout=Fog.timeout, interval=1, &block)
reload
retries = 3
View
17 lib/fog/ovirt/compute.rb
@@ -13,6 +13,8 @@ class Ovirt < Fog::Service
collection :templates
model :cluster
collection :clusters
+ model :interface
+ collection :interfaces
request_path 'fog/ovirt/requests/compute'
@@ -28,6 +30,12 @@ class Ovirt < Fog::Service
request :get_template
request :list_clusters
request :get_cluster
+ request :add_interface
+ request :destroy_interface
+ request :update_interface
+ request :list_vm_interfaces
+ request :list_template_interfaces
+ request :list_networks
module Shared
# converts an OVIRT object into an hash for fog to consume.
@@ -42,6 +50,8 @@ def ovirt_attrs obj
opts[key] = case value
when OVIRT::Link
value.id
+ when Array
+ value
when Hash
value
else
@@ -54,7 +64,6 @@ def ovirt_attrs obj
class Mock
include Shared
- attr_reader :client
def initialize(options={})
require 'rbovirt'
@@ -64,6 +73,7 @@ def initialize(options={})
end
private
+ attr_reader :client
#read mocks xml
def read_xml(file_name)
file_path = File.join(File.dirname(__FILE__),"requests","compute","mock_files",file_name)
@@ -73,7 +83,7 @@ def read_xml(file_name)
class Real
include Shared
- attr_reader :client
+
def initialize(options={})
require 'rbovirt'
@@ -87,6 +97,9 @@ def initialize(options={})
@client = OVIRT::Client.new(username, password, url, datacenter)
end
+
+ private
+ attr_reader :client
end
end
end
View
4 lib/fog/ovirt/models/compute/cluster.rb
@@ -1,5 +1,3 @@
-require 'fog/compute/models/server'
-
module Fog
module Compute
class Ovirt
@@ -12,7 +10,7 @@ class Cluster < Fog::Model
attribute :raw
def networks
- connection.client.networks(:cluster_id => id)
+ connection.list_networks(id)
end
def to_s
View
22 lib/fog/ovirt/models/compute/interface.rb
@@ -0,0 +1,22 @@
+module Fog
+ module Compute
+ class Ovirt
+
+ class Interface < Fog::Model
+ attr_accessor :raw
+ identity :id
+
+ attribute :name
+ attribute :network
+ attribute :interface
+ attribute :mac
+
+ def to_s
+ name
+ end
+
+ end
+
+ end
+ end
+end
View
32 lib/fog/ovirt/models/compute/interfaces.rb
@@ -0,0 +1,32 @@
+require 'fog/core/collection'
+require 'fog/ovirt/models/compute/interface'
+
+module Fog
+ module Compute
+ class Ovirt
+
+ class Interfaces < Fog::Collection
+
+ model Fog::Compute::Ovirt::Interface
+
+ attr_accessor :vm
+
+ def all(filters = {})
+ requires :vm
+ if vm.is_a? Fog::Compute::Ovirt::Server
+ load connection.list_vm_interfaces(vm.id)
+ elsif vm.is_a? Fog::Compute::Ovirt::Template
+ load connection.list_template_interfaces(vm.id)
+ else
+ raise 'interfaces should have vm or template'
+ end
+ end
+
+ def get(id)
+ new connection.get_interface(id)
+ end
+
+ end
+ end
+ end
+end
View
29 lib/fog/ovirt/models/compute/server.rb
@@ -24,18 +24,45 @@ class Server < Fog::Compute::Server
attribute :host
attribute :cluster
attribute :template
+ attribute :interfaces
attribute :raw
def ready?
!(status =~ /down/i)
end
+ def locked?
+ !!(status =~ /locked/i)
+ end
+
def stopped?
!!(status =~ /down/i)
end
def mac
- raw.interfaces.first.mac if raw.interfaces
+ interfaces.first.mac unless interfaces.empty?
+ end
+
+ def interfaces
+ attributes[:interfaces] ||= id.nil? ? [] : Fog::Compute::Ovirt::Interfaces.new(
+ :connection => connection,
+ :vm => self
+ )
+ end
+
+ def add_interface attrs
+ wait_for { stopped? } if attrs[:blocking]
+ connection.add_interface(id, attrs)
+ end
+
+ def update_interface attrs
+ wait_for { stopped? } if attrs[:blocking]
+ connection.update_interface(id, attrs)
+ end
+
+ def destroy_interface attrs
+ wait_for { stopped? } if attrs[:blocking]
+ connection.destroy_interface(id, attrs)
end
def start(options = {})
View
11 lib/fog/ovirt/models/compute/template.rb
@@ -6,6 +6,8 @@ class Template < Fog::Model
identity :id
+ attr_accessor :raw
+
attribute :name
attribute :description
attribute :profile
@@ -17,6 +19,15 @@ class Template < Fog::Model
attribute :cores, :aliases => 'cpus'
attribute :memory
attribute :cluster
+ attribute :interfaces
+
+
+ def interfaces
+ attributes[:interfaces] ||= id.nil? ? [] : Fog::Compute::Ovirt::Interfaces.new(
+ :connection => connection,
+ :vm => self
+ )
+ end
def ready?
!(status =~ /down/i)
View
23 lib/fog/ovirt/requests/compute/add_interface.rb
@@ -0,0 +1,23 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+
+ def add_interface(id, options = {})
+ raise ArgumentError, "instance id is a required parameter" unless id
+
+ client.add_interface(id, options)
+ end
+
+ end
+
+ class Mock
+ def add_interface(id, options = {})
+ raise ArgumentError, "instance id is a required parameter" unless id
+ true
+ end
+
+ end
+ end
+ end
+end
View
25 lib/fog/ovirt/requests/compute/destroy_interface.rb
@@ -0,0 +1,25 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+
+ def destroy_interface(id, options)
+ raise ArgumentError, "instance id is a required parameter" unless id
+ raise ArgumentError, "interface id is a required parameter for destroy-interface" unless options.has_key? :id
+
+ client.destroy_interface(id, options[:id])
+ end
+
+ end
+
+ class Mock
+ def destroy_interface(id, options)
+ raise ArgumentError, "instance id is a required parameter" unless id
+ raise ArgumentError, "interface id is a required parameter for destroy-interface" unless options.has_key? :id
+ true
+ end
+
+ end
+ end
+ end
+end
View
17 lib/fog/ovirt/requests/compute/list_networks.rb
@@ -0,0 +1,17 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+ def list_networks(cluster_id)
+ client.networks(:cluster_id => cluster_id)
+ end
+
+ end
+ class Mock
+ def list_networks(cluster_id)
+ []
+ end
+ end
+ end
+ end
+end
View
20 lib/fog/ovirt/requests/compute/list_template_interfaces.rb
@@ -0,0 +1,20 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+ def list_template_interfaces(vm_id)
+ client.template_interfaces(vm_id).map {|ovirt_obj| ovirt_attrs ovirt_obj}
+ end
+
+ end
+ class Mock
+ def list_template_interfaces(vm_id)
+ xml = read_xml 'nics.xml'
+ Nokogiri::XML(xml).xpath('/nics/nic').collect do |nic|
+ ovirt_attrs OVIRT::Interface::new(self, nic)
+ end
+ end
+ end
+ end
+ end
+end
View
20 lib/fog/ovirt/requests/compute/list_vm_interfaces.rb
@@ -0,0 +1,20 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+ def list_vm_interfaces(vm_id)
+ client.vm_interfaces(vm_id).map {|ovirt_obj| ovirt_attrs ovirt_obj}
+ end
+
+ end
+ class Mock
+ def list_vm_interfaces(vm_id)
+ xml = read_xml 'nics.xml'
+ Nokogiri::XML(xml).xpath('/nics/nic').collect do |nic|
+ ovirt_attrs OVIRT::Interface::new(self, nic)
+ end
+ end
+ end
+ end
+ end
+end
View
10 lib/fog/ovirt/requests/compute/mock_files/nics.xml
@@ -0,0 +1,10 @@
+<nics>
+<nic href="/api/vms/192cdd3f-3281-4e20-b81d-93bdc57ac387/nics/af743262-ebcf-4b18-ab5d-7218d788bdf3" id="af743262-ebcf-4b18-ab5d-7218d788bdf3">
+<name>nic1</name>
+<link href="/api/vms/192cdd3f-3281-4e20-b81d-93bdc57ac387/nics/af743262-ebcf-4b18-ab5d-7218d788bdf3/statistics" rel="statistics"/>
+<vm href="/api/vms/192cdd3f-3281-4e20-b81d-93bdc57ac387" id="192cdd3f-3281-4e20-b81d-93bdc57ac387"/>
+<network href="/api/networks/00000000-0000-0000-0000-000000000009" id="00000000-0000-0000-0000-000000000009"/>
+<interface>virtio</interface>
+<mac address="00:1a:4a:23:1b:8f"/>
+</nic>
+</nics>
View
25 lib/fog/ovirt/requests/compute/update_interface.rb
@@ -0,0 +1,25 @@
+module Fog
+ module Compute
+ class Ovirt
+ class Real
+
+ def update_interface(id, options)
+ raise ArgumentError, "instance id is a required parameter" unless id
+ raise ArgumentError, "interface id is a required parameter for update-interface" unless options.has_key? :id
+
+ client.update_interface(id, options)
+ end
+
+ end
+
+ class Mock
+ def update_interface(id, options)
+ raise ArgumentError, "instance id is a required parameter" unless id
+ raise ArgumentError, "interface id is a required parameter for update-interface" unless options.has_key? :id
+ true
+ end
+
+ end
+ end
+ end
+end
View
5 tests/aws/models/compute/subnet_tests.rb
@@ -0,0 +1,5 @@
+Shindo.tests("Fog::Compute[:aws] | subnet", ['aws']) do
+ @vpc=Fog::Compute[:aws].vpcs.create('cidr_block' => '10.0.10.0/24')
+ model_tests(Fog::Compute[:aws].subnets, {:vpc_id => @vpc.id, :cidr_block => '10.0.10.0/28'}, true)
+ @vpc.destroy
+end
View
6 tests/aws/models/compute/subnets_tests.rb
@@ -0,0 +1,6 @@
+Shindo.tests("Fog::Compute[:aws] | subnets", ['aws']) do
+ @vpc=Fog::Compute[:aws].vpcs.create('cidr_block' => '10.0.10.0/28')
+ collection_tests(Fog::Compute[:aws].subnets, { :vpc_id => @vpc.id, :cidr_block => '10.0.10.0/28'}, true)
+ @vpc.destroy
+end
+
View
36 tests/aws/requests/compute/subnet_tests.rb
@@ -0,0 +1,36 @@
+Shindo.tests('Fog::Compute[:aws] | subnet requests', ['aws']) do
+
+ @subnets_format = {
+ 'subnetSet' => [{
+ 'subnetId' => String,
+ 'state' => String,
+ 'vpcId' => String,
+ 'cidrBlock' => String,
+ 'availableIpAddressCount' => String,
+ 'availabilityZone' => String,
+ 'tagSet' => Hash,
+ }],
+ 'requestId' => String
+ }
+
+ tests('success') do
+ @vpc=Fog::Compute[:aws].vpcs.create('cidr_block' => '10.0.10.0/24')
+ @vpc_id = @vpc.id
+ @subnet_id = nil
+
+ tests('#create_subnet').formats(@subnets_format) do
+ data = Fog::Compute[:aws].create_subnet(@vpc_id, '10.0.10.16/28').body
+ @subnet_id = data['subnetSet'].first['subnetId']
+ data
+ end
+
+ tests('#describe_subnets').formats(@subnets_format) do
+ Fog::Compute[:aws].describe_subnets.body
+ end
+
+ tests("#delete_subnet('#{@subnet_id}')").formats(AWS::Compute::Formats::BASIC) do
+ Fog::Compute[:aws].delete_subnet(@subnet_id).body
+ end
+ @vpc.destroy
+ end
+end
View
8 tests/ovirt/compute_tests.rb
@@ -3,19 +3,21 @@
compute = Fog::Compute[:ovirt]
tests("Compute attributes") do
- %w{ client }.each do |attr|
+ %w{ ovirt_attrs }.each do |attr|
test("it should respond to #{attr}") { compute.respond_to? attr }
end
end
tests("Compute collections") do
- %w{ servers templates clusters }.each do |collection|
+ %w{ servers templates clusters interfaces }.each do |collection|
test("it should respond to #{collection}") { compute.respond_to? collection }
end
end
tests("Compute requests") do
- %w{ datacenters storage_domains vm_action destroy_vm }.each do |collection|
+ %w{ add_interface create_vm datacenters destroy_interface destroy_vm get_cluster get_template
+ get_virtual_machine list_clusters list_networks list_template_interfaces list_templates
+ list_virtual_machines list_vm_interfaces storage_domains update_interface update_vm vm_action }.each do |collection|
test("it should respond to #{collection}") { compute.respond_to? collection }
end
end
View
27 tests/ovirt/models/compute/interface_tests.rb
@@ -0,0 +1,27 @@
+Shindo.tests('Fog::Compute[:ovirt] | interface model', ['ovirt']) do
+
+ interfaces = Fog::Compute[:ovirt].servers.last.interfaces
+ interface = interfaces.last
+
+ tests('The interface model should') do
+ tests('have the action') do
+ test('reload') { interface.respond_to? 'reload' }
+ end
+ tests('have attributes') do
+ model_attribute_hash = interface.attributes
+ attributes = [ :id, :name, :network]
+ tests("The interface model should respond to") do
+ attributes.each do |attribute|
+ test("#{attribute}") { interface.respond_to? attribute }
+ end
+ end
+ tests("The attributes hash should have key") do
+ attributes.each do |attribute|
+ test("#{attribute}") { model_attribute_hash.has_key? attribute }
+ end
+ end
+ end
+ test('be a kind of Fog::Compute::Ovirt::Interface') { interface.kind_of? Fog::Compute::Ovirt::Interface }
+ end
+
+end
View
9 tests/ovirt/models/compute/interfaces_tests.rb
@@ -0,0 +1,9 @@
+Shindo.tests('Fog::Compute[:ovirt] | interfaces collection', ['ovirt']) do
+
+ interfaces = Fog::Compute[:ovirt].interfaces
+
+ tests('The interfaces collection') do
+ test('should be a kind of Fog::Compute::Ovirt::Interfaces') { interfaces.kind_of? Fog::Compute::Ovirt::Interfaces }
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.