foreman_packages 1.0.10 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/assets/javascripts/application.js +14 -0
- data/app/assets/javascripts/jquery.fileupload.js +904 -0
- data/app/controllers/foreman_packages/syattachments_controller.rb +93 -0
- data/app/controllers/foreman_packages/sypackagemodels_controller.rb +90 -0
- data/app/controllers/foreman_packages/sypackages_controller.rb +16 -13
- data/app/models/foreman_packages/syattachment.rb +10 -0
- data/app/models/foreman_packages/sypackage.rb +69 -72
- data/app/models/foreman_packages/sypackagemodel.rb +83 -0
- data/app/uploaders/foreman_packages/avatar_uploader.rb +16 -0
- data/app/views/foreman_packages/syattachments/_form.html.erb +19 -0
- data/app/views/foreman_packages/syattachments/_syattachment.html.erb +3 -0
- data/app/views/foreman_packages/syattachments/_syattachment_td.html.erb +9 -0
- data/app/views/foreman_packages/syattachments/edit.html.erb +1 -0
- data/app/views/foreman_packages/syattachments/index.html.erb +22 -0
- data/app/views/foreman_packages/syattachments/new.html.erb +1 -0
- data/app/views/foreman_packages/syattachments/show.html.erb +30 -0
- data/app/views/foreman_packages/sypackagemodels/_form.html.erb +24 -0
- data/app/views/foreman_packages/sypackagemodels/_list.html.erb +41 -0
- data/app/views/foreman_packages/sypackagemodels/edit.html.erb +1 -0
- data/app/views/foreman_packages/sypackagemodels/index.html.erb +5 -0
- data/app/views/foreman_packages/sypackagemodels/new.html.erb +1 -0
- data/app/views/foreman_packages/sypackagemodels/show.html.erb +118 -0
- data/app/views/foreman_packages/sypackages/_form.html.erb +82 -87
- data/app/views/foreman_packages/sypackages/_sypackage.html.erb +3 -0
- data/app/views/foreman_packages/sypackages/_sypackage_td.html.erb +19 -0
- data/app/views/foreman_packages/sypackages/create.js.erb +2 -0
- data/app/views/foreman_packages/sypackages/destroy.js.erb +1 -0
- data/app/views/foreman_packages/sypackages/edit.js.erb +3 -0
- data/app/views/foreman_packages/sypackages/new.js.erb +3 -0
- data/app/views/foreman_packages/sypackages/show.html.erb +1 -1
- data/app/views/foreman_packages/sypackages/update.js.erb +3 -0
- data/config/routes.rb +3 -9
- data/db/migrate/20150921011935_create_sypackages.rb +1 -0
- data/db/migrate/20150921023709_add_filename_to_sypackage.rb +1 -1
- data/db/migrate/20150921050518_add_file_cache_to_sypackage.rb +1 -1
- data/db/migrate/20150921050519_create_sypackagemodels.rb +11 -0
- data/db/migrate/20150921050522_change_filename_to_sypackage.rb +8 -0
- data/db/migrate/20150921050530_create_syattachments.rb +11 -0
- data/lib/foreman_packages/engine.rb +14 -18
- data/lib/foreman_packages/version.rb +1 -1
- metadata +32 -5
- data/app/uploaders/attachment_uploader.rb +0 -15
- data/app/uploaders/avatar_uploader.rb +0 -57
- data/app/views/foreman_packages/sypackages/upload.html.erb +0 -4
@@ -0,0 +1,93 @@
|
|
1
|
+
class ForemanPackages::SyattachmentsController < ApplicationController
|
2
|
+
# GET /syattachments
|
3
|
+
# GET /syattachments.json
|
4
|
+
def index
|
5
|
+
@syattachments = ForemanPackages::Syattachment.all
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.json { render json: @syattachments }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /syattachments/1
|
14
|
+
# GET /syattachments/1.json
|
15
|
+
def show
|
16
|
+
@syattachment = ForemanPackages::Syattachment.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.erb
|
20
|
+
format.json { render json: @syattachment }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /syattachments/new
|
25
|
+
# GET /syattachments/new.json
|
26
|
+
def new
|
27
|
+
#packagemodel = ForemanPackages::Sypackagemodel.find(params[:sypackagemodel_id])
|
28
|
+
#@syattachment = attachmentmodel.syattachments.new
|
29
|
+
#
|
30
|
+
packagemodel = ForemanPackages::Sypackagemodel.find(params[:sypackagemodel_id])
|
31
|
+
@syattachment = packagemodel.syattachments.new
|
32
|
+
respond_to do |format|
|
33
|
+
format.html # new.html.erb
|
34
|
+
format.json { render json: @syattachment }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# GET /syattachments/1/edit
|
39
|
+
def edit
|
40
|
+
@syattachment = ForemanPackages::Syattachment.find(params[:id])
|
41
|
+
end
|
42
|
+
|
43
|
+
# POST /syattachments
|
44
|
+
# POST /syattachments.json
|
45
|
+
def create
|
46
|
+
@syattachment = ForemanPackages::Syattachment.new(params[:foreman_packages_syattachment])
|
47
|
+
|
48
|
+
if params[:foreman_packages_syattachment][:link].present?
|
49
|
+
@syattachment.filename = params[:foreman_packages_syattachment][:link].original_filename
|
50
|
+
end
|
51
|
+
respond_to do |format|
|
52
|
+
if @syattachment.save
|
53
|
+
#format.html { redirect_to @syattachment, notice: 'Sypackagemodel was successfully created.' }
|
54
|
+
#format.json { render json: @syattachment, status: :created, location: @syattachment }
|
55
|
+
format.html { redirect_to @syattachment.foreman_packages_sypackagemodel }
|
56
|
+
format.json { head :no_content }
|
57
|
+
else
|
58
|
+
format.html { render action: "new" }
|
59
|
+
format.json { render json: @syattachment.errors, status: :unprocessable_entity }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# PUT /syattachments/1
|
65
|
+
# PUT /syattachments/1.json
|
66
|
+
def update
|
67
|
+
@syattachment = ForemanPackages::Syattachment.find(params[:id])
|
68
|
+
if params[:foreman_packages_syattachment][:link].present?
|
69
|
+
@syattachment.filename = params[:foreman_packages_syattachment][:link].original_filename
|
70
|
+
end
|
71
|
+
respond_to do |format|
|
72
|
+
if @syattachment.update_attributes(params[:foreman_packages_syattachment])
|
73
|
+
format.html { redirect_to @syattachment, notice: 'syattachment was successfully updated.' }
|
74
|
+
format.json { head :no_content }
|
75
|
+
else
|
76
|
+
format.html { render action: "edit" }
|
77
|
+
format.json { render json: @syattachment.errors, status: :unprocessable_entity }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# DELETE /syattachments/1
|
83
|
+
# DELETE /syattachments/1.json
|
84
|
+
def destroy
|
85
|
+
@syattachment = ForemanPackages::Syattachment.find(params[:id])
|
86
|
+
@syattachment.destroy
|
87
|
+
|
88
|
+
respond_to do |format|
|
89
|
+
format.html { redirect_to foreman_packages_syattachments_url }
|
90
|
+
format.json { head :no_content }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
class ForemanPackages::SypackagemodelsController < ApplicationController
|
2
|
+
# GET /sypackagemodels
|
3
|
+
# GET /sypackagemodels.json
|
4
|
+
def index
|
5
|
+
@sypackagemodels = ForemanPackages::Sypackagemodel.all.paginate(:page => params[:page])
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.erb
|
9
|
+
format.json { render json: @sypackagemodels }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /sypackagemodels/1
|
14
|
+
# GET /sypackagemodels/1.json
|
15
|
+
def show
|
16
|
+
@sypackagemodel = ForemanPackages::Sypackagemodel.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.erb
|
20
|
+
format.json { render json: @sypackagemodel }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /sypackagemodels/new
|
25
|
+
# GET /sypackagemodels/new.json
|
26
|
+
def new
|
27
|
+
@sypackagemodel = ForemanPackages::Sypackagemodel.new
|
28
|
+
respond_to do |format|
|
29
|
+
format.html # new.html.erb
|
30
|
+
format.json { render json: @sypackagemodel }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# GET /sypackagemodels/1/edit
|
35
|
+
def edit
|
36
|
+
@sypackagemodel = ForemanPackages::Sypackagemodel.find(params[:id])
|
37
|
+
# sygroup_time = @sypackagemodel.sygroups.size
|
38
|
+
# if sygroup_time == 0
|
39
|
+
# 5.times { @sypackagemodel.sygroups.build}
|
40
|
+
# else
|
41
|
+
# 5.times { @sypackagemodel.sygroups.build}
|
42
|
+
# end
|
43
|
+
end
|
44
|
+
|
45
|
+
# POST /sypackagemodels
|
46
|
+
# POST /sypackagemodels.json
|
47
|
+
def create
|
48
|
+
@sypackagemodel = ForemanPackages::Sypackagemodel.new(params[:foreman_packages_sypackagemodel])
|
49
|
+
|
50
|
+
respond_to do |format|
|
51
|
+
if @sypackagemodel.save
|
52
|
+
format.html { redirect_to @sypackagemodel, notice: 'Sypackagemodel was successfully created.' }
|
53
|
+
format.json { render json: @sypackagemodel, status: :created, location: @sypackagemodel }
|
54
|
+
else
|
55
|
+
format.html { render action: "new" }
|
56
|
+
format.json { render json: @sypackagemodel.errors, status: :unprocessable_entity }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# PUT /sypackagemodels/1
|
62
|
+
# PUT /sypackagemodels/1.json
|
63
|
+
def update
|
64
|
+
@sypackagemodel = ForemanPackages::Sypackagemodel.find(params[:id])
|
65
|
+
|
66
|
+
respond_to do |format|
|
67
|
+
if @sypackagemodel.update_attributes(params[:foreman_packages_sypackagemodel])
|
68
|
+
format.html { redirect_to @sypackagemodel, notice: 'Sypackagemodel was successfully updated.' }
|
69
|
+
format.json { head :no_content }
|
70
|
+
else
|
71
|
+
format.html { render action: "edit" }
|
72
|
+
format.json { render json: @sypackagemodel.errors, status: :unprocessable_entity }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# DELETE /sypackagemodels/1
|
78
|
+
# DELETE /sypackagemodels/1.json
|
79
|
+
def destroy
|
80
|
+
@sypackagemodel = ForemanPackages::Sypackagemodel.find(params[:id])
|
81
|
+
@sypackagemodel.destroy
|
82
|
+
@sypackagemodel.destory_dir
|
83
|
+
respond_to do |format|
|
84
|
+
format.html { redirect_to foreman_packages_sypackagemodels_url }
|
85
|
+
format.json { head :no_content }
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -24,11 +24,10 @@ class ForemanPackages::SypackagesController < ApplicationController
|
|
24
24
|
# GET /sypackages/new
|
25
25
|
# GET /sypackages/new.json
|
26
26
|
def new
|
27
|
-
|
28
|
-
|
27
|
+
packagemodel = ForemanPackages::Sypackagemodel.find(params[:sypackagemodel_id])
|
28
|
+
@sypackage = packagemodel.sypackages.new
|
29
29
|
respond_to do |format|
|
30
|
-
format.
|
31
|
-
format.json { render json: @sypackage }
|
30
|
+
format.js
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
@@ -41,13 +40,17 @@ class ForemanPackages::SypackagesController < ApplicationController
|
|
41
40
|
# POST /sypackages.json
|
42
41
|
def create
|
43
42
|
@sypackage = ForemanPackages::Sypackage.new(params[:foreman_packages_sypackage])
|
44
|
-
|
45
|
-
|
43
|
+
puts ">>>>>>>>>>>>>>>>>"
|
44
|
+
puts @sypackage
|
45
|
+
puts "<<<<<<<<<<<<<<<<<<"
|
46
|
+
puts params[:foreman_packages_sypackage]
|
47
|
+
puts "++++++++++++++++++++++++++++++++++++"
|
48
|
+
if params[:foreman_packages_sypackage][:avatar].present?
|
49
|
+
@sypackage.avatar = params[:foreman_packages_sypackage][:avatar].original_filename
|
46
50
|
end
|
47
51
|
respond_to do |format|
|
48
52
|
if @sypackage.save
|
49
|
-
format.
|
50
|
-
format.json { render json: @sypackage, status: :created, location: @sypackage }
|
53
|
+
format.js
|
51
54
|
else
|
52
55
|
format.html { render action: "new" }
|
53
56
|
format.json { render json: @sypackage.errors, status: :unprocessable_entity }
|
@@ -59,11 +62,12 @@ class ForemanPackages::SypackagesController < ApplicationController
|
|
59
62
|
# PUT /sypackages/1.json
|
60
63
|
def update
|
61
64
|
@sypackage = ForemanPackages::Sypackage.find(params[:id])
|
62
|
-
|
65
|
+
if params[:foreman_packages_sypackage][:avatar].present?
|
66
|
+
@sypackage.avatar = params[:foreman_packages_sypackage][:avatar].original_filename
|
67
|
+
end
|
63
68
|
respond_to do |format|
|
64
69
|
if @sypackage.update_attributes(params[:foreman_packages_sypackage])
|
65
|
-
format.
|
66
|
-
format.json { head :no_content }
|
70
|
+
format.js
|
67
71
|
else
|
68
72
|
format.html { render action: "edit" }
|
69
73
|
format.json { render json: @sypackage.errors, status: :unprocessable_entity }
|
@@ -78,8 +82,7 @@ class ForemanPackages::SypackagesController < ApplicationController
|
|
78
82
|
@sypackage.destroy
|
79
83
|
|
80
84
|
respond_to do |format|
|
81
|
-
format.
|
82
|
-
format.json { head :no_content }
|
85
|
+
format.js
|
83
86
|
end
|
84
87
|
end
|
85
88
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class ForemanPackages::Syattachment < ActiveRecord::Base
|
2
|
+
require 'carrierwave'
|
3
|
+
|
4
|
+
attr_accessible :link, :filename, :sypackagemodel_id, :link_cache
|
5
|
+
belongs_to :foreman_packages_sypackagemodel, class_name: "ForemanPackages::Sypackagemodel",foreign_key: "sypackagemodel_id"
|
6
|
+
|
7
|
+
mount_uploader :link, ForemanPackages::AvatarUploader
|
8
|
+
attr_accessor :uploader_secure_token
|
9
|
+
|
10
|
+
end
|
@@ -1,90 +1,87 @@
|
|
1
1
|
class ForemanPackages::Sypackage < ActiveRecord::Base
|
2
2
|
require "fileutils"
|
3
|
-
|
3
|
+
require 'carrierwave'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
after_update :create_dir
|
8
|
-
|
9
|
-
#validates :filename, :name , :ensure, :presence => true
|
10
|
-
validate :name, :filename, :presence => true
|
11
|
-
validates :name, :uniqueness => true
|
12
|
-
#after_destory :destory_dir
|
13
|
-
def create_dir
|
14
|
-
#目前用 "/home/stdtnt/app/"代替 "/etc/puppet/environments/production/modules/packages"
|
15
|
-
#该处需要注意权限问题,当前用户是否具有该目录的操作权限
|
16
|
-
root_dir_name = "/etc/puppet/environments/production/modules/packages/"
|
17
|
-
#self.destory_dir #默认删除该目录,然后重新创建
|
18
|
-
dir_exist_status = File.exist?(root_dir_name) #判断该目录是否存在
|
19
|
-
if !dir_exist_status
|
20
|
-
#创建目录结构
|
21
|
-
Dir::mkdir(root_dir_name)
|
22
|
-
if !File.exist?(root_dir_name + "files")
|
23
|
-
Dir::mkdir(root_dir_name + "files")
|
24
|
-
end
|
5
|
+
attr_accessible :name, :ensure, :file_path, :file_ensure, :file_source, :file_mode, :file_onwer, :file_group, :file_notify, :file_require, :service_name, :service_ensure, :service_enable, :service_hasstatus, :service_hasrestart, :avatar, :sypackagemodel_id, :avatar_cache
|
6
|
+
belongs_to :foreman_packages_sypackagemodel, class_name: "ForemanPackages::Sypackagemodel",foreign_key: "sypackagemodel_id"
|
25
7
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
if File.exist?(root_dir_name + "/files")
|
32
|
-
if File.exist?(root_dir_name + "/files/welcome.conf")
|
33
|
-
#生成files下welcome.conf文件
|
34
|
-
files_welcome_File = File.new(root_dir_name + "/files/welcome.conf", "w+")
|
35
|
-
files_welcome_File.close
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
if File.exist?(root_dir_name + "/manifests")
|
40
|
-
if File.exist?(root_dir_name + "/manifests/init.pp")
|
41
|
-
FileUtils.rm_r (root_dir_name + "/manifests/init.pp")
|
42
|
-
end
|
43
|
-
#生成manifests下init.pp文件
|
44
|
-
main_init_File = File.new(root_dir_name +"/manifests/init.pp", "w+")
|
45
|
-
if main_init_File
|
46
|
-
main_init_File.syswrite(self.create_content)
|
47
|
-
else
|
48
|
-
puts "Unable to open file!"
|
49
|
-
end
|
50
|
-
main_init_File.close
|
51
|
-
end
|
52
|
-
|
53
|
-
#self.change_dir
|
54
|
-
|
55
|
-
end
|
8
|
+
mount_uploader :avatar, ForemanPackages::AvatarUploader
|
9
|
+
attr_accessor :uploader_secure_token
|
56
10
|
|
11
|
+
#validates :filename, :name , :ensure, :presence => true
|
12
|
+
# validate :name, :filename, :presence => true
|
13
|
+
# validates :name, :uniqueness => true
|
57
14
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
15
|
+
after_create :create_dir
|
16
|
+
after_update :create_dir
|
17
|
+
after_destroy :create_dir
|
18
|
+
def create_dir
|
19
|
+
#该处需要注意权限问题,当前用户是否具有该目录的操作权限
|
20
|
+
root_dir_name = "/etc/puppet/environments/production/modules/" + self.foreman_packages_sypackagemodel.name
|
21
|
+
|
22
|
+
dir_exist_status = File.exist?(root_dir_name )
|
23
|
+
if dir_exist_status
|
24
|
+
#FileUtils.rm_r root_dir_name
|
25
|
+
end #默认删除该目录,然后重新创建,主要目的防止文件或文件夹被误删除
|
26
|
+
|
27
|
+
#创建目录结构
|
28
|
+
Dir::mkdir(root_dir_name)
|
29
|
+
if !File.exist?(root_dir_name + "/files")
|
30
|
+
Dir::mkdir(root_dir_name + "/files")
|
31
|
+
end
|
32
|
+
|
33
|
+
if !File.exist?(root_dir_name + "/manifests")
|
34
|
+
Dir::mkdir(root_dir_name + "/manifests")
|
35
|
+
end
|
36
|
+
|
37
|
+
if File.exist?(root_dir_name + "/files")
|
38
|
+
if File.exist?(root_dir_name + "/files/welcome.conf")
|
39
|
+
#生成files下welcome.conf文件
|
40
|
+
files_welcome_File = File.new(root_dir_name + "/files/welcome.conf", "w+")
|
41
|
+
files_welcome_File.close
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
if File.exist?(root_dir_name + "/manifests")
|
46
|
+
if File.exist?(root_dir_name + "/manifests/init.pp")
|
47
|
+
FileUtils.rm_r (root_dir_name + "/manifests/init.pp")
|
48
|
+
end
|
49
|
+
#生成manifests下init.pp文件
|
50
|
+
main_init_File = File.new(root_dir_name +"/manifests/init.pp", "w+")
|
51
|
+
if main_init_File
|
52
|
+
main_init_File.syswrite(self.create_content)
|
53
|
+
else
|
54
|
+
puts "Unable to open file!"
|
55
|
+
end
|
56
|
+
main_init_File.close
|
70
57
|
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def destory_dir
|
61
|
+
#该处需要注意权限问题,当前用户是否具有该目录的操作权限
|
62
|
+
root_dir_name = "/etc/puppet/environments/production/modules/" + self.foreman_packages_sypackagemodel.name
|
63
|
+
#判断该目录是否存在
|
64
|
+
dir_exist_status = File.exist?(root_dir_name )
|
65
|
+
if dir_exist_status
|
66
|
+
FileUtils.rm_r root_dir_name
|
67
|
+
end
|
68
|
+
end
|
71
69
|
|
72
70
|
def create_content
|
73
71
|
title_content = "class packages {"
|
74
|
-
|
72
|
+
if self.foreman_packages_sypackagemodel.sypackages.size > 0
|
73
|
+
self.foreman_packages_sypackagemodel.sypackages.each do |package|
|
74
|
+
user_content = "\n" + "\s\s" + "package{'" + package.name + "':" + "\n\s\s\s\s" + "ensure => '" + package.ensure + "'," + "\n\s\s" +"}" + "\n"
|
75
75
|
|
76
|
-
|
76
|
+
file_content = "\s\s" + "file{'"+ package.file_path + "':" + "\n\s\s\s\s" + "ensure => '" + package.file_ensure + "'," + "\n\s\s\s\s" + "source => '" + package.file_source + "mode => '" + package.file_mode + "'," + "\n\s\s\s\s" + "onwer => '" + package.file_onwer + "group => '" + package.file_group + "'," + "\n\s\s\s\s" + "notify=> Service['" + package.file_notify + "']," + "\n\s\s\s\s" + "require=> Package['" + package.file_require + "']," + "\n\s\s" +"}" + "\n\s\s"
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
service_content = "service{'"+ package.service_name + "':" + "\n\s\s\s\s" + "ensure => '" + package.service_ensure + "'," + "\n\s\s\s\s" + "enable => '" + package.service_enable + "hasstatus => '" + package.service_hasstatus + "'," + "\n\s\s\s\s" + "hasrestart => '" + package.service_hasrestart + "," + "\n\s\s" +"}" + "\n\s\s"
|
81
|
-
|
82
|
-
title_content += user_content + file_content + service_content
|
83
|
-
end
|
78
|
+
service_content = "service{'"+ package.service_name + "':" + "\n\s\s\s\s" + "ensure => '" + package.service_ensure + "'," + "\n\s\s\s\s" + "enable => '" + package.service_enable + "hasstatus => '" + package.service_hasstatus + "'," + "\n\s\s\s\s" + "hasrestart => '" + package.service_hasrestart + "," + "\n\s\s" +"}" + "\n\s\s"
|
84
79
|
|
80
|
+
title_content += user_content + file_content + service_content
|
81
|
+
end
|
82
|
+
end
|
85
83
|
|
86
84
|
rs = title_content + "\n" + "}"
|
87
85
|
return rs
|
88
86
|
end
|
89
|
-
|
90
87
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class ForemanPackages::Sypackagemodel < ActiveRecord::Base
|
2
|
+
require "fileutils"
|
3
|
+
attr_accessible :name, :remark
|
4
|
+
|
5
|
+
has_many :sypackages, class_name: "ForemanPackages::Sypackage",foreign_key: "sypackagemodel_id", :dependent => :destroy
|
6
|
+
has_many :syattachments, class_name: "ForemanPackages::Syattachment",foreign_key: "sypackagemodel_id", :dependent => :destroy
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
after_create :create_dir
|
11
|
+
after_update :create_dir
|
12
|
+
after_destroy :destory_dir
|
13
|
+
def create_dir
|
14
|
+
#该处需要注意权限问题,当前用户是否具有该目录的操作权限
|
15
|
+
root_dir_name = "/etc/puppet/environments/production/modules/" + self.name
|
16
|
+
|
17
|
+
dir_exist_status = File.exist?(root_dir_name )
|
18
|
+
if dir_exist_status
|
19
|
+
#FileUtils.rm_r root_dir_name
|
20
|
+
end #默认删除该目录,然后重新创建,主要目的防止文件或文件夹被误删除
|
21
|
+
|
22
|
+
#创建目录结构
|
23
|
+
Dir::mkdir(root_dir_name)
|
24
|
+
if !File.exist?(root_dir_name + "/files")
|
25
|
+
Dir::mkdir(root_dir_name + "/files")
|
26
|
+
end
|
27
|
+
|
28
|
+
if !File.exist?(root_dir_name + "/manifests")
|
29
|
+
Dir::mkdir(root_dir_name + "/manifests")
|
30
|
+
end
|
31
|
+
|
32
|
+
if File.exist?(root_dir_name + "/files")
|
33
|
+
if File.exist?(root_dir_name + "/files/welcome.conf")
|
34
|
+
#生成files下welcome.conf文件
|
35
|
+
files_welcome_File = File.new(root_dir_name + "/files/welcome.conf", "w+")
|
36
|
+
files_welcome_File.close
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
if File.exist?(root_dir_name + "/manifests")
|
41
|
+
if File.exist?(root_dir_name + "/manifests/init.pp")
|
42
|
+
FileUtils.rm_r (root_dir_name + "/manifests/init.pp")
|
43
|
+
end
|
44
|
+
#生成manifests下init.pp文件
|
45
|
+
main_init_File = File.new(root_dir_name +"/manifests/init.pp", "w+")
|
46
|
+
if main_init_File
|
47
|
+
main_init_File.syswrite(self.create_content)
|
48
|
+
else
|
49
|
+
puts "Unable to open file!"
|
50
|
+
end
|
51
|
+
main_init_File.close
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def destory_dir
|
56
|
+
#该处需要注意权限问题,当前用户是否具有该目录的操作权限
|
57
|
+
root_dir_name = "/etc/puppet/environments/production/modules/" + self.name
|
58
|
+
#判断该目录是否存在
|
59
|
+
dir_exist_status = File.exist?(root_dir_name )
|
60
|
+
if dir_exist_status
|
61
|
+
FileUtils.rm_r root_dir_name
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_content
|
66
|
+
title_content = "class packages {"
|
67
|
+
if self.sypackages.size > 0
|
68
|
+
self.sypackages.each do |package|
|
69
|
+
user_content = "\n" + "\s\s" + "package{'" + package.name + "':" + "\n\s\s\s\s" + "ensure => '" + package.ensure + "'," + "\n\s\s" +"}" + "\n"
|
70
|
+
|
71
|
+
file_content = "\s\s" + "file{'"+ package.file_path + "':" + "\n\s\s\s\s" + "ensure => '" + package.file_ensure + "'," + "\n\s\s\s\s" + "source => '" + package.file_source + "mode => '" + package.file_mode + "'," + "\n\s\s\s\s" + "onwer => '" + package.file_onwer + "group => '" + package.file_group + "'," + "\n\s\s\s\s" + "notify=> Service['" + package.file_notify + "']," + "\n\s\s\s\s" + "require=> Package['" + package.file_require + "']," + "\n\s\s" +"}" + "\n\s\s"
|
72
|
+
|
73
|
+
service_content = "service{'"+ package.service_name + "':" + "\n\s\s\s\s" + "ensure => '" + package.service_ensure + "'," + "\n\s\s\s\s" + "enable => '" + package.service_enable + "hasstatus => '" + package.service_hasstatus + "'," + "\n\s\s\s\s" + "hasrestart => '" + package.service_hasrestart + "," + "\n\s\s" +"}" + "\n\s\s"
|
74
|
+
|
75
|
+
title_content += user_content + file_content + service_content
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
rs = title_content + "\n" + "}"
|
80
|
+
return rs
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'carrierwave'
|
3
|
+
class ForemanPackages::AvatarUploader < CarrierWave::Uploader::Base
|
4
|
+
#使用minimagick处理压缩图片,确保安装magickimage这个东东,ubuntu可以sudo apt-get install magickimage
|
5
|
+
|
6
|
+
# Choose what kind of storage to use for this uploader:
|
7
|
+
storage :file
|
8
|
+
# storage :fog
|
9
|
+
|
10
|
+
# Override the directory where uploaded files will be stored.
|
11
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
12
|
+
def store_dir #定义上传到哪个文件夹下
|
13
|
+
"/etc/puppet/environments/production/modules/#{model.foreman_packages_sypackagemodel.name}/files"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<%= javascript 'syattachments', 'syattachment_edit', 'syattachment_edit_interfaces', 'class_edit', 'compute_resource', 'lookup_keys'%>
|
2
|
+
|
3
|
+
<%= form_for @syattachment do |f| %>
|
4
|
+
<%= base_errors_for @syattachment %>
|
5
|
+
<div class="row clearfix">
|
6
|
+
<div class="row">
|
7
|
+
<div class="form-group col-md-6">
|
8
|
+
<%= f.file_field :link %>
|
9
|
+
<%= f.hidden_field :link_cache %>
|
10
|
+
</div>
|
11
|
+
</div>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="actions">
|
15
|
+
<%= f.hidden_field :sypackagemodel_id, value: @syattachment.sypackagemodel_id %>
|
16
|
+
<%= f.submit "提交", class: "btn btn-success" %>
|
17
|
+
<%= link_to '返回', foreman_packages_syattachments_path, class: "btn btn-primary" %>
|
18
|
+
</div>
|
19
|
+
<% end %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<td><%= syattachment.filename %></td>
|
2
|
+
<td><%= syattachment.link %></td>
|
3
|
+
<td><%= syattachment.created_at.strftime "%Y-%m-%m" %></td>
|
4
|
+
<td>
|
5
|
+
<%= link_to '查看', syattachment %>
|
6
|
+
<%= link_to '编辑', edit_foreman_packages_syattachment_path(syattachment), class: "btn btn-xs btn-warning" %>
|
7
|
+
<%= link_to '删除', syattachment, method: :delete, data: { confirm: '确定删除?' }, class: "btn btn-xs btn-danger" %>
|
8
|
+
|
9
|
+
</td>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'form' %>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<h1 class="clearfix">
|
2
|
+
<span class="pull-left">
|
3
|
+
图档列表
|
4
|
+
</span>
|
5
|
+
</h1>
|
6
|
+
|
7
|
+
<table class="table table-striped table-hover attachments">
|
8
|
+
<thead>
|
9
|
+
<tr>
|
10
|
+
<th>名称</th>
|
11
|
+
<th>位置</th>
|
12
|
+
<th>创建于</th>
|
13
|
+
<th>操作</th>
|
14
|
+
</tr>
|
15
|
+
</thead>
|
16
|
+
|
17
|
+
<tbody>
|
18
|
+
<% @syattachments.each do |syattachment| %>
|
19
|
+
<%= render partial: 'foreman_packages/syattachments/syattachment', locals: { syattachment: syattachment } %>
|
20
|
+
<% end %>
|
21
|
+
</tbody>
|
22
|
+
</table>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'form' %>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
<div class="container">
|
3
|
+
<div class="row">
|
4
|
+
<h1 class="clearfix">
|
5
|
+
<%= link_to '返回模板', @syattachment.foreman_packages_sypackagemodel, class: "btn btn-primary pull-right mr1" %>
|
6
|
+
<%= link_to '列表', foreman_packages_syattachments_path, class: "btn btn-primary pull-right mr1" %>
|
7
|
+
<%= link_to '编辑', edit_foreman_packages_syattachment_path(@syattachment), class: "btn btn-warning pull-right mr1" %>
|
8
|
+
</h1>
|
9
|
+
</div>
|
10
|
+
|
11
|
+
<div class="row col-md-12">
|
12
|
+
<table class="table table-striped table-bordered">
|
13
|
+
<thead></thead>
|
14
|
+
<tbody>
|
15
|
+
<tr>
|
16
|
+
<td><strong>名称</strong></td>
|
17
|
+
<td><%= @syattachment.filename %></td>
|
18
|
+
</tr>
|
19
|
+
<tr>
|
20
|
+
<td><strong>保存位置</strong></td>
|
21
|
+
<td><%= @syattachment.link %></td>
|
22
|
+
</tr>
|
23
|
+
<tr>
|
24
|
+
<td><strong>创建于</strong></td>
|
25
|
+
<td><%= @syattachment.created_at.strftime "%Y-%m-%m" %></td>
|
26
|
+
</tr>
|
27
|
+
</tbody>
|
28
|
+
</table>
|
29
|
+
</div>
|
30
|
+
</div>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<%= javascript 'sypackagemodels', 'sypackagemodel_edit', 'sypackagemodel_edit_interfaces', 'class_edit', 'compute_resource', 'lookup_keys'%>
|
2
|
+
|
3
|
+
<%= form_for @sypackagemodel, :html => {:data => {:id => @sypackagemodel.try(:id), :submit => 'progress_bar'}} do |f| %>
|
4
|
+
<%= base_errors_for @sypackagemodel %>
|
5
|
+
<div class="row clearfix">
|
6
|
+
<div class="row">
|
7
|
+
<div class="form-group col-md-3">
|
8
|
+
<label>name</label>
|
9
|
+
<%= f.text_field :name, :size => "col-md-3", placeholder: "填写模块名", class: "form-control" %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div class="form-group col-md-3">
|
13
|
+
<label>remark</label>
|
14
|
+
<%= f.text_field :remark, :size => "col-md-3", placeholder: "remark", class: "form-control" %>
|
15
|
+
</div>
|
16
|
+
</div>
|
17
|
+
<div class="row">
|
18
|
+
<div class="actions">
|
19
|
+
<%= f.submit "提交", class: "btn btn-success" %>
|
20
|
+
<%= link_to '返回', foreman_packages_sypackagemodels_path, class: "btn btn-primary" %>
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
<% end %>
|