KnifeCommands.role_name method
This commit is contained in:
parent
90d0630ca2
commit
94b483b209
@ -32,12 +32,12 @@ class KnifeCommands
|
||||
knife("tag delete #{name} #{tagsStr}")
|
||||
end
|
||||
|
||||
def self.create_role project, env
|
||||
def self.create_role role_name, project, env
|
||||
file = "/tmp/new_role.json"
|
||||
File.open(file, "w") do |f|
|
||||
f.puts <<-EOH
|
||||
{
|
||||
"name" : "#{project}_#{env}",
|
||||
"name" : "#{role_name}",
|
||||
"description": "",
|
||||
"json_class": "Chef::Role",
|
||||
"default_attributes": {
|
||||
@ -52,7 +52,7 @@ class KnifeCommands
|
||||
EOH
|
||||
end
|
||||
out = `knife role from file #{file}`
|
||||
raise "Cannot create role '#{project}_#{env}': #{out}" unless $?.success?
|
||||
raise "Cannot create role '#{role_name}': #{out}" unless $?.success?
|
||||
true
|
||||
end
|
||||
|
||||
@ -61,6 +61,10 @@ EOH
|
||||
return (s ? JSON.parse(o) : nil)
|
||||
end
|
||||
|
||||
def self.role_name project_name, deploy_env
|
||||
project_name + (DevopsService.config[:role_separator] || "_") + deploy_env
|
||||
end
|
||||
|
||||
def self.knife cmd
|
||||
o = `knife #{cmd} 2>&1`
|
||||
return o, $?.success?
|
||||
|
||||
@ -539,12 +539,12 @@ module Version2_0
|
||||
return "Can't get roles list" if all_roles.nil?
|
||||
roles = {:new => [], :error => [], :exist => []}
|
||||
envs.each do |e|
|
||||
role_name = project_id + (DevopsService.config[:role_separator] || "_") + e.identifier
|
||||
role_name = KnifeCommands.role_name(project_id, e.identifier)
|
||||
begin
|
||||
if all_roles.include? role_name
|
||||
roles[:exist].push role_name
|
||||
else
|
||||
KnifeCommands.create_role project_id, e.identifier
|
||||
KnifeCommands.create_role role_name, project_id, e.identifier
|
||||
roles[:new].push role_name
|
||||
logger.info "Role '#{role_name}' created"
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user