Commit 42a1744d authored by nazarf's avatar nazarf

add form and to get node with seet

git-svn-id: https://svn.sp-service.com.ua/svnroot/svn/node-stats/branches/nazar_trunk@12 320591d9-fe85-4a77-9bad-1a723db14d60
parent 3da4b946
...@@ -127,7 +127,12 @@ class NodesController < AdminController ...@@ -127,7 +127,12 @@ class NodesController < AdminController
end end
def sync_node def sync_node
Node.sync_node @params = {
from: params[:sync_to_sheet][:from],
to: params[:sync_to_sheet][:to]
}
p @params
Node.sync_node(@params[:from], @params[:to])
redirect_to nodes_path redirect_to nodes_path
end end
......
...@@ -12,17 +12,23 @@ class Node < ActiveRecord::Base ...@@ -12,17 +12,23 @@ class Node < ActiveRecord::Base
AFTER_DOMAIN = 8 AFTER_DOMAIN = 8
AFTER_IP = 9 AFTER_IP = 9
STATE = 10 STATE = 10
LINKED_PROXMOX_ID = 11
GATEWAY = 12
NETMASK = 13
IPV6 = 14
def self.sync_node def self.sync_node(from, to)
session = GoogleDrive::Session.from_service_account_key("client_secret.json") session = GoogleDrive::Session.from_service_account_key("client_secret.json")
spreadsheet ||= session.spreadsheet_by_title("znode-instal-stats") spreadsheet ||= session.spreadsheet_by_title("znode-instal-stats")
@worksheet = spreadsheet.worksheets.first @worksheet = spreadsheet.worksheets.first
@worksheet.rows.each do |row| @worksheet.rows.each_with_index do |row, index|
Node.create(name: row[AFTER_DOMAIN], domain: row[AFTER_DOMAIN], ipv4: row[AFTER_IP], start_balance_t: row[START_AMOUNT_T], if index >= from.to_i && index <= to.to_i
start_balance_z: row[START_AMOUNT_Z], node_username: row[RPC_USER], node_password: row[RPC_PASS]) Node.create(name: row[AFTER_DOMAIN], domain: row[AFTER_DOMAIN], ipv4: row[AFTER_IP], ipv6: row[IPV6], start_balance_t: row[START_AMOUNT_T],
start_balance_z: row[START_AMOUNT_Z], node_username: row[RPC_USER], node_password: row[RPC_PASS])
end
end end
end end
end end
......
...@@ -3,7 +3,11 @@ ...@@ -3,7 +3,11 @@
%h1 %h1
= model_class.model_name.human(count: 2).mb_chars.titleize = model_class.model_name.human(count: 2).mb_chars.titleize
= link_to 'refresh node', z_gettotalbalance_url, class: 'btn btn-success' = link_to 'refresh node', z_gettotalbalance_url, class: 'btn btn-success'
= link_to 'sync node', sync_node_url, class: 'btn btn-success' = simple_form_for :sync_to_sheet, url: sync_node_path, method: :get, html: {class: 'form-inline'} do |f|
= f.button :submit, 'get node', class: 'btn btn-primary'
= f.input :from, required: false, label: 'from'
= f.input :to, required: false, label: 'to'
-#= link_to 'sync node', sync_node_url, class: 'btn btn-success'
%p=@command %p=@command
Investment: Investment:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment