Class: Trema::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/trema/command.rb

Overview

trema command rubocop:disable ClassLength

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



18
19
20
# File 'lib/trema/command.rb', line 18

def controller
  @controller
end

Class Method Details

.unix_domain_socket(name, check = false) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/trema/command.rb', line 10

def self.unix_domain_socket(name, check = false)
  path = File.expand_path(File.join(Phut.socket_dir, "#{name}.ctl"))
  if check && !FileTest.socket?(path)
    raise "Socket file #{path} does not exist."
  end
  'drbunix:' + path
end

Instance Method Details

#fetch(name) ⇒ Object

FIXME



79
80
81
# File 'lib/trema/command.rb', line 79

def fetch(name)
  Phut::Vswitch.find_by(name: name) || Phut::Vhost.find_by(name: name)
end

#killallObject

rubocop:disable MethodLength rubocop:disable AbcSize



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/trema/command.rb', line 42

def killall
  @controller.logger.debug 'Shutting down...' if @controller
  @controller.stop
  @controller_thread.kill if @controller_thread
  @phut_run_thread.kill if @phut_run_thread
  Phut::Vswitch.destroy_all
  Phut::Vhost.destroy_all
  Phut::Netns.destroy_all
  Phut::Link.destroy_all
  FileUtils.rm pid_file if FileTest.exist?(pid_file)
  DRb.stop_service
  exit 0 if @options[:daemonize]
end

#port_down(switch_name, port) ⇒ Object



62
63
64
# File 'lib/trema/command.rb', line 62

def port_down(switch_name, port)
  Phut::Vswitch.find_by(name: switch_name).bring_port_down(port)
end

#port_up(switch_name, port) ⇒ Object

rubocop:enable MethodLength rubocop:enable AbcSize



58
59
60
# File 'lib/trema/command.rb', line 58

def port_up(switch_name, port)
  Phut::Vswitch.find_by(name: switch_name).bring_port_up(port)
end

#run(args, options) ⇒ Object

rubocop:disable MethodLength



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/trema/command.rb', line 21

def run(args, options)
  @args = args
  @options = options

  create_controller
  trap_signals
  create_pid_file
  start_phut

  if @options[:daemonize]
    run_as_daemon { start_controller_and_drb_threads }
  else
    start_controller_and_drb_threads
  end
rescue NoControllerDefined => e
  raise e, "#{ruby_file}: #{e.message}"
end

#vhostObject



70
71
72
# File 'lib/trema/command.rb', line 70

def vhost
  Phut::Vhost
end


74
75
76
# File 'lib/trema/command.rb', line 74

def vlink
  Phut::Link
end

#vswitchObject



66
67
68
# File 'lib/trema/command.rb', line 66

def vswitch
  Phut::Vswitch
end