Permalink
Browse files

Add thumbnail for vms

  • Loading branch information...
ricofehr committed Apr 14, 2017
1 parent e5e4d32 commit 43c481eba4d44b73a0efc6943d2bcf095db31c60
View
@@ -15,6 +15,10 @@
/ror/public/*
!/ror/public/.keep
# Ignore thumb folder
/ror/thumbs/*
!/ror/thumbs/default.png
# Ignore nohup file
nohup.out
View
@@ -132,3 +132,6 @@
path = vagrant/modules/neutron
url = https://github.com/ricofehr/puppet-neutron
branch = nextdeploy
[submodule "vagrant/modules/phantomjs"]
path = vagrant/modules/phantomjs
url = https://github.com/3fs/puppet-phantomjs
View
@@ -52,3 +52,6 @@ gem 'dalli'
#yard for document code
gem 'yard'
# take screenshot from url
gem "webshot"
View
@@ -29,9 +29,19 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
arel (5.0.1.20140414130214)
bcrypt (3.1.10)
builder (3.2.2)
capybara (2.13.0)
addressable
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
cliver (0.3.2)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
@@ -48,9 +58,13 @@ GEM
thread_safe (~> 0.1)
warden (~> 1.2.3)
erubis (2.7.0)
eventmachine (1.2.3)
execjs (2.6.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
faye-websocket (0.7.5)
eventmachine (>= 0.12.0)
websocket-driver (>= 0.3.5)
gitlab (3.6.1)
httparty
terminal-table
@@ -69,13 +83,22 @@ GEM
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.99)
mini_magick (4.3.6)
mini_portile2 (2.1.0)
minitest (5.8.3)
multi_json (1.11.2)
multi_xml (0.5.5)
multipart-post (2.0.0)
mysql2 (0.3.20)
net-http-persistent (2.9.4)
nokogiri (1.7.1)
mini_portile2 (~> 2.1.0)
orm_adapter (0.5.0)
poltergeist (1.12.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
public_suffix (2.0.5)
puma (2.15.3)
rack (1.5.5)
rack-test (0.6.3)
@@ -132,6 +155,16 @@ GEM
json (>= 1.8.0)
warden (1.2.3)
rack (>= 1.0)
webshot (0.1.0)
activesupport
faye-websocket (~> 0.7.3)
mini_magick (~> 4.3.3)
poltergeist (~> 1.12.0)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
xpath (2.0.0)
nokogiri (~> 1.3)
yard (0.8.7.6)
PLATFORMS
@@ -157,6 +190,7 @@ DEPENDENCIES
spring
turbolinks
uglifier (>= 1.3.0)
webshot
yard
BUNDLED WITH
@@ -123,7 +123,7 @@ def ember_to_rails
def endpoint_params
params.require(:endpoint).permit(:prefix, :path, :envvars, :aliases, :project_id,
:framework_id, :is_install, :port, :ipfilter,
:customvhost, :is_sh, :is_import)
:customvhost, :is_sh, :is_import, :is_main)
end
end
end
@@ -303,7 +303,7 @@ def ember_to_rails
def uri_params
params.require(:uri).permit(:absolute, :path, :aliases, :envvars, :vm_id,
:framework_id, :port, :ipfilter, :customvhost,
:is_sh, :is_import, :is_redir_alias)
:is_sh, :is_import, :is_redir_alias, :is_main)
end
end
end
@@ -355,6 +355,7 @@ def ember_to_rails
params_p.delete(:nova_id)
#params_p.delete(:name)
params_p.delete(:floating_ip)
params_p.delete(:thumb)
params_p.delete(:user)
params_p.delete(:project)
params_p.delete(:systemimage)
@@ -326,6 +326,7 @@ def check_status
def clear_vmfiles
Rails.logger.warn "rm -f hiera/#{name}#{Rails.application.config.os_suffix}.yaml"
system("rm -f hiera/#{name}#{Rails.application.config.os_suffix}.yaml")
system("rm -f thumbs/#{id}.png")
system("rm -f /tmp/vm#{id}.lock")
end
@@ -450,4 +451,27 @@ def logs
{ message: bashret, status: 200 }
end
def webshot
uri = uris.first
Rails.cache.fetch("vms/#{id}/webshot", expires_in: 600.minutes) do
# take a lock for once shot at time
begin
open("/tmp/webshot.lock", File::RDWR|File::CREAT) do |f|
f.flock(File::LOCK_EX)
begin
# Setup Capybara
ws = Webshot::Screenshot.instance
# Customize thumbnail
suppress(Exception) do
ws.capture "http://#{htlogin}:#{htpassword}@#{uri.absolute}/", "thumbs/#{id}.png", width: 360, height: 240, quality: 85
end
end
end
rescue => e
raise Exceptions::NextDeployException.new("Lock on webshot command for #{name} failed, #{e.message}")
end
end
end
end
View
@@ -13,18 +13,16 @@ class Vm < ActiveRecord::Base
has_many :supervises, dependent: :destroy
has_many :technos, through: :supervises
has_many :uris, dependent: :destroy
has_many :uris, -> { order(is_main: :desc) }, dependent: :destroy
has_many :frameworks, through: :uris
# Some scope for find vms objects by commit, by project or by name
scope :find_by_user_commit, ->(user_id, commit){ where("user_id=#{user_id} AND commit_id like '%#{commit}'") }
scope :find_by_user_project, ->(user_id, project_id){ where(user_id: user_id, project_id: project_id) }
attr_accessor :floating_ip, :commit, :vnc_url
attr_accessor :floating_ip, :commit, :vnc_url, :thumb
# Some hooks before vm changes
#before_create :boot_os
#after_create :generate_host_all
before_destroy :delete_vm
# Init external api objects and extra attributes
@@ -216,7 +214,7 @@ def init_defaulturis
end
Uri.new(vm: self, framework: endpoint.framework, absolute: absolute, path: endpoint.path,
envvars: endpoint.envvars, aliases: aliases, port: endpoint.port, ipfilter: endpoint.ipfilter,
is_sh: endpoint.is_sh, is_import: endpoint.is_import, is_redir_alias: false).save
is_sh: endpoint.is_sh, is_import: endpoint.is_import, is_main: endpoint.is_main, is_redir_alias: false).save
end
reload
@@ -340,6 +338,14 @@ def init_extra_attr
# delete from cache if nil object
Rails.cache.delete("vms/#{nova_id}/floating_ip") if @floating_ip.nil?
webshot
@thumb = if File.exist?("thumbs/#{id}.png")
"/thumbs/#{id}.png"
else
Rails.cache.delete("vms/#{id}/webshot")
"/thumbs/default.png"
end
end
@commit =
@@ -3,7 +3,7 @@
# @author Eric Fehr (ricofehr@nextdeploy.io, github: ricofehr)
class EndpointSerializer < ActiveModel::Serializer
attributes :id, :prefix, :path, :envvars, :aliases, :is_install,
:ipfilter, :port, :customvhost, :is_sh, :is_import
:ipfilter, :port, :customvhost, :is_sh, :is_import, :is_main
has_one :project, key: :project
has_one :framework, key: :framework
@@ -4,7 +4,7 @@
class UriSerializer < ActiveModel::Serializer
attributes :id, :absolute, :path, :envvars, :aliases,
:ipfilter, :port, :customvhost, :is_sh,
:is_import, :is_redir_alias
:is_import, :is_redir_alias, :is_main
has_one :vm, key: :vm
has_one :framework, key: :framework
@@ -2,7 +2,7 @@
#
# @author Eric Fehr (ricofehr@nextdeploy.io, github: ricofehr)
class VmSerializer < ActiveModel::Serializer
attributes :id, :nova_id, :floating_ip, :vnc_url, :created_at, :name, :topic, :status,
attributes :id, :nova_id, :floating_ip, :vnc_url, :thumb, :created_at, :name, :topic, :status,
:is_auth, :htlogin, :htpassword, :termpassword, :layout, :is_prod,
:is_cached, :is_ht, :is_ci, :is_backup, :is_cors, :is_ro
@@ -0,0 +1,5 @@
class AddIsMainToUris < ActiveRecord::Migration
def change
add_column :uris, :is_main, :boolean, default: false
end
end
@@ -0,0 +1,5 @@
class AddIsMainToEndpoints < ActiveRecord::Migration
def change
add_column :endpoints, :is_main, :boolean, default: false
end
end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160721084127) do
ActiveRecord::Schema.define(version: 20170413134410) do
create_table "brands", force: true do |t|
t.string "name"
@@ -31,6 +31,8 @@
t.string "ipfilter", limit: 512, default: ""
t.string "customvhost", limit: 4096, default: ""
t.boolean "is_sh", default: false
t.boolean "is_import", default: true
t.boolean "is_main", default: false
end
add_index "endpoints", ["framework_id"], name: "index_endpoints_on_framework_id", using: :btree
@@ -60,6 +62,7 @@
t.integer "expiration"
t.integer "ordering"
t.boolean "is_twitter"
t.string "date", default: ""
end
create_table "project_systemimages", force: true do |t|
@@ -144,6 +147,7 @@
t.integer "ordering"
t.integer "technotype_id"
t.string "dockercompose"
t.string "playbook", limit: 8192
end
add_index "technos", ["technotype_id"], name: "index_technos_on_technotype_id", using: :btree
@@ -157,14 +161,17 @@
create_table "uris", force: true do |t|
t.integer "vm_id"
t.integer "framework_id"
t.string "absolute", limit: 512
t.string "absolute", limit: 512
t.string "path"
t.string "envvars", limit: 512
t.string "aliases", limit: 2048
t.string "envvars", limit: 512
t.string "aliases", limit: 2048
t.integer "port"
t.string "ipfilter", limit: 512, default: ""
t.string "customvhost", limit: 4096, default: ""
t.boolean "is_sh", default: false
t.string "ipfilter", limit: 512, default: ""
t.string "customvhost", limit: 4096, default: ""
t.boolean "is_sh", default: false
t.boolean "is_import", default: true
t.boolean "is_redir_alias", default: false
t.boolean "is_main", default: false
end
add_index "uris", ["framework_id"], name: "index_uris_on_framework_id", using: :btree
@@ -204,6 +211,8 @@
t.string "layout", limit: 15
t.boolean "is_user_create", default: false
t.integer "quotaprod", default: 0
t.integer "nbpages", default: 11
t.boolean "is_recv_vms", default: false
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
@@ -215,6 +224,7 @@
t.integer "techno_id"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "status", default: true
end
add_index "vm_technos", ["techno_id"], name: "index_vm_technos_on_techno_id", using: :btree
@@ -241,6 +251,9 @@
t.boolean "is_ht", default: false
t.boolean "is_backup", default: false
t.boolean "is_ci", default: false
t.boolean "is_cors"
t.string "topic"
t.boolean "is_ro", default: false
end
add_index "vms", ["project_id"], name: "index_vms_on_project_id", using: :btree
Oops, something went wrong.

0 comments on commit 43c481e

Please sign in to comment.