Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.rvmrc
.bundle
.DS_Store
.idea
coverage
doc/*
docs/_site/*
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def initialize(options={})
@persistent = options[:persistent] || true
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@version = options[:version] || '2010-10-01'
@version = options[:version] || '2011-05-05'

@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
end
Expand Down
100 changes: 87 additions & 13 deletions lib/fog/aws/models/dns/records.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,107 @@ class AWS

class Records < Fog::Collection

attribute :is_truncated, :aliases => ['IsTruncated']
attribute :max_items, :aliases => ['MaxItems']
attribute :is_truncated, :aliases => ['IsTruncated']
attribute :max_items, :aliases => ['MaxItems']
attribute :name
attribute :next_record_name, :aliases => ['NextRecordName']
attribute :next_record_type, :aliases => ['NextRecordType']
attribute :next_record_name, :aliases => ['NextRecordName']
attribute :next_record_type, :aliases => ['NextRecordType']
attribute :next_record_identifier, :aliases => ['NextRecordIdentifier']
attribute :type
attribute :identifier

attribute :zone

model Fog::DNS::AWS::Record

def all(options = {})
requires :zone
options['maxitems'] ||= max_items
options['name'] ||= name
options['type'] ||= type
options[:max_items] ||= max_items
options[:name] ||= zone.domain
options[:type] ||= type
options[:identifier] ||= identifier
options.delete_if {|key, value| value.nil?}

data = connection.list_resource_record_sets(zone.id, options).body
merge_attributes(data.reject {|key, value| !['IsTruncated', 'MaxItems', 'NextRecordName', 'NextRecordType'].include?(key)})
# NextRecordIdentifier is completely absent instead of nil, so set to nil, or iteration breaks.
data['NextRecordIdentifier'] = nil unless data.has_key?('NextRecordIdentifier')

merge_attributes(data.reject {|key, value| !['IsTruncated', 'MaxItems', 'NextRecordName', 'NextRecordType', 'NextRecordIdentifier'].include?(key)})
# leave out the default, read only records
data = data['ResourceRecordSets'].reject {|record| ['NS', 'SOA'].include?(record['Type'])}
# data = data['ResourceRecordSets'].reject {|record| ['NS', 'SOA'].include?(record['Type'])}
# AMT: these are not read only
data = data['ResourceRecordSets']
load(data)
end

def get(record_id)
data = connection.get_change(record_id).body
new(data)
rescue Excon::Errors::Forbidden
#
# Load all zone records into the collection.
#
def all!
data = []

begin
options = {
:name => next_record_name,
:type => next_record_type,
:identifier => next_record_identifier
}
options.delete_if {|key, value| value.nil?}

batch = connection.list_resource_record_sets(zone.id, options).body
# NextRecordIdentifier is completely absent instead of nil, so set to nil, or iteration breaks.
batch['NextRecordIdentifier'] = nil unless batch.has_key?('NextRecordIdentifier')

merge_attributes(batch.reject {|key, value| !['IsTruncated', 'MaxItems', 'NextRecordName', 'NextRecordType', 'NextRecordIdentifier'].include?(key)})

data.concat(batch['ResourceRecordSets'])
end while is_truncated

load(data)
end

#
# AWS Route 53 records are uniquely identified by a compound key of name, type, and identifier.
# #get allows one to retrieve a record using one or more of those key components.
#
# ==== Parameters
# * record_name - The name of the record to retrieve.
# * record_type - The type of record to retrieve, if nil, then the first matching record is returned.
# * record_identifier - The record set identifier to retrieve, if nil, then the first matching record is returned.
#
def get(record_name, record_type = nil, record_identifier = nil)
requires :zone
# Append a trailing period to the record_name if absent.
record_name = record_name + "." unless record_name.end_with?(".")
record_type = record_type.upcase unless record_type.nil?

options = {
:max_items => 1,
:name => record_name,
:type => record_type,
:identifier => record_identifier
}
options.delete_if {|key, value| value.nil?}

data = connection.list_resource_record_sets(zone.id, options).body
# Get first record
data = data['ResourceRecordSets'].shift

if data
record = new(data)
# make sure everything matches
if record.name == record_name
if (!record_type.nil? && record.type != record_type) ||
(!record_identifier.nil? && record.set_identifier != record_identifier)
nil
else
record
end
end
else
nil
end
rescue Excon::Errors::NotFound
nil
end

Expand Down
24 changes: 17 additions & 7 deletions lib/fog/aws/requests/dns/change_resource_record_sets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,42 @@ def change_resource_record_sets(zone_id, change_batch, options = {})
optional_tags+= "<Comment>#{value}</Comment>"
end
}

#build XML
if change_batch.count > 0

changes= "<ChangeBatch>#{optional_tags}<Changes>"

change_batch.each { |change_item|
action_tag = %Q{<Action>#{change_item[:action]}</Action>}
name_tag = %Q{<Name>#{change_item[:name]}</Name>}
type_tag = %Q{<Type>#{change_item[:type]}</Type>}
ttl_tag = %Q{<TTL>#{change_item[:ttl]}</TTL>}

raise "Weighted records require a 'setidentifier' and 'weight' tag to be specified, but you only specified the #{change_item[:setidentifier].nil?? 'weight' : 'setidentifier'}" if (change_item[:weight].nil? and !change_item[:setidentifier].nil?) or (!change_item[:weight].nil? and change_item[:setidentifier].nil?)
identifier_tag = %Q{<SetIdentifier>#{change_item[:setidentifier]}</SetIdentifier>} unless change_item[:setidentifier].nil?
weight_tag = %Q{<Weight>#{change_item[:weight]}</Weight>} unless change_item[:weight].nil?

resource_records= change_item[:resource_records]
resource_record_tags = ''
resource_records.each { |record|
resource_record_tags+= %Q{<ResourceRecord><Value>#{record}</Value></ResourceRecord>}
}
resource_tag= %Q{<ResourceRecords>#{resource_record_tags}</ResourceRecords>}

change_tags = %Q{<Change>#{action_tag}<ResourceRecordSet>#{name_tag}#{type_tag}#{ttl_tag}#{resource_tag}</ResourceRecordSet></Change>}

if (change_item[:weight].nil? and change_item[:setidentifier].nil?)
change_tags = %Q{<Change>#{action_tag}<ResourceRecordSet>#{name_tag}#{type_tag}#{ttl_tag}#{resource_tag}</ResourceRecordSet></Change>}
else
change_tags = %Q{<Change>#{action_tag}<ResourceRecordSet>#{name_tag}#{type_tag}#{identifier_tag}#{weight_tag}#{ttl_tag}#{resource_tag}</ResourceRecordSet></Change>}
end
changes+= change_tags
}

changes+= '</Changes></ChangeBatch>'
puts "@@@ SENDING @@@\n#{changes}\n\n"
end

body = %Q{<?xml version="1.0" encoding="UTF-8"?><ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2010-10-01/">#{changes}</ChangeResourceRecordSetsRequest>}
body = %Q{<?xml version="1.0" encoding="UTF-8"?><ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2011-05-05/">#{changes}</ChangeResourceRecordSetsRequest>}
request({
:body => body,
:parser => Fog::Parsers::DNS::AWS::ChangeResourceRecordSets.new,
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/requests/dns/create_hosted_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def create_hosted_zone(name, options = {})
end

request({
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2010-10-01/"><Name>#{name}</Name>#{optional_tags}</CreateHostedZoneRequest>},
:body => %Q{<?xml version="1.0" encoding="UTF-8"?><CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/2011-05-05/"><Name>#{name}</Name>#{optional_tags}</CreateHostedZoneRequest>},
:parser => Fog::Parsers::DNS::AWS::CreateHostedZone.new,
:expects => 201,
:method => 'POST',
Expand Down
28 changes: 28 additions & 0 deletions lib/fog/cloudstack/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@ class Unauthorized < Fog::Compute::Cloudstack::Error; end
request_path 'fog/cloudstack/requests/compute'

request :acquire_ip_address
request :add_vpn_user
request :assign_to_load_balancer_rule
request :attach_volume
request :authorize_security_group_ingress
request :authorize_security_group_egress
request :change_service_for_virtual_machine
request :copy_template
request :create_account
request :create_domain
request :create_egress_firewall_rule
request :create_firewall_rule
request :create_ip_forwarding_rule
request :create_load_balancer_rule
request :create_network
request :create_port_forwarding_rule
request :create_remote_access_vpn
request :create_security_group
request :create_ssh_key_pair
request :create_snapshot
Expand All @@ -35,19 +41,28 @@ class Unauthorized < Fog::Compute::Cloudstack::Error; end
request :create_volume
request :delete_account
request :delete_domain
request :delete_egress_firewall_rule
request :delete_firewall_rule
request :delete_ip_forwarding_rule
request :delete_load_balancer_rule
request :delete_port_forwarding_rule
request :delete_network
request :delete_security_group
request :delete_remote_access_vpn
request :delete_ssh_key_pair
request :delete_snapshot
request :delete_snapshot_policies
request :delete_user
request :delete_volume
request :detach_volume
request :deploy_virtual_machine
request :destroy_router
request :destroy_virtual_machine
request :disable_user
request :disable_static_nat
request :disassociate_ip_address
request :enable_user
request :enable_static_nat
request :generate_usage_records
request :get_vm_password
request :list_accounts
Expand All @@ -61,13 +76,16 @@ class Unauthorized < Fog::Compute::Cloudstack::Error; end
request :list_capacity
request :list_domains
request :list_domain_children
request :list_egress_firewall_rules
request :list_events
request :list_external_firewalls
request :list_external_load_balancers
request :list_firewall_rules
request :list_hosts
request :list_hypervisors
request :list_instance_groups
request :list_isos
request :list_ip_forwarding_rules
request :list_load_balancer_rules
request :list_load_balancer_rule_instances
request :list_network_offerings
Expand All @@ -77,7 +95,9 @@ class Unauthorized < Fog::Compute::Cloudstack::Error; end
request :list_pods
request :list_port_forwarding_rules
request :list_public_ip_addresses
request :list_remote_access_vpns
request :list_resource_limits
request :list_routers
request :list_security_groups
request :list_service_offerings
request :list_snapshots
Expand All @@ -89,20 +109,28 @@ class Unauthorized < Fog::Compute::Cloudstack::Error; end
request :list_users
request :list_virtual_machines
request :list_volumes
request :list_vpn_users
request :list_zones
request :migrate_virtual_machine
request :query_async_job_result
request :reboot_router
request :reboot_virtual_machine
request :recover_virtual_machine
request :register_ssh_key_pair
request :register_user_keys
request :remove_from_load_balancer_rule
request :remove_vpn_user
request :restart_network
request :reset_password_for_virtual_machine
request :revoke_security_group_ingress
request :revoke_security_group_egress
request :start_router
request :start_virtual_machine
request :stop_virtual_machine
request :stop_router
request :update_account
request :update_domain
request :update_network
request :update_user
request :update_resource_count
request :update_virtual_machine
Expand Down
20 changes: 20 additions & 0 deletions lib/fog/cloudstack/requests/compute/add_vpn_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Fog
module Compute
class Cloudstack
class Real

# Adds a vpn user.
#
# {CloudStack API Reference}[http://download.cloud.com/releases/2.2.0/api_2.2.14/user/addVpnUser.html]
def add_vpn_user(options={})
options.merge!(
'command' => 'addVpnUser'
)

request(options)
end

end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Fog
module Compute
class Cloudstack
class Real

# Creates an account.
#
# {CloudStack API Reference}[http://download.cloud.com/releases/2.2.0/api_2.2.4/global_admin/authorizeSecurityGroupEgress.html]
def authorize_security_group_egress(options={})
options.merge!(
'command' => 'authorizeSecurityGroupEgress'
)

request(options)
end

end
end
end
end


20 changes: 20 additions & 0 deletions lib/fog/cloudstack/requests/compute/create_egress_firewall_rule.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Fog
module Compute
class Cloudstack
class Real

# Creates a firewall rule.
#
# {CloudStack API Reference}[http://download.cloud.com/releases/2.2.0/api_2.2.4/global_admin/createEgressFirewallRule.html]
def create_egress_firewall_rule(options={})
options.merge!(
'command' => 'createEgressFirewallRule'
)

request(options)
end

end
end
end
end
20 changes: 20 additions & 0 deletions lib/fog/cloudstack/requests/compute/create_firewall_rule.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Fog
module Compute
class Cloudstack
class Real

# Creates a firewall rule.
#
# {CloudStack API Reference}[http://download.cloud.com/releases/2.2.0/api_2.2.4/global_admin/createFirewallRule.html]
def create_firewall_rule(options={})
options.merge!(
'command' => 'createFirewallRule'
)

request(options)
end

end
end
end
end
Loading