Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Merge branch 'great-master-patch' into v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
slntopp committed Aug 19, 2021
2 parents 1565a8c + 7be7386 commit 47c4876
Show file tree
Hide file tree
Showing 31 changed files with 1,191 additions and 2,218 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- uses: actions/[email protected]
- uses: actions/setup-node@v2.1.5
- uses: actions/setup-node@v2.3.0

- name: Dependencies
run: npm install
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
chmod +x ione_server.rb
chmod +x -R hooks/*
rake hooks
rake install_gems[y]
rake install_deps[yum, y]
\cp -f sys/ione.service /usr/lib/systemd/system/ione.service
systemctl daemon-reload
systemctl restart ione
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check_ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

steps:
- uses: actions/[email protected]
- uses: actions/setup-node@v2.1.5
- uses: actions/setup-node@v2.3.0

- name: Dependencies
run: npm install
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/[email protected]

- name: Setup Ruby
uses: ruby/setup-ruby@v1.72.1
uses: ruby/setup-ruby@v1.78.0
with:
ruby-version: 2.5

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ Creators:
<td align="left">OpenNebula</td><td align="center">5.10+(see <a href="https://github.com/ione-cloud/ione/releases">Releases</a> for <br/>older ONe versions)</td><td align="center"></td>
</tr>
<tr>
<td align="left">MySQL MariaDB Server</td><td align="center">~8.0</td><td align="center"></td>
<td align="left">DataBase</td><td align="center"></td><td align="center"></td>
</tr>
<tr>
<td align="right">MySQL MariaDB Server</td><td align="center">~8.0</td><td></td>
</tr>
<tr>
<td align="right">PostgreSQL</td><td align="center">^13.3</td><td></td>
</tr>
<tr>
<td align="left">Ruby</td><td align="center">2.5.5</td><td align="center"></td>
Expand Down
45 changes: 33 additions & 12 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$messages = []

task :before, [:silent, :domain] do | _task, args |
task :before, [:packm, :silent, :domain] do | _task, args |
@packm = args[:packm] || 'yum'
@silent = args[:silent]
@domain = args[:domain]

Expand All @@ -16,27 +17,25 @@ task :before, [:silent, :domain] do | _task, args |
end

@src_dir = pwd
@version = File.read("#{@src_dir}/meta/version.txt")
puts "Installing IONe #{@version}"
end

task :useful_questions do
puts
puts "IONe installer is going to overwrite your nginx configuration."
nginx = @silent
until ['y', 'n'].include? nginx do
puts "IONe installer is would like to overwrite your nginx configuration."
@nginx = @silent
until ['y', 'n'].include? @nginx do
print "Do you want to continue? (y/n) "
nginx = STDIN.gets.strip.downcase
end
if nginx == 'n' then
puts "Exiting"
exit 0
@nginx = STDIN.gets.strip.downcase
end

while @domain.nil?
print "Please enter your base domain: "
@domain = STDIN.gets.strip.downcase

puts "You've entered '#{@domain}'"
puts "Nginx going to be configured with following server names:"
puts "Nginx should to be configured with following server names:"
puts " cloud.#{@domain} --> Sunstone"
puts " ione-api.#{@domain} --> IONe API"
puts " ione-admin.#{@domain} --> IONe UI"
Expand All @@ -49,15 +48,15 @@ task :useful_questions do
puts "Using '#{@domain}' as base domain."
end

load "rake/install_gems.rake"
load "rake/install_deps.rake"
load "rake/install_ione.rake"
load "rake/install_ui.rake"
load "rake/configure_nginx.rake"
load "rake/set_hooks.rake"
load "rake/test_install.rake"

desc "Full IONe Installation"
task :install, [:silent, :domain] => [:before, :useful_questions, :install_gems, :install_ione, :hooks, :install_ui, :configure_nginx] do
task :install, [:packm, :silent, :domain] => [:before, :useful_questions, :install_deps, :install_ione, :hooks, :install_ui, :configure_nginx] do
$messages << <<-EOF
Thanks, for installation and choosing us!
Configure ione with ione.conf & IONe UI and test install with: rake test_install
Expand All @@ -67,3 +66,25 @@ task :install, [:silent, :domain] => [:before, :useful_questions, :install_gems,
puts msg
end
end

desc "IONe check update"
task :check_update do
sh %{git checkout master}
sh %{git pull}
current = File.read('./meta/version.txt')
installed = File.read('/usr/lib/one/ione/meta/version.txt')
puts "\n" * 5
if current != installed then
puts "Update available! \n !!! DANGEROUS!!! Run rake update to install it."
else
puts "You are up to date."
end
end

desc "IONe update"
task :update, [:silent, :domain] => [:before, :useful_questions, :install_deps, :install_ione, :hooks, :install_ui, :configure_nginx] do
for msg in $messages do
puts msg
end
puts "IONe #{@version} is now installed, you're up to date!"
end
23 changes: 14 additions & 9 deletions core/connect_db.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
if $oned_conf.get('DB/BACKEND') != "\"mysql\"" then
STDERR.puts "OneDB backend is not MySQL, exiting..."
db_backend = ($oned_conf.get('DB/BACKEND') || $oned_conf.get('DB/backend')).delete("\"")
case db_backend
when "mysql"
adapter = :mysql2
when "postgresql"
adapter = :postgres
else
STDERR.puts "OneDB backend(#{db_backend}) is not supported, exiting..."
exit 1
end

ops = {}
ops[:host] = $oned_conf.get('DB/SERVER')
ops[:user] = $oned_conf.get('DB/USER')
ops[:password] = $oned_conf.get('DB/PASSWD')
ops[:database] = $oned_conf.get('DB/DB_NAME')
ops[:host] = ($oned_conf.get('DB/SERVER') || $oned_conf.get('DB/server'))
ops[:user] = ($oned_conf.get('DB/USER') || $oned_conf.get('DB/user'))
ops[:password] = ($oned_conf.get('DB/PASSWD') || $oned_conf.get('DB/passwd'))
ops[:database] = ($oned_conf.get('DB/DB_NAME') || $oned_conf.get('DB/db_name'))

ops.each do |k, v|
next if !v || !(v.is_a? String)

ops[k] = v.chomp('"').reverse.chomp('"').reverse
ops[k] = v.delete("\"")
end

ops.merge! adapter: :mysql2, encoding: 'utf8mb4'
ops.merge! adapter: adapter

require 'sequel'
$db = Sequel.connect(**ops)
2 changes: 2 additions & 0 deletions core/load_oned_conf.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'augeas'

ONED_CONF = '/etc/one/oned.conf' unless defined? ONED_CONF

work_file_dir = File.dirname(ONED_CONF)
work_file_name = File.basename(ONED_CONF)

Expand Down
5 changes: 5 additions & 0 deletions hooks/user_post_delete_clean_up.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@

id = user.id

if id == 0 then
puts "oneadmin user, skipping..."
exit 0
end

unless user.groups.include? IONe::Settings['IAAS_GROUP_ID'] then
puts "Not IaaS User, skipping..."
exit 0
Expand Down
6 changes: 0 additions & 6 deletions ione_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,6 @@
ENDPOINT = "http://localhost:#{$oned_conf.get('PORT')}/RPC2"
$client = Client.new(CREDENTIALS, ENDPOINT) # oneadmin auth-client

require "SettingsDriver"

# Settings Table Model
# @see https://github.com/ione-cloud/ione-sunstone/blob/55a9efd68681829624809b4895a49d750d6e6c34/models/SettingsDriver.rb#L13-L37 Settings Model Definition
class Settings < Sequel::Model(:settings); end

puts 'Including on_helper funcs'
require "#{ROOT}/service/on_helper.rb"
include ONeHelper
Expand Down
55 changes: 47 additions & 8 deletions lib/creative_funcs/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ def Reinstall(params, trace = ["Reinstall method called:#{__LINE__}"])
LOG_DEBUG params.merge!({ :method => 'Reinstall' }).debug_out
return nil if params['debug'] == 'turn_method_off'

return { 'vmid' => rand(params['vmid'].to_i + 1000), 'vmid_old' => params['vmid'], 'ip' => '0.0.0.0',
'ip_old' => '0.0.0.0' } if params['debug'] == 'data'

LOG "Reinstalling VM#{params['vmid']}", 'Reinstall'
trace << "Checking params:#{__LINE__ + 1}"
if params.get('vmid', 'groupid', 'userid', 'templateid').include?(nil) then
Expand Down Expand Up @@ -171,7 +168,7 @@ def Reinstall(params, trace = ["Reinstall method called:#{__LINE__}"])
return vmid.message if vmid.class != Integer

trace << "Changing VM owner:#{__LINE__ + 1}"
onblock(:vm, vmid).chown(params['userid'], IONe::Settings['USERS_GROUP'])
onblock(:vm, vmid).chown(params['userid'], params['groupid'] || IONe::Settings['USERS_GROUP'])

##### PostDeploy Activity define #####
Thread.new do
Expand Down Expand Up @@ -212,6 +209,49 @@ def Reinstall(params, trace = ["Reinstall method called:#{__LINE__}"])
return e.message, trace
end

# Recreates VM - leaves same ID, same IP addresses, amount of resources, etc, but recreates on host
# @param [Hash] params
# @option params [Integer] :vm
# @option params [String] :passwd (optional)
# @option deploy [Boolean] :deploy (optional)
# @return [TrueClass, Integer] - true and host where VM been deployed before recreate
def Recreate(params, trace = ["Recreate method called:#{__LINE__}"])
params.to_sym!
LOG "Recreating VM#{params[:vm]}", 'Recreate'

trace << "Getting VM:#{__LINE__}"
vm = onblock(:vm, params[:vm])
vm.info!
trace << "Checking access rights:#{__LINE__}"
onblock(:u, -1, @client) do | u |
u.info!
if u.id != vm.uid && !u.groups.include?(0) then
raise StandardError.new("Not enough access to perform Recreate")
end
end
trace << "Getting VM host:#{__LINE__}"
host, _ = vm.host
trace << "Recovering VM:#{__LINE__}"
vm.recover(4)

if params[:passwd] then
trace << "Changing VM password#{__LINE__}"
vm.passwd params[:passwd]
end

if params[:deploy] then
trace << "Waiting for state PENDING to deploy VM:#{__LINE__}"
vm.wait_state("PENDING", 120)
trace << "Deploying VM:#{__LINE__}"
vm.deploy(host.to_i)
end

return true, host.to_i
rescue => e
LOG_ERROR "Error ocurred while Reinstall: #{e.message}"
raise e
end

# Creates new virtual machine from the given OS template and resize it to given specs, and new user account, which becomes owner of this VM
# @param [Hash] params - all needed data for new User and VM creation
# @option params [String] :login Username for new OpenNebula account
Expand Down Expand Up @@ -253,8 +293,7 @@ def CreateVMwithSpecs(params, trace = ["#{__method__} method called:#{__LINE__}"
LOG_DEBUG "No vCenter configuration found"
end

params['username'] = params['username'] || 'Administrator'
params['vm_name'] = params['vm_name'] || "#{params['login']}_vm"
params['vm_name'] = params['vm_name'] || "#{params['login']}_vm"
###################### Doing some important system stuff ###############################################################

LOG_AUTO "CreateVMwithSpecs for #{params['login']} Order Accepted! #{params['trial'] == true ? "VM is Trial" : nil}"
Expand Down Expand Up @@ -302,6 +341,7 @@ def CreateVMwithSpecs(params, trace = ["#{__method__} method called:#{__LINE__}"
trace << "Creating new VM:#{__LINE__ + 1}"
onblock(:t, params['templateid']) do | t |
t.info!
params['username'] = params['username'] || (t.win? ? 'Administrator' : 'root')
specs = ""
if !t['/VMTEMPLATE/TEMPLATE/CAPACITY'] && t['/VMTEMPLATE/TEMPLATE/HYPERVISOR'].upcase == "VCENTER" then
specs = {
Expand Down Expand Up @@ -381,7 +421,6 @@ def CreateVMwithSpecs(params, trace = ["#{__method__} method called:#{__LINE__}"
end

if %w(VCENTER KVM).include? params['extra']['type'].upcase then
win = onblock(:t, params['templateid']).win?
LOG_DEBUG "Instantiating VM as#{win ? nil : ' not'} Windows"
trace << "Setting VM context:#{__LINE__ + 2}"
begin
Expand All @@ -391,7 +430,7 @@ def CreateVMwithSpecs(params, trace = ["#{__method__} method called:#{__LINE__}"
NETWORK: "YES",
PASSWORD: params['passwd'],
SSH_PUBLIC_KEY: "$USER[SSH_PUBLIC_KEY]",
USERNAME: win ? params['username'] : nil
USERNAME: params['username']
}
}.to_one_template
)
Expand Down
10 changes: 10 additions & 0 deletions lib/std++/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def to_sym!
def to_s!
self.keys.each do |key|
self[key.to_s] = self.delete key if key.class != String
if self[key.to_s].class == Hash then
self[key.to_s].to_s!
end
end
self
end
Expand Down Expand Up @@ -122,6 +125,13 @@ def self.from_one_template tmpl
end
res
end

# Generic #merge method better version
def deep_merge(second)
merger = proc { | _, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
self.merge(second, &merger)
end

# @!endgroup
end

Expand Down
2 changes: 2 additions & 0 deletions lib/vmcontrol/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def Terminate(userid, vmid)
return 1
elsif userid == 0 then
LOG "Terminate query rejected! Tryed to delete root-user(oneadmin)", "Terminate"
return 1
end
Delete(userid)
LOG "Terminating VM#{vmid}", "Terminate"
Expand Down Expand Up @@ -223,6 +224,7 @@ def Release(vmid)
def Delete(userid)
if userid == 0 then
LOG "Delete query rejected! Tryed to delete root-user(oneadmin)", "Delete"
return
end
LOG "Deleting User ##{userid}", "Delete"
onblock(:u, userid).delete
Expand Down
10 changes: 10 additions & 0 deletions lib/vminfo/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ def get_user_vms
r = VirtualMachinePool.new(@client, -1).get_hash['VM_POOL']
r.empty? ? [] : r['VM']
end
# Returns all @client User vms with extended info
# @return [Array<Hash>]
def get_user_vms_ext
u = onblock(:u, -1, @client)
r = u.info!

raise r if OpenNebula.is_error? r

u.vms $db
end

# @!endgroup
end
3 changes: 2 additions & 1 deletion lib/vntools/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def reserve_public_ip params
end
end

vn = onblock(:vn, uvnet, @client)
vn = onblock(:vn, uvnet, $client)
vn.chown(u.id, u.groups.first)
vn.chmod(1, 1, 1, 0, 0, 0, 0, 0, 0)
return vn.id
end

Expand Down
2 changes: 1 addition & 1 deletion meta/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.2 - testing
v1.0.2 - stable
5 changes: 4 additions & 1 deletion rake/configure_nginx.rake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ end
desc "Configure Nginx"
task :configure_nginx => [:before, :useful_questions] do
cd @src_dir

if @nginx == 'n' then
puts "Skipping nginx configuration..."
return
end
puts
print "Do you want installer to generate self-signed cert? (y/n) "
cert = @silent
Expand Down
Loading

0 comments on commit 47c4876

Please sign in to comment.