Skip to content

Commit

Permalink
support purging for all types of resources
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxFedotov committed Nov 13, 2018
1 parent 41677ea commit e579214
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def create
end

def destroy
writer_hostgroup = @resource.value(:writer_hostgroup)
backup_writer_hostgroup = @resource.value(:backup_writer_hostgroup)
reader_hostgroup = @resource.value(:reader_hostgroup)
offline_hostgroup = @resource.value(:offline_hostgroup)
writer_hostgroup = @property_hash[:writer_hostgroup]
backup_writer_hostgroup = @property_hash[:backup_writer_hostgroup]
reader_hostgroup = @property_hash[:reader_hostgroup]
offline_hostgroup = @property_hash[:offline_hostgroup]
query = 'DELETE FROM `mysql_group_replication_hostgroups`'
query << " WHERE `writer_hostgroup` = #{writer_hostgroup} AND `backup_writer_hostgroup` = #{backup_writer_hostgroup} AND `reader_hostgroup` = #{reader_hostgroup} AND `offline_hostgroup` = #{offline_hostgroup}"
mysql([defaults_file, '-e', query].compact)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/proxy_mysql_query_rule/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def create
end

def destroy
rule_id = @resource.value(:rule_id)
rule_id = @property_hash[:rule_id]
mysql([defaults_file, '-e', "DELETE FROM `mysql_query_rules` WHERE `rule_id` = '#{rule_id}'"].compact)

@property_hash.clear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def create
end

def destroy
writer_hostgroup = @resource.value(:writer_hostgroup)
reader_hostgroup = @resource.value(:reader_hostgroup)
writer_hostgroup = @property_hash[:writer_hostgroup]
reader_hostgroup = @property_hash[:reader_hostgroup]
query = 'DELETE FROM `mysql_replication_hostgroups`'
query << " WHERE `writer_hostgroup` = #{writer_hostgroup} AND `reader_hostgroup` = #{reader_hostgroup}"
mysql([defaults_file, '-e', query].compact)
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/provider/proxy_mysql_server/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def create
end

def destroy
hostname = @resource.value(:hostname)
port = @resource.value(:port)
hostgroup_id = @resource.value(:hostgroup_id)
hostname = @property_hash[:hostname]
port = @property_hash[:port]
hostgroup_id = @property_hash[:hostgroup_id]
query = 'DELETE FROM `mysql_servers`'
query << " WHERE `hostname` = '#{hostname}' AND `port` = #{port} AND `hostgroup_id` = '#{hostgroup_id}'"
mysql([defaults_file, '-e', query].compact)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def create
end

def destroy
hostname = @resource.value(:hostname)
port = @resource.value(:port)
hostname = @property_hash[:hostname]
port = @property_hash[:port]

query = 'DELETE FROM `mysql_servers`'
query << " WHERE `hostname` = '#{hostname}' AND `port` = #{port}"
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/proxy_mysql_user/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def create
end

def destroy
name = @resource[:name]
name = @property_hash[:name]
mysql([defaults_file, '-e', "DELETE FROM mysql_users WHERE username = '#{name}'"].compact)

@property_hash.clear
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/proxy_scheduler/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def create
end

def destroy
scheduler_id = @resource.value(:scheduler_id)
scheduler_id = @property_hash[:scheduler_id]

mysql([defaults_file, '-e', "DELETE FROM `scheduler` WHERE `id` = #{scheduler_id}"].compact)

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_group_replication_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
raise('backup_writer_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:backup_writer_hostgroup].nil?
raise('reader_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:reader_hostgroup].nil?
raise('offline_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:offline_hostgroup].nil?
raise('name must match writer_hostgroup-backup_writer_hostgroup-reader_hostgroup-offline_hostgroup parameters') if self[:name] != "#{self[:writer_hostgroup]}-#{self[:backup_writer_hostgroup]}-#{self[:reader_hostgroup]}-#{self[:offline_hostgroup]}"
raise('name must match writer_hostgroup-backup_writer_hostgroup-reader_hostgroup-offline_hostgroup parameters') if (self[:ensure] == :present) && self[:name] != "#{self[:writer_hostgroup]}-#{self[:backup_writer_hostgroup]}-#{self[:reader_hostgroup]}-#{self[:offline_hostgroup]}"
end

newparam(:name, namevar: true) do
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/proxy_mysql_query_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
autorequire(:service) { 'proxysql' }

validate do
raise('rule_id parameter is required.') if self[:rule_id].nil?
raise('name must match \'mysql_query_rule-\'<rule_id> format') if self[:name] != "mysql_query_rule-#{self[:rule_id]}"
raise('rule_id parameter is required.') if (self[:ensure] == :present) && self[:rule_id].nil?
raise('name must match \'mysql_query_rule-\'<rule_id> format') if (self[:ensure] == :present) && self[:name] != "mysql_query_rule-#{self[:rule_id]}"
end

newparam(:name, namevar: true) do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_replication_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
validate do
raise('writer_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:writer_hostgroup].nil?
raise('reader_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:reader_hostgroup].nil?
raise('name must match writer_hostgroup-reader_hostgroup parameters') if self[:name] != "#{self[:writer_hostgroup]}-#{self[:reader_hostgroup]}"
raise('name must match writer_hostgroup-reader_hostgroup parameters') if (self[:ensure] == :present) && self[:name] != "#{self[:writer_hostgroup]}-#{self[:reader_hostgroup]}"
end

newparam(:name, namevar: true) do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
raise('hostname parameter is required.') if (self[:ensure] == :present) && self[:hostname].nil?
raise('port parameter is required.') if (self[:ensure] == :present) && self[:port].nil?
raise('hostgroup_id parameter is required.') if (self[:ensure] == :present) && self[:hostgroup_id].nil?
raise('name must match hostname, port and hostgroup_id parameters') if self[:name] != "#{self[:hostname]}:#{self[:port]}-#{self[:hostgroup_id]}"
raise('name must match hostname, port and hostgroup_id parameters') if (self[:ensure] == :present) && self[:name] != "#{self[:hostname]}:#{self[:port]}-#{self[:hostgroup_id]}"
end

newparam(:name, namevar: true) do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_server_no_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
raise('hostname parameter is required.') if (self[:ensure] == :present) && self[:hostname].nil?
raise('port parameter is required.') if (self[:ensure] == :present) && self[:port].nil?
raise('hostgroup_id parameter is required.') if (self[:ensure] == :present) && self[:hostgroup_id].nil?
raise('name must match hostname and port') if self[:name] != "#{self[:hostname]}:#{self[:port]}"
raise('name must match hostname and port') if (self[:ensure] == :present) && self[:name] != "#{self[:hostname]}:#{self[:port]}"
end

newparam(:name, namevar: true) do
Expand Down
4 changes: 1 addition & 3 deletions lib/puppet/type/proxy_mysql_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def initialize(*args)
super

return if self[:ensure] != :present
self[:password] = '*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(self[:password])).upcase unless self[:password].start_with?('*') || self[:encrypt_password] != :true
end

Expand Down Expand Up @@ -80,13 +80,11 @@ def initialize(*args)

newproperty(:backend) do
desc 'Backend or not.'
defaultto 1
newvalue(%r{[01]})
end

newproperty(:frontend) do
desc 'Frontend or not.'
defaultto 1
newvalue(%r{[01]})
end

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/proxy_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
autorequire(:service) { 'proxysql' }

validate do
raise('scheduler_id parameter is required.') if self[:scheduler_id].nil?
raise('scheduler_id parameter is required.') if (self[:ensure] == :present) && self[:scheduler_id].nil?
raise('filename parameter is required.') if (self[:ensure] == :present) && self[:filename].nil?
raise('name must match \'scheduler-\'<scheduler_id> format') if self[:name] != "scheduler-#{self[:scheduler_id]}"
raise('name must match \'scheduler-\'<scheduler_id> format') if (self[:ensure] == :present) && self[:name] != "scheduler-#{self[:scheduler_id]}"
end

newparam(:name, namevar: true) do
Expand Down

0 comments on commit e579214

Please sign in to comment.