Class: Y2Network::S390DeviceActivator

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Yast::Logger
Defined in:
src/lib/y2network/s390_device_activator.rb

Overview

This class is responsable of activating the supported S390 devices.

Constant Summary collapse

CONFIGURE_CMD =

Command for configuring z Systems specific devices

"/sbin/chzdev".freeze
LIST_CMD =

Command for displaying configuration of z Systems specific devices

"/sbin/lszdev".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(builder) ⇒ S390DeviceActivator

Constructor


51
52
53
# File 'src/lib/y2network/s390_device_activator.rb', line 51

def initialize(builder)
  @builder = builder
end

Instance Attribute Details

#builderObject

Returns the value of attribute builder


36
37
38
# File 'src/lib/y2network/s390_device_activator.rb', line 36

def builder
  @builder
end

Class Method Details

.for(builder) ⇒ Object

Load fresh instace of device activator for given interface config builder


39
40
41
42
43
44
45
46
# File 'src/lib/y2network/s390_device_activator.rb', line 39

def self.for(builder)
  type = builder.type
  require "y2network/s390_device_activators/#{type.file_name}"
  S390DeviceActivators.const_get(type.class_name).new(builder)
rescue LoadError => e
  log.info "Specialized device activator for #{type.short_name} not found. #{e.inspect}"
  nil
end

Instance Method Details

#configureBoolean

It tries to enable the interface with the configured device id


94
95
96
97
98
99
100
# File 'src/lib/y2network/s390_device_activator.rb', line 94

def configure
  return false unless device_id
  cmd = [CONFIGURE_CMD, type.short_name, device_id, "-e"].concat(configure_attributes)

  log.info("Activating s390 device: #{device_id}")
  Yast::Execute.on_target!(*cmd, allowed_exitstatus: 0..255).zero?
end

#configure_attributesArray<String>

Each s390 device type permits a set of attributes to be passed as extra options to the configuration command. This method return a list of each option in the form "attribute=value"

Examples:

qeth options

@activator.configure_attributes
#=> ["bridge_role=primary", "layer2=1", "portno=0", "ipa_takeover/enable=1"]

ctc options

@activator.configure_attributes
#=> ["protocol=1"]

68
69
70
# File 'src/lib/y2network/s390_device_activator.rb', line 68

def configure_attributes
  []
end

#configured_interfaceString

Obtains the enabled interface name associated with the device id


105
106
107
108
109
110
# File 'src/lib/y2network/s390_device_activator.rb', line 105

def configured_interface
  return "" unless device_id
  cmd = [LIST_CMD, device_id, "-c", "names", "-n"]

  Yast::Execute.stdout.on_target!(cmd).chomp
end

#device_idString?

The device id to be used by lszdev or chzdev commands


75
76
77
# File 'src/lib/y2network/s390_device_activator.rb', line 75

def device_id
  nil
end

#device_id_from(channel) ⇒ String

Returns the complete device id which contains the given channel


83
84
85
86
87
88
89
# File 'src/lib/y2network/s390_device_activator.rb', line 83

def device_id_from(channel)
  cmd = [LIST_CMD, type.short_name, "-c", "id", "-n"]

  Yast::Execute.stdout.on_target!(cmd).split("\n").find do |d|
    d.include? channel
  end
end

#propose!Object

Makes a new configuration proposal


113
114
# File 'src/lib/y2network/s390_device_activator.rb', line 113

def propose!
end