mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
add network offerings model and add functionality to egress_firewall_rule model
This commit is contained in:
parent
7a1a43fb6b
commit
09ac1f9005
8 changed files with 126 additions and 17 deletions
|
@ -31,6 +31,8 @@ module Fog
|
|||
collection :jobs
|
||||
model :network
|
||||
collection :networks
|
||||
model :network_offering
|
||||
collection :network_offerings
|
||||
model :public_ip_address
|
||||
collection :public_ip_addresses
|
||||
model :port_forwarding_rule
|
||||
|
|
|
@ -8,6 +8,30 @@ module Fog
|
|||
attribute :state, :aliases => 'state'
|
||||
attribute :cidr_list, :aliases => 'cidrlist'
|
||||
attribute :tags, :type => :array
|
||||
attribute :job_id, :aliases => 'jobid' # only on create
|
||||
|
||||
def save
|
||||
requires :protocol, :network_id
|
||||
|
||||
options = {
|
||||
'protocol' => protocol,
|
||||
'networkid' => network_id,
|
||||
'cidrlist' => cidr_list,
|
||||
}
|
||||
|
||||
response = service.create_egress_firewall_rule(options)
|
||||
merge_attributes(response['createegressfirewallruleresponse'])
|
||||
end
|
||||
|
||||
def destroy
|
||||
requires :id
|
||||
|
||||
response = service.delete_egress_firewall_rule('id' => id )
|
||||
success_status = response['deleteegressfirewallruleresponse']['success']
|
||||
|
||||
success_status == 'true'
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,7 +30,7 @@ module Fog
|
|||
attribute :domain_id, :aliases => 'domainid'
|
||||
attribute :domain, :aliases => 'domain'
|
||||
|
||||
attribute :service, :aliases => 'service'
|
||||
# attribute :service, :aliases => 'service'
|
||||
attribute :network_domain, :aliases => 'domain'
|
||||
attribute :physical_network_id, :aliases => 'physicalnetworkid'
|
||||
attribute :restart_required, :aliases => 'restartrequired'
|
||||
|
@ -39,22 +39,31 @@ module Fog
|
|||
attribute :is_persistent, :aliases => 'ispersistent', :type => :boolean
|
||||
attribute :display_network, :aliases => 'displaynetwork'
|
||||
|
||||
def restart
|
||||
# AN - need to test
|
||||
response = @connection.restart_network( self.id)
|
||||
# there are a bunch of fields
|
||||
# should be mapped back to attributes
|
||||
# restart network - will return a job
|
||||
def restart(options={})
|
||||
response = service.restart_network( options.merge({'id'=> self.id}))
|
||||
service.jobs.new(response['restartnetworkresponse'])
|
||||
end
|
||||
|
||||
# create a new network
|
||||
def save
|
||||
raise Fog::Errors::Error.new('Creating a network is not supported')
|
||||
requires :display_text, :name, :network_offering_id, :zone_id
|
||||
|
||||
options = {
|
||||
'displaytext' => display_text,
|
||||
'name' => name,
|
||||
'zoneid' => zone_id,
|
||||
'networkofferingid' => network_offering_id
|
||||
}
|
||||
|
||||
response = service.create_network(options)
|
||||
merge_attributes(response['createnetworkresponse']['network'])
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise Fog::Errors::Error.new('Destroying a network is not supported')
|
||||
|
||||
# response = @connection.delete_network( {'id' => @self.id })
|
||||
# returns success & displaytext
|
||||
# delete given network - will return a job
|
||||
def destroy(options={})
|
||||
response = service.delete_network(options.merge({'id'=> self.id}))
|
||||
service.jobs.new(response["deletenetworkresponse"])
|
||||
end
|
||||
|
||||
end # Network
|
||||
|
|
25
lib/fog/cloudstack/models/compute/network_offering.rb
Normal file
25
lib/fog/cloudstack/models/compute/network_offering.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class NetworkOffering < Fog::Model
|
||||
identity :id, :aliases => 'id'
|
||||
attribute :name, :aliases => 'name'
|
||||
attribute :display_text, :aliases => 'displaytext'
|
||||
attribute :traffic_type, :aliases => 'traffictype'
|
||||
attribute :is_default, :aliases => 'isdefault', :type => :boolean
|
||||
attribute :specify_vlan, :aliases => 'specifyvlan'
|
||||
attribute :conserve_mode, :aliases => 'conservemode'
|
||||
attribute :specify_ip_ranges, :aliases => 'specifyipranges'
|
||||
attribute :availability, :aliases => 'availability'
|
||||
attribute :network_rate, :aliases => 'networkrate'
|
||||
attribute :state, :aliases => 'state'
|
||||
attribute :guest_ip_type, :aliases => 'guestiptype'
|
||||
attribute :service_offering_id, :aliases => 'serviceofferingid'
|
||||
attribute :service, :aliases => 'service'
|
||||
attribute :for_vpc, :aliases => 'forvpc'
|
||||
attribute :is_persistent, :aliases => 'ispersistent', :type => :boolean
|
||||
attribute :egress_default_policy, :aliases => 'egressdefaultpolicy'
|
||||
end # NetworkOffering
|
||||
end # Cloudstack
|
||||
end # Compute
|
||||
end # Fog
|
39
lib/fog/cloudstack/models/compute/network_offerings.rb
Normal file
39
lib/fog/cloudstack/models/compute/network_offerings.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
|
||||
require 'fog/core/collection'
|
||||
require 'fog/cloudstack/models/compute/network_offering'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Cloudstack
|
||||
class NetworkOfferings < Fog::Collection
|
||||
model Fog::Compute::Cloudstack::NetworkOffering
|
||||
|
||||
def all(filters={})
|
||||
options = get_filter_options(filters)
|
||||
data = service.list_network_offerings(options)["listnetworkofferingsresponse"]["networkoffering"] || []
|
||||
load(data)
|
||||
end
|
||||
|
||||
def get(network_offering_id, filters={})
|
||||
filter_option = get_filter_options(filters)
|
||||
options = filter_option.merge('id' => network_offering_id)
|
||||
if data = service.list_network_offerings(options)["listnetworkofferingsresponse"]["networkoffering"].first
|
||||
new(data)
|
||||
end
|
||||
rescue Fog::Compute::Cloudstack::BadRequest
|
||||
nil
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_filter_options(filters)
|
||||
default_filter = {
|
||||
'projectfilter' => 'self'
|
||||
}
|
||||
default_filter.merge(filters)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
|
||||
require 'fog/core/collection'
|
||||
require 'fog/cloudstack/models/compute/network'
|
||||
|
||||
|
|
|
@ -3,23 +3,33 @@ module Fog
|
|||
class Cloudstack
|
||||
|
||||
class Real
|
||||
# Creates a egress firewall rule for a given network
|
||||
# Creates a egress firewall rule for a given network
|
||||
#
|
||||
# {CloudStack API Reference}[http://cloudstack.apache.org/docs/api/apidocs-4.4/root_admin/createEgressFirewallRule.html]
|
||||
def create_egress_firewall_rule(*args)
|
||||
options = {}
|
||||
if args[0].is_a? Hash
|
||||
options = args[0]
|
||||
options.merge!('command' => 'createEgressFirewallRule')
|
||||
options.merge!('command' => 'createEgressFirewallRule')
|
||||
else
|
||||
options.merge!('command' => 'createEgressFirewallRule',
|
||||
'networkid' => args[0],
|
||||
options.merge!('command' => 'createEgressFirewallRule',
|
||||
'networkid' => args[0],
|
||||
'protocol' => args[1])
|
||||
end
|
||||
request(options)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_egress_firewall_rule(*args)
|
||||
egress_firewall_rule_id = Fog::Cloudstack.uuid
|
||||
|
||||
egress_firewall_rule = {}
|
||||
|
||||
{'createegressfirewallruleresponse' => egress_firewall_rule}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -55,6 +55,7 @@ def compute_providers
|
|||
:protocol => 'tcp'
|
||||
},
|
||||
:disk_offering_attributes => { :name => "new disk offering", :display_text => 'New Disk Offering' },
|
||||
:egress_firewall_rule_attributes => {:network_id => '89198f7c-0245-aa1d-136a-c5f479ef9db7', :protocol => 'tcp'},
|
||||
:mocked => true
|
||||
},
|
||||
:glesys => {
|
||||
|
|
Loading…
Add table
Reference in a new issue