42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/chef/knife/cosmic_template_extract.rb', line 42
def run
validate_base_options
Chef::Log.debug("Validate template name")
if locate_config_value(:name)
templatename = locate_config_value(:name)
else
templatename = @name_args.first
unless /^[a-zA-Z0-9][a-zA-Z0-9_\-# ]*$/.match templatename then
ui.error "Invalid templatename."
exit 1
end
end
zonename = locate_config_value(:zone)
if ! zonename
then
ui.error "No zone specified"
exit 1
end
print "#{ui.color("Extracting template: #{templatename}", :magenta)}\n"
Chef::Log.debug("Getting zone")
zone = connection.get_zone(
zonename,
)
if ! zone then
ui.error "Zone #{zonename} not found"
exit 1
end
Chef::Log.debug("Getting template")
template = connection.get_template(
templatename,
)
if ! template then
ui.error "Template #{templatename} not found"
exit 1
end
Chef::Log.debug("Extracting template")
params = {
'command' => 'extractTemplate',
'id' => template["id"],
'mode' => "HTTP_DOWNLOAD",
'zoneid' => zone["id"]
}
json = connection.send_async_request(params)
if json then
url = json["template"]["url"]
print "\n#{url}\n"
else
ui.error "Template extraction failed.\n"
exit 1
end
end
|