-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlibvirt_flavor.rb
96 lines (82 loc) · 2.6 KB
/
libvirt_flavor.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
class Chef
class Knife
class LibvirtFlavorList < Knife
deps do
require 'chef/knife/bootstrap'
Chef::Knife::Bootstrap.load_deps
require 'chef/data_bag'
end
banner "knife libvirt flavor list (options)"
def run
Chef::DataBag.load("libvirt_flavors").each do |name,uri|
puts " #{name}"
end
end
end
class LibvirtFlavorShow < Knife
deps do
require 'chef/knife/bootstrap'
Chef::Knife::Bootstrap.load_deps
require 'chef/data_bag'
end
banner "knife libvirt flavor show FLAVOR (options)"
def run
@name_args.each do |flavor_name|
output(format_for_display(Chef::DataBagItem.load("libvirt_flavors", flavor_name).raw_data))
puts
end
end
end
class LibvirtFlavorEdit < Knife
deps do
require 'chef/knife/bootstrap'
Chef::Knife::Bootstrap.load_deps
require 'chef/data_bag_item'
end
banner "knife libvirt flavor edit FLAVOR (options)"
def run
flavor = @name_args.first
item = Chef::DataBagItem.load('libvirt_flavors', flavor)
output = edit_data(item)
rest.put_rest("data/libvirt_flavors/#{flavor}", output)
stdout.puts("Saved data_bag_item[#{flavor}]")
output(format_for_display(object.raw_data)) if config[:print_after]
end
end
class LibvirtFlavorFromFile < Knife
deps do
require 'chef/knife/bootstrap'
require 'chef/knife/core/object_loader'
Chef::Knife::Bootstrap.load_deps
end
banner "knife libvirt flavor from file FILE (options)"
def loader
@loader ||= Knife::Core::ObjectLoader.new(DataBagItem, ui)
end
def create_dbag
begin
rest.post_rest("data", { "name" => "libvirt_flavors" })
rescue Net::HTTPServerException => e
puts "Data bag #{@data_bag_name} already exists"
end
end
def run
file = @name_args.first
item = loader.load_from("data_bags", "libvirt_flavors", file)
dbag = Chef::DataBagItem.new
dbag.data_bag("libvirt_flavors")
dbag.raw_data = item # item is json
begin
dbag.save
rescue
create_dbag
puts "Creating data bag for libvirt flavors"
dbag.save
end
puts "Updated flavor '#{dbag.id}'"
# modify json file into what chef expects with all the defaults we want
# call the chef methods that save the data bag.
end
end
end
end