Skip to content

Commit

Permalink
Floating IPs provisioning backend
Browse files Browse the repository at this point in the history
Models: EMS Network Provider using task queue
UI to follow and integrate with tests
  • Loading branch information
gildub committed Nov 1, 2016
1 parent d7598f7 commit f53b12f
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 1 deletion.
24 changes: 23 additions & 1 deletion app/models/manageiq/providers/openstack/network_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ManageIQ::Providers::Openstack::NetworkManager < ManageIQ::Providers::Netw
include ManageIQ::Providers::Openstack::ManagerMixin
include SupportsFeatureMixin

supports :create_floating_ip
supports :create_security_group
supports :create_network_router

Expand Down Expand Up @@ -113,6 +114,27 @@ def create_network_router_queue(userid, options = {})
MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def create_floating_ip(options)
FloatingIp.raw_create_floating_ip(self, options)
end

def create_floating_ip_queue(userid, options = {})
task_opts = {
:action => "creating Floating IP for user #{userid}",
:userid => userid
}
queue_opts = {
:class_name => self.class.name,
:method_name => 'create_security_group',
:instance_id => id,
:priority => MiqQueue::HIGH_PRIORITY,
:role => 'ems_operations',
:zone => my_zone,
:args => [options]
}
MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def create_security_group(options)
SecurityGroup.raw_create_security_group(self, options)
end
Expand All @@ -124,7 +146,7 @@ def create_security_group_queue(userid, options = {})
}
queue_opts = {
:class_name => self.class.name,
:method_name => 'create_security_group',
:method_name => 'create_floating_ip',
:instance_id => id,
:priority => MiqQueue::HIGH_PRIORITY,
:role => 'ems_operations',
Expand Down
103 changes: 103 additions & 0 deletions app/models/manageiq/providers/openstack/network_manager/floating_ip.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,105 @@
class ManageIQ::Providers::Openstack::NetworkManager::FloatingIp < ::FloatingIp
include ProviderObjectMixin
include AsyncDeleteMixin
include SupportsFeatureMixin

supports :create_floating_ip
supports :delete_floating_ip
supports :update_floating_ip

def self.raw_create_floating_ip(ext_management_system, options)
cloud_tenant = options.delete(:cloud_tenant)
floating_ip = nil
floating_network_id = CloudNetwork.find(options[:cloud_network_id]).ems_ref

raw_options = remapping(options)

ext_management_system.with_provider_connection(connection_options(cloud_tenant)) do |service|
floating_ip = service.create_floating_ip(floating_network_id, raw_options)
end
{:ems_ref => floating_ip['id'], :name => options[:name]}
rescue => e
_log.error "floating_ip=[#{options[:name]}], error: #{e}"
raise MiqException::MiqFloatingIpCreateError, e.to_s, e.backtrace
end

def self.remapping(options)
new_options = options.dup
new_options[:floating_ip_address] = options[:address] if options[:address]
new_options[:tenant_id] = CloudTenant.find(options[:cloud_tenant_id]).ems_ref if options[:cloud_tenant_id]
new_options[:port_id] = options[:network_port_ems_ref] if options[:network_port_ems_ref]
new_options.delete(:address)
new_options.delete(:cloud_network_id)
new_options.delete(:network_port_ems_ref)
new_options.delete(:cloud_tenant_id)
new_options
end

def raw_delete_floating_ip
ext_management_system.with_provider_connection(connection_options(cloud_tenant)) do |service|
service.delete_floating_ip(ems_ref)
end
rescue => e
_log.error "floating_ip=[#{name}], error: #{e}"
raise MiqException::MiqFloatingIpDeleteError, e.to_s, e.backtrace
end

def delete_floating_ip_queue(userid)
task_opts = {
:action => "deleting Floating IP for user #{userid}",
:userid => userid
}
queue_opts = {
:class_name => self.class.name,
:method_name => 'raw_delete_floating_ip',
:instance_id => id,
:priority => MiqQueue::HIGH_PRIORITY,
:role => 'ems_operations',
:zone => ext_management_system.my_zone,
:args => []
}
MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def raw_update_floating_ip(options)
ext_management_system.with_provider_connection(connection_options(cloud_tenant)) do |service|
if options[:network_port_ems_ref].empty?
service.disassociate_floating_ip(ems_ref)
else
service.associate_floating_ip(ems_ref, options[:network_port_ems_ref])
end
end
rescue => e
_log.error "floating_ip=[#{name}], error: #{e}"
raise MiqException::MiqFloatingIpUpdateError, e.to_s, e.backtrace
end

def update_floating_ip_queue(userid, options = {})
task_opts = {
:action => "updating Floating IP for user #{userid}",
:userid => userid
}
queue_opts = {
:class_name => self.class.name,
:method_name => 'raw_update_floating_ip',
:instance_id => id,
:priority => MiqQueue::HIGH_PRIORITY,
:role => 'ems_operations',
:zone => ext_management_system.my_zone,
:args => [options]
}
MiqTask.generic_action_with_callback(task_opts, queue_opts)
end

def self.connection_options(cloud_tenant = nil)
connection_options = {:service => "Network"}
connection_options[:tenant_name] = cloud_tenant.name if cloud_tenant
connection_options
end

private

def connection_options(cloud_tenant = nil)
self.class.connection_options(cloud_tenant)
end
end
3 changes: 3 additions & 0 deletions app/models/mixins/supports_feature_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ module SupportsFeatureMixin
:backup_create => 'CloudVolume backup creation',
:backup_restore => 'CloudVolume backup restore',
:cinder_service => 'Cinder storage service',
:create_floating_ip => 'Floating IP Creation',
:create_host_aggregate => 'Host Aggregate Creation',
:create_network_router => 'Network Router Creation',
:create_security_group => 'Security Group Creation',
:swift_service => 'Swift storage service',
:delete => 'Deletion',
:delete_aggregate => 'Host Aggregate Deletion',
:delete_floating_ip => 'Floating IP Deletion',
:delete_network_router => 'Network Router Deletion',
:delete_security_group => 'Security Group Deletion',
:disassociate_floating_ip => 'Disassociate a Floating IP',
Expand Down Expand Up @@ -102,6 +104,7 @@ module SupportsFeatureMixin
:timeline => 'Query for events',
:update_aggregate => 'Host Aggregate Update',
:update => 'Update',
:update_floating_ip => 'Update Floating IP association',
:update_network_router => 'Network Router Update',
:ems_network_new => 'New EMS Network Provider',
:update_security_group => 'Security Group Update',
Expand Down
5 changes: 5 additions & 0 deletions gems/pending/util/miq-exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ class MiqOrchestrationUpdateError < Error; end
class MiqOrchestrationDeleteError < Error; end
class MiqOrchestrationStackNotExistError < Error; end

class MiqFloatingIpValidationError < Error; end
class MiqFloatingIpCreateError < Error; end
class MiqFloatingIpUpdateError < Error; end
class MiqFloatingIpDeleteError < Error; end

class MiqLoadBalancerProvisionError < Error; end
class MiqLoadBalancerStatusError < Error; end
class MiqLoadBalancerValidationError < Error; end
Expand Down

0 comments on commit f53b12f

Please sign in to comment.