Do not manage network, subnet, router resources if prefetch fails
If prefetch of neutron_network, neutron_subnet, or neutron_router resources fails (because of Neutron API timeouts or failures, for example) then the provider will believe the resources don't exist and will attempt to create them. This can cause duplicate resources in Neutron. This patch records when the prefetch fails, and if so, shunts any of the resource management methods to fail(). Change-Id: I612847bfd23ac735583ab228d8a9396f52f0ef14 Closes-bug: 1532284
This commit is contained in:
parent
023292b59c
commit
1d354007be
@ -19,8 +19,17 @@ Puppet::Type.type(:neutron_network).provide(
|
||||
'net'
|
||||
end
|
||||
|
||||
def self.do_not_manage
|
||||
@do_not_manage
|
||||
end
|
||||
|
||||
def self.do_not_manage=(value)
|
||||
@do_not_manage = value
|
||||
end
|
||||
|
||||
def self.instances
|
||||
list_neutron_resources(neutron_type).collect do |id|
|
||||
self.do_not_manage = true
|
||||
list = list_neutron_resources(neutron_type).collect do |id|
|
||||
attrs = get_neutron_resource_attrs(neutron_type, id)
|
||||
new(
|
||||
:ensure => :present,
|
||||
@ -35,6 +44,8 @@ Puppet::Type.type(:neutron_network).provide(
|
||||
:tenant_id => attrs['tenant_id']
|
||||
)
|
||||
end
|
||||
self.do_not_manage = false
|
||||
list
|
||||
end
|
||||
|
||||
def self.prefetch(resources)
|
||||
@ -51,6 +62,10 @@ Puppet::Type.type(:neutron_network).provide(
|
||||
end
|
||||
|
||||
def create
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_network[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
|
||||
network_opts = Array.new
|
||||
|
||||
if @resource[:shared] =~ /true/i
|
||||
@ -107,19 +122,31 @@ Puppet::Type.type(:neutron_network).provide(
|
||||
end
|
||||
|
||||
def destroy
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_network[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
auth_neutron('net-delete', name)
|
||||
@property_hash[:ensure] = :absent
|
||||
end
|
||||
|
||||
def admin_state_up=(value)
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_network[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
auth_neutron('net-update', "--admin_state_up=#{value}", name)
|
||||
end
|
||||
|
||||
def shared=(value)
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_network[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
auth_neutron('net-update', "--shared=#{value}", name)
|
||||
end
|
||||
|
||||
def router_external=(value)
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_network[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
if value == 'False'
|
||||
auth_neutron('net-update', "--router:external=#{value}", name)
|
||||
else
|
||||
|
@ -15,8 +15,17 @@ Puppet::Type.type(:neutron_router).provide(
|
||||
|
||||
mk_resource_methods
|
||||
|
||||
def self.do_not_manage
|
||||
@do_not_manage
|
||||
end
|
||||
|
||||
def self.do_not_manage=(value)
|
||||
@do_not_manage = value
|
||||
end
|
||||
|
||||
def self.instances
|
||||
list_neutron_resources('router').collect do |id|
|
||||
self.do_not_manage = true
|
||||
list = list_neutron_resources('router').collect do |id|
|
||||
attrs = get_neutron_resource_attrs('router', id)
|
||||
new(
|
||||
:ensure => :present,
|
||||
@ -30,6 +39,8 @@ Puppet::Type.type(:neutron_router).provide(
|
||||
:tenant_id => attrs['tenant_id']
|
||||
)
|
||||
end
|
||||
self.do_not_manage = false
|
||||
list
|
||||
end
|
||||
|
||||
def self.prefetch(resources)
|
||||
@ -46,6 +57,10 @@ Puppet::Type.type(:neutron_router).provide(
|
||||
end
|
||||
|
||||
def create
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
|
||||
opts = Array.new
|
||||
|
||||
if @resource[:admin_state_up] == 'False'
|
||||
@ -105,6 +120,9 @@ EOT
|
||||
end
|
||||
|
||||
def destroy
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
auth_neutron('router-delete', name)
|
||||
@property_hash[:ensure] = :absent
|
||||
end
|
||||
@ -121,6 +139,9 @@ EOT
|
||||
end
|
||||
|
||||
def gateway_network_name=(value)
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
if value == ''
|
||||
auth_neutron('router-gateway-clear', name)
|
||||
else
|
||||
@ -142,6 +163,9 @@ EOT
|
||||
end
|
||||
|
||||
def admin_state_up=(value)
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
set_admin_state_up(value)
|
||||
end
|
||||
|
||||
@ -150,6 +174,9 @@ EOT
|
||||
end
|
||||
|
||||
def distributed=(value)
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
results = auth_neutron("router-show", '--format=shell', resource[:name])
|
||||
attrs = self.class.parse_creation_output(results)
|
||||
set_admin_state_up(false)
|
||||
@ -160,6 +187,9 @@ EOT
|
||||
end
|
||||
|
||||
def ha=(value)
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_router[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
results = auth_neutron("router-show", '--format=shell', resource[:name])
|
||||
attrs = self.class.parse_creation_output(results)
|
||||
set_admin_state_up(false)
|
||||
|
@ -20,8 +20,17 @@ Puppet::Type.type(:neutron_subnet).provide(
|
||||
'subnet'
|
||||
end
|
||||
|
||||
def self.do_not_manage
|
||||
@do_not_manage
|
||||
end
|
||||
|
||||
def self.do_not_manage=(value)
|
||||
@do_not_manage = value
|
||||
end
|
||||
|
||||
def self.instances
|
||||
list_neutron_resources(neutron_type).collect do |id|
|
||||
self.do_not_manage = true
|
||||
list = list_neutron_resources(neutron_type).collect do |id|
|
||||
attrs = get_neutron_resource_attrs(neutron_type, id)
|
||||
new(
|
||||
:ensure => :present,
|
||||
@ -38,6 +47,8 @@ Puppet::Type.type(:neutron_subnet).provide(
|
||||
:tenant_id => attrs['tenant_id']
|
||||
)
|
||||
end
|
||||
self.do_not_manage = false
|
||||
list
|
||||
end
|
||||
|
||||
def self.prefetch(resources)
|
||||
@ -88,6 +99,10 @@ Puppet::Type.type(:neutron_subnet).provide(
|
||||
end
|
||||
|
||||
def create
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
|
||||
opts = ["--name=#{@resource[:name]}"]
|
||||
|
||||
if @resource[:ip_version]
|
||||
@ -165,11 +180,17 @@ Puppet::Type.type(:neutron_subnet).provide(
|
||||
end
|
||||
|
||||
def destroy
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
auth_neutron('subnet-delete', name)
|
||||
@property_hash[:ensure] = :absent
|
||||
end
|
||||
|
||||
def gateway_ip=(value)
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
if value == ''
|
||||
auth_neutron('subnet-update', '--no-gateway', name)
|
||||
else
|
||||
@ -178,6 +199,9 @@ Puppet::Type.type(:neutron_subnet).provide(
|
||||
end
|
||||
|
||||
def enable_dhcp=(value)
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
if value == 'False'
|
||||
auth_neutron('subnet-update', "--disable-dhcp", name)
|
||||
else
|
||||
@ -186,6 +210,9 @@ Puppet::Type.type(:neutron_subnet).provide(
|
||||
end
|
||||
|
||||
def dns_nameservers=(values)
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
unless values.empty?
|
||||
opts = ["#{name}", "--dns-nameservers", "list=true"]
|
||||
for value in values
|
||||
@ -196,6 +223,9 @@ Puppet::Type.type(:neutron_subnet).provide(
|
||||
end
|
||||
|
||||
def host_routes=(values)
|
||||
if self.class.do_not_manage
|
||||
fail("Not managing Neutron_subnet[#{@resource[:name]}] due to earlier Neutron API failures.")
|
||||
end
|
||||
unless values.empty?
|
||||
opts = ["#{name}", "--host-routes", "type=dict", "list=true"]
|
||||
for value in values
|
||||
|
Loading…
Reference in New Issue
Block a user