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