Class: Vagrant::Node::ClientController
- Inherits:
-
Object
- Object
- Vagrant::Node::ClientController
- Defined in:
- lib/vagrant-node/clientcontroller.rb
Class Method Summary collapse
- .authorized?(token, challenge) ⇒ Boolean
-
.backup_log(vmname = nil) ⇒ Object
BACKUP LOG METHOD ###############.
-
.box_add(box, url, user = "guest", pass = "--no-pass") ⇒ Object
BOX ADD METHOD #######################.
-
.box_delete(box, provider) ⇒ Object
BOX DELETE METHOD #####################.
-
.cleardownloadboxes ⇒ Object
CLEAR BOX DOWNLOADS METHOD ##################.
-
.config_show ⇒ Object
CONFIG SHOW METHOD #####################.
-
.config_upload(cfile) ⇒ Object
CONFIG UPLOAD METHOD #####################.
- .execute_queued ⇒ Object
-
.listboxes ⇒ Object
BOX LIST METHOD #######################.
-
.listdownloadboxes ⇒ Object
BOX DOWNLOADS METHOD ##################.
-
.nodeinfo ⇒ Object
NODE INFO (CPU,MEMORY) ################.
-
.operation_queued(id) ⇒ Object
OPERATION METHODS #######################.
- .operation_queued_last ⇒ Object
-
.password_change(new_password) ⇒ Object
NODE PASSWORD CHANGE ###################.
- .send_challenge ⇒ Object
-
.vm_add(config, rename) ⇒ Object
VIRTUAL MACHINE ADD METHOD ###############.
-
.vm_confirmed_destroy(vmname) ⇒ Object
VIRTUAL MACHINE DESTROY METHOD ###############.
-
.vm_delete(vmname, remove = false) ⇒ Object
VIRTUAL MACHINE DELETE METHOD ###############.
-
.vm_halt(vmname, force) ⇒ Object
VIRTUAL MACHINE HALT METHOD #################.
-
.vm_info(vmname) ⇒ Object
VIRTUAL MACHINE INFO METHOD ###############.
-
.vm_provision(vmname) ⇒ Object
VIRTUAL MACHINE PROVISION METHOD ##################.
-
.vm_resume(vmname) ⇒ Object
VIRTUAL MACHINE RESUME METHOD ##################.
-
.vm_snapshot_delete(vmname, snapshot_id) ⇒ Object
VIRTUAL MACHINE SNAPSHOT DELETE METHOD #############.
-
.vm_snapshot_restore(vmname, snapshot_id) ⇒ Object
VIRTUAL MACHINE SNAPSHOT RESTORE METHOD #############.
-
.vm_snapshot_take(vmname, name, desc = " ") ⇒ Object
VIRTUAL MACHINE SNAPSHOT TAKE METHOD #############.
-
.vm_snapshot_take_file(vmname) ⇒ Object
VIRTUAL MACHINE BACKUP TAKE METHOD #############.
-
.vm_snapshots(vmname = nil) ⇒ Object
VIRTUAL MACHINE SNAPSHOT LIST METHOD #############.
-
.vm_ssh_config(vmname) ⇒ Object
VIRTUAL MACHINE SSHCONFIG## ###############.
-
.vm_status(vmname = nil, verbose = true) ⇒ Object
VIRTUAL MACHINE STATUS METHOD ###############.
-
.vm_suspend(vmname) ⇒ Object
VIRTUAL MACHINE SUSPEND METHOD ##################.
-
.vm_up(vmname) ⇒ Object
VIRTUAL MACHINE UP METHOD ##################.
Class Method Details
.authorized?(token, challenge) ⇒ Boolean
58 59 60 61 62 |
# File 'lib/vagrant-node/clientcontroller.rb', line 58 def self.(token,challenge) ensure_environment @pw.(token,challenge) end |
.backup_log(vmname = nil) ⇒ Object
BACKUP LOG METHOD ###############
FIXME No está controlado el que el parámetro sea nil
970 971 972 973 974 975 976 977 978 979 980 981 |
# File 'lib/vagrant-node/clientcontroller.rb', line 970 def self.backup_log(vmname=nil) ensure_environment #begin @db.get_backup_log_entries(vmname) # rescue => e # puts e.message # end end |
.box_add(box, url, user = "guest", pass = "--no-pass") ⇒ Object
BOX ADD METHOD #######################
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/vagrant-node/clientcontroller.rb', line 183 def self.box_add(box,url,user="guest",pass="--no-pass") @env.boxes.all.each do |box_name,provider| if box_name==box raise RestException.new(500,"There is a box with the same name") end end command_block = Proc.new { #ensure_environment boxes = [] #TODO # Get the provider if one was set provider = nil # provider = options[:provider].to_sym if options[:provider] begin #uri = "\\\\155.54.190.227\\boxtmp\\boxes\\debian_squeeze_32.box" # # if uri=~ /^\\\\(.*?)\\(.*?)\\(.*?)$/ # puts "EL HOST ES #{$1}" # puts "EL Share ES #{$2}" # puts "EL PATH ES #{$3}" # host = $1 # share = $2 # path = $3 # # Getting and checking box file # boxname=File.basename(path.gsub('\\',File::SEPARATOR)) # # raise 'Box file format not supported' if File.extname(boxname)!=".box" # # samba = nil # begin # samba = Sambal::Client.new( :host => host, # :share => share, # :user => user, # :password => pass) # # # # Get the tmp file name # temp_path = @env.tmp_path.join("box" + Time.now.to_i.to_s) # # # response = nil # # smbclient //155.54.190.227/boxtmp --no-pass -W WORKGROUP -U guest -p 445 # smbclient //155.54.190.227/boxtmp -D boxes -c "get debian_squeeze_321.box" -N # # command="smbclient //#{host}/#{share} -D #{dirlocation} -c \"get #{boxname}\" -U #{user} --no-pass" # # # FIXME encontrar si existe algún tipo de notificación por # interrupciónde la descarga # FIXME a little hack beacuse in version 0.1.2 of sambal there is # a timeout that close the download after 10 seconds # def samba.ask(cmd) # @i.printf("#{cmd}\n") # response = @o.expect(/^smb:.*\\>/)[0] # end # # response = samba.get(path, temp_path.to_s) # FIXME DELETE # pp response.inspect # # raise response.message if !response.success? # # if response.success? # File download succesfully # added_box = nil # begin # provider=nil # force = true # added_box = @env.boxes.add(temp_path,box,nil,force) # boxes << {:name=>box,:provider=>added_box.provider.to_s} # rescue Vagrant::Errors::BoxUpgradeRequired # Upgrade the box # env.boxes.upgrade(box) # # Try adding it again # retry # rescue Exception => e # boxes = nil # end # # end # # rescue Exception => e # puts "EXCEPCION de descarga" if response # puts "EXCEPCION de conexion" if !response # puts e.message # boxes=nil # end # # # Closing connection # samba.close if samba # # # Cleaning # if temp_path && File.exist?(temp_path) # File.unlink(temp_path) # end # # # else copy_db = @db.clone boxes <<{:name=>box} # FIXME Ver qué poner en los parámetros de la llamada provider=nil force = true # Always overwrite box if exists insecure = true #Don't validate SSL certs #Calling original box add action @env.action_runner.run(BoxAddAction, { :box_name => box, :box_provider => provider, :box_url => url, :box_force => force, :box_download_insecure => insecure, :db => copy_db, }) # @env.action_runner.run(Vagrant::Action.action_box_add, { # :box_name => box, # :box_provider => provider, # :box_url => url, # :box_force => force, # :box_download_insecure => insecure, # }) # end boxes rescue =>e puts e. end } method("execute_queued").call(&command_block); end |
.box_delete(box, provider) ⇒ Object
BOX DELETE METHOD #####################
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/vagrant-node/clientcontroller.rb', line 150 def self.box_delete(box,provider) ensure_environment boxes = [] bbox = @env.boxes.find(box,provider.to_sym) if (bbox) get_vms("").each do |machine| if (!machine.box.nil? && machine.box.name==box) raise RestException.new(500,"The box can't be deleted because the virtual machine '#{machine.name.to_s}' is using it") end end boxes << bbox.name bbox.destroy! else raise RestException.new(404,"The box '#{box}' does not exist") end boxes end |
.cleardownloadboxes ⇒ Object
CLEAR BOX DOWNLOADS METHOD ##################
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/vagrant-node/clientcontroller.rb', line 113 def self.cleardownloadboxes ensure_environment @db.clear_box_downloads true end |
.config_show ⇒ Object
CONFIG SHOW METHOD #####################
987 988 989 990 991 |
# File 'lib/vagrant-node/clientcontroller.rb', line 987 def self.config_show ensure_environment file = @env.root_path+"Vagrantfile" end |
.config_upload(cfile) ⇒ Object
CONFIG UPLOAD METHOD #####################
996 997 998 999 1000 1001 1002 1003 1004 |
# File 'lib/vagrant-node/clientcontroller.rb', line 996 def self.config_upload(cfile) ensure_environment f = File.new(@env.root_path+"Vagrantfile", "w") f.write(cfile) f.close true end |
.execute_queued ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vagrant-node/clientcontroller.rb', line 30 def self.execute_queued ensure_environment #Generating a random identifier for process rpid=rand(1000000) pid = fork do begin @db.create_queued_process(rpid) res = yield @db.set_queued_process_result(rpid,res.to_json) rescue Exception => e @db.set_queued_process_error(rpid,e) end end rpid end |
.listboxes ⇒ Object
BOX LIST METHOD #######################
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/vagrant-node/clientcontroller.rb', line 129 def self.listboxes ensure_environment boxes = @env.boxes.all.sort fboxes = Array.new boxes.each do |name, provider| fboxes << {"name" => name,"provider" => provider} end fboxes end |
.listdownloadboxes ⇒ Object
BOX DOWNLOADS METHOD ##################
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/vagrant-node/clientcontroller.rb', line 90 def self.listdownloadboxes ensure_environment downloads = @db.get_box_download fdownloads = Array.new downloads.each do |row| fdownloads << {"box_name" => row["box_name"],"box_url" => row["box_url"],"box_progress" => row["download_progress"],"box_remaining" => row["download_remaining"],"download_status" => row["download_status"]} end fdownloads end |
.nodeinfo ⇒ Object
NODE INFO (CPU,MEMORY) ################
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vagrant-node/clientcontroller.rb', line 67 def self.nodeinfo usw = Usagewatch Facter.loadfacts result=Hash[Facter.to_hash.map{|(k,v)| [k.to_sym,v]}] result[:cpuaverage] = Sys::CPU.load_avg; result[:diskusage] = usw.uw_diskused result end |
.operation_queued(id) ⇒ Object
OPERATION METHODS #######################
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 |
# File 'lib/vagrant-node/clientcontroller.rb', line 1009 def self.operation_queued(id) ensure_environment result = @db.get_queued_process_result(id) raise RestException.new(404,"The operation ID: #{id} not found") if (result.size==0) opres = Array.new aux=result.first opres[0]=aux["operation_status"] opres[1]=aux["operation_result"] opres end |
.operation_queued_last ⇒ Object
1026 1027 1028 1029 1030 1031 |
# File 'lib/vagrant-node/clientcontroller.rb', line 1026 def self.operation_queued_last ensure_environment @db.get_queued_last end |
.password_change(new_password) ⇒ Object
NODE PASSWORD CHANGE ###################
959 960 961 962 963 964 |
# File 'lib/vagrant-node/clientcontroller.rb', line 959 def self.password_change(new_password) ensure_environment @db.node_password_set(new_password,true) true end |
.send_challenge ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/vagrant-node/clientcontroller.rb', line 50 def self.send_challenge challenge = SecureRandom.urlsafe_base64(nil, false) = SecureRandom.urlsafe_base64(nil, false) {:cookie => , :challenge => challenge} end |
.vm_add(config, rename) ⇒ Object
VIRTUAL MACHINE ADD METHOD ###############
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'lib/vagrant-node/clientcontroller.rb', line 414 def self.vm_add(config,rename) ensure_environment begin path="/tmp/conf."+Time.now.to_i.to_s f = File.new(path, "w") f.write(config) f.close cm = ConfigManager.new(@env.root_path+"Vagrantfile") cmtmp = ConfigManager.new(path) current_vms = @env.machine_names cmtmp.get_vm_names.each do |key| if current_vms.include?(key) raise RestException.new(406,"There is a remote VM with the same name: \"#{key}\"") if rename=="false" cmtmp.rename_vm(key,"#{key}_1") end end cm.insert_vms_sexp(cmtmp.extract_vms_sexp) rescue => e raise e ensure File.delete(path) end end |
.vm_confirmed_destroy(vmname) ⇒ Object
VIRTUAL MACHINE DESTROY METHOD ###############
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/vagrant-node/clientcontroller.rb', line 474 def self.vm_confirmed_destroy(vmname) ensure_environment machine_names = [] #begin get_vms(vmname.to_sym).each do |machine| machine_names << machine.name machine.action(:destroy, :force_confirm_destroy => true) end machine_names #rescue => e # return nil #end end |
.vm_delete(vmname, remove = false) ⇒ Object
VIRTUAL MACHINE DELETE METHOD ###############
457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/vagrant-node/clientcontroller.rb', line 457 def self.vm_delete(vmname,remove=false) ensure_environment cm = ConfigManager.new(@env.root_path+"Vagrantfile") self.vm_confirmed_destroy(vmname) if remove!=false cm.delete_vm(vmname) true end |
.vm_halt(vmname, force) ⇒ Object
VIRTUAL MACHINE HALT METHOD #################
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
# File 'lib/vagrant-node/clientcontroller.rb', line 498 def self.vm_halt(vmname,force) force=(force=="true")?true:false; command_block = Proc.new { begin machine_names = [] get_vms(vmname).each do |machine| machine.action(:halt, :force_halt => force) machine_names << {"vmname" => machine.name.to_s, "provider" => machine.provider_name.to_s, "status" => machine.state.short_description} end raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?) machine_names rescue Exception => e aux=get_vms(vmname) machine=aux[0] raise RestException.new(404,"The machine #{vmname} does not exist") if (aux.empty?) raise VMActionException.new(machine.name.to_s,machine.provider_name.to_s,e.) if (!machine.nil?) end } method("execute_queued").call(&command_block); #rescue => e # return nil #end end |
.vm_info(vmname) ⇒ Object
VIRTUAL MACHINE INFO METHOD ###############
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'lib/vagrant-node/clientcontroller.rb', line 539 def self.vm_info(vmname) raise RestException.new(500,"The VM Name can't be emtpy") if vmname.empty? ensure_environment #execute("snapshot",self.uuid,"showvminfo",name) machines=get_vms(vmname) raise RestException.new(404,"The machine #{vmname} does not exist") if (machines.empty?) info = Hash.new if (machines[0].id!=nil) machines[0].provider.driver.execute("showvminfo",machines[0].id,"--machinereadable").split("\n").each do |line| if (line =~ /^(.*?)=\"(.*?)\"$/) || (line =~ /^(.*?)=(.*?)$/) info[$1]=$2 end end end info end |
.vm_provision(vmname) ⇒ Object
VIRTUAL MACHINE PROVISION METHOD ##################
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
# File 'lib/vagrant-node/clientcontroller.rb', line 855 def self.vm_provision(vmname) #ensure_environment command_block = Proc.new { machine_names = [] # Por ahora no dejo que el vmname esté vacío para realizar la operación sobre todas las vm raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?) #begin #Provisioning get_vms(vmname).each do |machine| machine_names << machine.name machine.action(:provision) end raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?) machine_names } method("execute_queued").call(&command_block); end |
.vm_resume(vmname) ⇒ Object
VIRTUAL MACHINE RESUME METHOD ##################
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 |
# File 'lib/vagrant-node/clientcontroller.rb', line 646 def self.vm_resume(vmname) command_block = Proc.new { #ensure_environment begin machine_names = [] #Launching machines get_vms(vmname).each do |machine| machine.action(:resume) machine_names << {"vmname" => machine.name.to_s, "provider" => machine.provider_name.to_s, "status" => machine.state.short_description} end raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?) machine_names rescue Exception => e aux=get_vms(vmname) machine=aux[0] raise RestException.new(404,"The machine #{vmname} does not exist") if (aux.empty?) raise VMActionException.new(machine.name.to_s,machine.provider_name.to_s,e.) if (!machine.nil?) end } method("execute_queued").call(&command_block); end |
.vm_snapshot_delete(vmname, snapshot_id) ⇒ Object
VIRTUAL MACHINE SNAPSHOT DELETE METHOD #############
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 |
# File 'lib/vagrant-node/clientcontroller.rb', line 769 def self.vm_snapshot_delete(vmname,snapshot_id) ensure_environment #begin raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?) get_vms(vmname).each do |machine| env = { :machine => machine, :machine_action => SnapshotAction::DELETE, :snapshot_id => snapshot_id, } # # res = @env.action_runner.run(SnapshotAction,env) # return res[:delete_snapshot] # end # # rescue => e # puts e.message # # return nil # end end |
.vm_snapshot_restore(vmname, snapshot_id) ⇒ Object
VIRTUAL MACHINE SNAPSHOT RESTORE METHOD #############
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 |
# File 'lib/vagrant-node/clientcontroller.rb', line 806 def self.vm_snapshot_restore(vmname,snapshot_id) command_block = Proc.new { #ensure_environment raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?) restore_results = {} get_vms(vmname).each do |machine| prev_state=machine.state.id #First, ensure that the machine is in a proper state #to restore the snapshot (save, poweroff) machine.action(:suspend) if prev_state==:running #Now the machine is ready for restoration env = { :machine => machine, :machine_action => SnapshotAction::RESTORE, :snapshot_id => snapshot_id } res = @env.action_runner.run(SnapshotAction,env) #Now restore the vm to the previous state if running machine.action(:up) if prev_state==:running restore_results[machine.name.to_sym]=res[:restore_result] end restore_results } method("execute_queued").call(&command_block); end |
.vm_snapshot_take(vmname, name, desc = " ") ⇒ Object
VIRTUAL MACHINE SNAPSHOT TAKE METHOD #############
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 |
# File 'lib/vagrant-node/clientcontroller.rb', line 717 def self.vm_snapshot_take(vmname,name,desc=" ") command_block = Proc.new { #ensure_environment raise RestException.new(404,"Virtual Machine not specified") if (vmname==nil ||vmname.empty?) machine = get_vms(vmname) raise RestException.new(404,"Virtual Machine not found") if (machine.empty?) env = { :machine => machine.first, :machine_action => SnapshotAction::TAKE, :snapshot_name => name, :snapshot_desc => desc } res = @env.action_runner.run(SnapshotAction,env) res[:last_snapshot] # get_vms(vmname).each do |machine| # env = # { # :machine => machine, # :machine_action => SnapshotAction::TAKE, # :snapshot_name => name, # :snapshot_desc => desc # } # # res = @env.action_runner.run(SnapshotAction,env) # # return res[:last_snapshot] # # end } method("execute_queued").call(&command_block); end |
.vm_snapshot_take_file(vmname) ⇒ Object
VIRTUAL MACHINE BACKUP TAKE METHOD #############
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 |
# File 'lib/vagrant-node/clientcontroller.rb', line 913 def self.vm_snapshot_take_file(vmname) ensure_environment current_machine = nil t = Time.now.strftime "%Y-%m-%d %H:%M:%S" begin machines=get_vms(vmname) return [404,"Virtual Machine not found"] if machines.empty? machines.each do |machine| current_machine = machine.name.to_s env = { :machine => machine, :machine_action => SnapshotAction::BACKUP, :path => @env.data_dir } @db.add_backup_log_entry(t,current_machine,BACKUP_IN_PROGRESS) res = @env.action_runner.run(SnapshotAction,env) if res[:bak_filename] == SnapshotAction::ERROR @db.update_backup_log_entry(t,current_machine,BACKUP_ERROR) return [500,"Internal Error"] if res[:bak_filename] == SnapshotAction::ERROR else @db.update_backup_log_entry(t,current_machine,BACKUP_SUCCESS) return [200,res[:bak_filename]] end end rescue => e @db.update_backup_log_entry(t,current_machine,BACKUP_ERROR) return [500,"Internal Error"] end end |
.vm_snapshots(vmname = nil) ⇒ Object
VIRTUAL MACHINE SNAPSHOT LIST METHOD #############
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
# File 'lib/vagrant-node/clientcontroller.rb', line 682 def self.vm_snapshots(vmname=nil) ensure_environment #begin snapshots = {} get_vms(vmname).each do |machine| env = { :machine => machine, :machine_action => SnapshotAction::LIST } res = @env.action_runner.run(SnapshotAction,env) snapshots[machine.name.to_sym]=res[:snapshots_list] end snapshots # rescue => e # puts e.message # # return nil # end end |
.vm_ssh_config(vmname) ⇒ Object
VIRTUAL MACHINE SSHCONFIG## ###############
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 |
# File 'lib/vagrant-node/clientcontroller.rb', line 887 def self.vm_ssh_config(vmname) ensure_environment #Ensure vmname exists and it is not empty return nil if vmname.empty? #begin info = Array.new get_vms(vmname).each do |machine| info << machine.ssh_info end info[0] # rescue => e # puts e.message # return nil #end end |
.vm_status(vmname = nil, verbose = true) ⇒ Object
VIRTUAL MACHINE STATUS METHOD ###############
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
# File 'lib/vagrant-node/clientcontroller.rb', line 571 def self.vm_status(vmname=nil,verbose=true) ensure_environment begin status = Array.new if (verbose==true || verbose=="true") get_vms(vmname).each do |machine| status << {"name" => machine.name.to_s, "status" => machine.state.short_description, "provider" => machine.provider_name} end else @env.machine_names.each do |machine| status << {"name" => machine.to_s} end end status rescue Exception => e raise e end end |
.vm_suspend(vmname) ⇒ Object
VIRTUAL MACHINE SUSPEND METHOD ##################
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
# File 'lib/vagrant-node/clientcontroller.rb', line 604 def self.vm_suspend(vmname) command_block = Proc.new { #ensure_environment begin machine_names = [] #Suspendiing machines get_vms(vmname).each do |machine| machine.action(:suspend) machine_names << {"vmname" => machine.name.to_s, "provider" => machine.provider_name.to_s, "status" => machine.state.short_description} end raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?) machine_names rescue Exception => e aux=get_vms(vmname) machine=aux[0] raise RestException.new(404,"The machine #{vmname} does not exist") if (aux.empty?) raise VMActionException.new(machine.name.to_s,machine.provider_name.to_s,e.) if (!machine.nil?) end } method("execute_queued").call(&command_block); end |
.vm_up(vmname) ⇒ Object
VIRTUAL MACHINE UP METHOD ##################
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/vagrant-node/clientcontroller.rb', line 352 def self.vm_up(vmname) command_block = Proc.new { machine_names = [] begin = {} [:parallel] = true #Launching machines @env.batch([:parallel]) do |batch| get_vms(vmname).each do |machine| batch.action(machine, :up, ) machine_names << {"vmname" => machine.name.to_s, "provider" => machine.provider_name.to_s, "status" => "running"} end end raise RestException.new(404,"The machine #{vmname} does not exist") if (machine_names.empty?) machine_names rescue Exception => e aux=get_vms(vmname) machine=aux[0] raise RestException.new(404,"The machine #{vmname} does not exist") if (aux.empty?) raise VMActionException.new(machine.name.to_s,machine.provider_name.to_s,e.) if (!machine.nil?) end } method("execute_queued").call(&command_block) end |