From ffdb0ab421d40bf0e787079fdaf59bb331af762f Mon Sep 17 00:00:00 2001 From: ricofehr Date: Sun, 8 Jan 2017 21:34:03 +0100 Subject: [PATCH] Add custom and optional "topic" field for vms --- ror/app/controllers/api/v1/vms_controller.rb | 12 +++++++++--- ror/app/models/vm.rb | 9 +++++++++ ror/app/serializers/vm_serializer.rb | 2 +- ror/config/routes.rb | 1 + ror/db/migrate/20170107143054_add_topic_to_vms.rb | 5 +++++ webui | 2 +- 6 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 ror/db/migrate/20170107143054_add_topic_to_vms.rb diff --git a/ror/app/controllers/api/v1/vms_controller.rb b/ror/app/controllers/api/v1/vms_controller.rb index 5208062..9eae5b2 100644 --- a/ror/app/controllers/api/v1/vms_controller.rb +++ b/ror/app/controllers/api/v1/vms_controller.rb @@ -8,12 +8,12 @@ class API::V1::VmsController < ApplicationController before_filter :authenticate_user_from_token!, :except => [:setupcomplete, :resetpassword, :refreshcommit] before_filter :authenticate_api_v1_user!, :except => [:setupcomplete, :resetpassword, :refreshcommit] # Hook who set vm object - before_action :set_vm, only: [:show, :update, :destroy, :check_status, + before_action :set_vm, only: [:show, :update, :topic, :destroy, :check_status, :boot, :gitpull, :logs, :toggleauth, :toggleprod, :togglecached, :toggleht, :toggleci, :togglebackup, :togglecors, :postinstall_display, :postinstall, :reboot] # Hook who check rights before action - before_action :check_me, only: [:show, :update, :destroy, :check_status, + before_action :check_me, only: [:show, :update, :topic, :destroy, :check_status, :boot, :gitpull, :logs, :toggleauth, :toggleprod, :togglecached, :toggleht, :toggleci, :togglebackup, :togglecors, :postinstall_display, :postinstall, :reboot] @@ -113,6 +113,12 @@ def update end end + # Change topic content + def topic + @vm.set_topic(params[:topic]) + render nothing: true + end + # Boot vm def boot @vm.boot @@ -360,7 +366,7 @@ def ember_to_rails # Never trust parameters from the scary internet, only allow the white list through. def vm_params - params.require(:vm).permit(:systemimage_id, :user_id, :commit_id, :project_id, :vmsize_id, :name, :is_auth, :htlogin, :htpassword, :layout, :is_prod, :is_cached, :is_ht, :is_ci, :is_cors, :techno_ids => []) + params.require(:vm).permit(:systemimage_id, :user_id, :commit_id, :project_id, :vmsize_id, :name, :topic, :is_auth, :htlogin, :htpassword, :layout, :is_prod, :is_cached, :is_ht, :is_ci, :is_cors, :techno_ids => []) end end end diff --git a/ror/app/models/vm.rb b/ror/app/models/vm.rb index f3b36ec..530c8da 100644 --- a/ror/app/models/vm.rb +++ b/ror/app/models/vm.rb @@ -51,6 +51,15 @@ def change_user(user_id) puppetrefresh end + # Update vm topic + # + # @param topic (String): new topic + # No return + def set_topic(topic) + self.topic = topic + save + end + # Toggle is_auth parameter # # No param diff --git a/ror/app/serializers/vm_serializer.rb b/ror/app/serializers/vm_serializer.rb index 1182b63..bd90a30 100644 --- a/ror/app/serializers/vm_serializer.rb +++ b/ror/app/serializers/vm_serializer.rb @@ -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, :status, + attributes :id, :nova_id, :floating_ip, :vnc_url, :created_at, :name, :topic, :status, :is_auth, :htlogin, :htpassword, :termpassword, :layout, :is_prod, :is_cached, :is_ht, :is_ci, :is_backup, :is_cors diff --git a/ror/config/routes.rb b/ror/config/routes.rb index 26c1ddd..bccc0f7 100644 --- a/ror/config/routes.rb +++ b/ror/config/routes.rb @@ -27,6 +27,7 @@ put '/vms/:name/setupcomplete' => 'vms#setupcomplete', as: 'vm_setupcomplete', constraints: { name: /[a-zA-Z0-9-]+/ } put '/vms/:name/resetpassword/:password' => 'vms#resetpassword', as: 'vm_resetpassword', constraints: { name: /[a-zA-Z0-9-]+/, password: /[a-zA-Z0-9-]+/ } put '/vms/:name/commit' => 'vms#refreshcommit', as: 'vm_refreshcommit', constraints: { name: /[a-zA-Z0-9-]+/ } + put '/vms/:id/topic' => 'vms#topic', as: 'vm_topic', constraints: { id: /\d+/ } get '/vms/:id/setupcomplete' => 'vms#check_status', as: 'vm_check_status', constraints: { id: /\d+/ } post '/vms/short' => 'vms#create_short', as: 'create_short' post '/vms/:id/gitpull' => 'vms#gitpull', as: 'vm_gitpull', constraints: { id: /\d+/ } diff --git a/ror/db/migrate/20170107143054_add_topic_to_vms.rb b/ror/db/migrate/20170107143054_add_topic_to_vms.rb new file mode 100644 index 0000000..2704dde --- /dev/null +++ b/ror/db/migrate/20170107143054_add_topic_to_vms.rb @@ -0,0 +1,5 @@ +class AddTopicToVms < ActiveRecord::Migration + def change + add_column :vms, :topic, :string + end +end diff --git a/webui b/webui index 0762b69..b4be0c8 160000 --- a/webui +++ b/webui @@ -1 +1 @@ -Subproject commit 0762b69b718558e23ffd5168125a5868e9551543 +Subproject commit b4be0c86005fb3f6eae92ede4ad46c9be6b9fb5c