Class | VirtP2V::NetworkDevice |
In: |
lib/virt-p2v/netdevice.rb
lib/virt-p2v/netdevice.rb |
Parent: | Object |
CONNECTION | = | 'org.freedesktop.NetworkManagerSettings.Connection'.freeze | Some NetworkManager names, for convenience | |
DEVICE | = | 'org.freedesktop.NetworkManager.Device'.freeze | ||
NETWORKMANAGER | = | 'org.freedesktop.NetworkManager'.freeze | ||
PROPERTIES | = | 'org.freedesktop.DBus.Properties'.freeze | ||
SETTINGS | = | 'org.freedesktop.NetworkManagerSettings'.freeze | ||
WIRED | = | 'org.freedesktop.NetworkManager.Device.Wired'.freeze | ||
TYPE_UNKNOWN | = | 0 | NetworkManager device types projects.gnome.org/NetworkManager/developers/spec-08.html | |
TYPE_ETHERNET | = | 1 | ||
TYPE_WIFI | = | 2 | ||
TYPE_GSM | = | 3 | ||
TYPE_CDMA | = | 4 | ||
STATE_UNKNOWN | = | 0 | NetworkManager device states | |
STATE_UNMANAGED | = | 1 | ||
STATE_UNAVAILABLE | = | 2 | ||
STATE_DISCONNECTED | = | 3 | ||
STATE_PREPARE | = | 4 | ||
STATE_CONFIG | = | 5 | ||
STATE_NEED_AUTH | = | 6 | ||
STATE_IP_CONFIG | = | 7 | ||
STATE_ACTIVATED | = | 8 | ||
STATE_FAILED | = | 9 | ||
STATES | = | { 0 => 'Unknown'.freeze, # For completeness 1 => 'Unmanaged'.freeze, # For completeness 2 => 'No cable connected'.freeze, 3 => 'Not connected'.freeze, 4 => 'Preparing to connect'.freeze, 5 => 'Configuring'.freeze, 6 => 'Waiting for authentication'.freeze, 7 => 'Obtaining an IP address'.freeze, 8 => 'Connected'.freeze, 9 => 'Connection failed'.freeze | Human readable descriptions of NetworkManager Device States | |
CONNECTION | = | 'org.freedesktop.NetworkManagerSettings.Connection'.freeze | Some NetworkManager names, for convenience | |
DEVICE | = | 'org.freedesktop.NetworkManager.Device'.freeze | ||
NETWORKMANAGER | = | 'org.freedesktop.NetworkManager'.freeze | ||
PROPERTIES | = | 'org.freedesktop.DBus.Properties'.freeze | ||
SETTINGS | = | 'org.freedesktop.NetworkManagerSettings'.freeze | ||
WIRED | = | 'org.freedesktop.NetworkManager.Device.Wired'.freeze | ||
TYPE_UNKNOWN | = | 0 | NetworkManager device types projects.gnome.org/NetworkManager/developers/spec-08.html | |
TYPE_ETHERNET | = | 1 | ||
TYPE_WIFI | = | 2 | ||
TYPE_GSM | = | 3 | ||
TYPE_CDMA | = | 4 | ||
STATE_UNKNOWN | = | 0 | NetworkManager device states | |
STATE_UNMANAGED | = | 1 | ||
STATE_UNAVAILABLE | = | 2 | ||
STATE_DISCONNECTED | = | 3 | ||
STATE_PREPARE | = | 4 | ||
STATE_CONFIG | = | 5 | ||
STATE_NEED_AUTH | = | 6 | ||
STATE_IP_CONFIG | = | 7 | ||
STATE_ACTIVATED | = | 8 | ||
STATE_FAILED | = | 9 | ||
STATES | = | { 0 => 'Unknown'.freeze, # For completeness 1 => 'Unmanaged'.freeze, # For completeness 2 => 'No cable connected'.freeze, 3 => 'Not connected'.freeze, 4 => 'Preparing to connect'.freeze, 5 => 'Configuring'.freeze, 6 => 'Waiting for authentication'.freeze, 7 => 'Obtaining an IP address'.freeze, 8 => 'Connected'.freeze, 9 => 'Connection failed'.freeze | Human readable descriptions of NetworkManager Device States |
activated | [R] | |
activated | [R] | |
connected | [R] | |
connected | [R] | |
mac | [R] | |
mac | [R] | |
name | [R] | |
name | [R] | |
state | [R] | |
state | [R] |
# File lib/virt-p2v/netdevice.rb, line 94 94: def self.add_listener(cb) 95: @@listeners.push(cb) 96: end
# File lib/virt-p2v/netdevice.rb, line 94 94: def self.add_listener(cb) 95: @@listeners.push(cb) 96: end
# File lib/virt-p2v/netdevice.rb, line 66 66: def initialize(obj, device, props) 67: device.default_iface = WIRED 68: 69: @nm_obj = obj 70: @name = props.Get(DEVICE, 'Interface')[0] 71: @mac = props.Get(WIRED, 'HwAddress')[0] 72: state = props.Get(DEVICE, 'State')[0] 73: 74: # Lookup by name 75: @@devices[@name] = self 76: 77: state_updated(state) 78: 79: # Register a listener for state changes 80: device.on_signal('PropertiesChanged') { |props| 81: if props.has_key?('State') then 82: state_updated(props['State']) 83: 84: # Notify registered state change handlers 85: @@listeners.each { |cb| cb.call(self) } 86: end 87: } 88: end
# File lib/virt-p2v/netdevice.rb, line 66 66: def initialize(obj, device, props) 67: device.default_iface = WIRED 68: 69: @nm_obj = obj 70: @name = props.Get(DEVICE, 'Interface')[0] 71: @mac = props.Get(WIRED, 'HwAddress')[0] 72: state = props.Get(DEVICE, 'State')[0] 73: 74: # Lookup by name 75: @@devices[@name] = self 76: 77: state_updated(state) 78: 79: # Register a listener for state changes 80: device.on_signal('PropertiesChanged') { |props| 81: if props.has_key?('State') then 82: state_updated(props['State']) 83: 84: # Notify registered state change handlers 85: @@listeners.each { |cb| cb.call(self) } 86: end 87: } 88: end
# File lib/virt-p2v/netdevice.rb, line 102 102: def activate(auto, ip, prefix, gateway, dns) 103: # Get an IP config dependent on whether ip is IPv4 or IPv6 104: ip_config = auto ? get_config_auto : 105: ip.ipv4? ? get_config_ipv4(ip, prefix, gateway, dns) : 106: get_config_ipv6(ip, prefix, gateway, dns) 107: 108: # Create a new NetworkManager connection object 109: settings = @@nm_service.object( 110: '/org/freedesktop/NetworkManagerSettings') 111: settings.introspect() 112: settings.default_iface = SETTINGS 113: 114: uuid = `uuidgen`.chomp 115: settings.AddConnection( 116: 'connection' => { 117: 'uuid' => uuid, 118: 'id' => 'P2V', 119: 'type' => '802-3-ethernet', 120: 'autoconnect' => false 121: }, 122: '802-3-ethernet' => {}, 123: 'ipv4' => ip_config['ipv4'], 124: 'ipv6' => ip_config['ipv6'] 125: ) 126: 127: # Find the connection we just created 128: # XXX: There must be a better way to get this! 129: conn = settings.ListConnections()[0].each { |i| 130: conn = @@nm_service.object(i) 131: conn.introspect 132: conn.default_iface = CONNECTION 133: 134: break i if conn.GetSettings()[0]['connection']['uuid'] == uuid 135: } 136: # XXX: mbooth@redhat.com - 22/7/2011 137: # The first time this code runs on a RHEL 6 system 138: # (NetworkManager-0.8.1-9.el6_1.1.i686), conn will be an 139: # array containing a single element: the connection. This will cause 140: # ActivateConnection below to return an error, and the p2v client to 141: # crash. If you run p2v client a second time, conn will be a simple 142: # value, not a single element array, and ActivateConnection works fine. 143: # I assume this is a bug in NetworkManager. I don't see this behaviour 144: # in F14. 145: conn = conn[0] if conn.kind_of?(Array) 146: 147: nm = @@nm_service.object('/org/freedesktop/NetworkManager') 148: nm.introspect 149: nm.default_iface = NETWORKMANAGER 150: nm.ActivateConnection('org.freedesktop.NetworkManagerSystemSettings', 151: conn, @nm_obj, '/') 152: end
# File lib/virt-p2v/netdevice.rb, line 102 102: def activate(auto, ip, prefix, gateway, dns) 103: # Get an IP config dependent on whether ip is IPv4 or IPv6 104: ip_config = auto ? get_config_auto : 105: ip.ipv4? ? get_config_ipv4(ip, prefix, gateway, dns) : 106: get_config_ipv6(ip, prefix, gateway, dns) 107: 108: # Create a new NetworkManager connection object 109: settings = @@nm_service.object( 110: '/org/freedesktop/NetworkManagerSettings') 111: settings.introspect() 112: settings.default_iface = SETTINGS 113: 114: uuid = `uuidgen`.chomp 115: settings.AddConnection( 116: 'connection' => { 117: 'uuid' => uuid, 118: 'id' => 'P2V', 119: 'type' => '802-3-ethernet', 120: 'autoconnect' => false 121: }, 122: '802-3-ethernet' => {}, 123: 'ipv4' => ip_config['ipv4'], 124: 'ipv6' => ip_config['ipv6'] 125: ) 126: 127: # Find the connection we just created 128: # XXX: There must be a better way to get this! 129: conn = settings.ListConnections()[0].each { |i| 130: conn = @@nm_service.object(i) 131: conn.introspect 132: conn.default_iface = CONNECTION 133: 134: break i if conn.GetSettings()[0]['connection']['uuid'] == uuid 135: } 136: # XXX: mbooth@redhat.com - 22/7/2011 137: # The first time this code runs on a RHEL 6 system 138: # (NetworkManager-0.8.1-9.el6_1.1.i686), conn will be an 139: # array containing a single element: the connection. This will cause 140: # ActivateConnection below to return an error, and the p2v client to 141: # crash. If you run p2v client a second time, conn will be a simple 142: # value, not a single element array, and ActivateConnection works fine. 143: # I assume this is a bug in NetworkManager. I don't see this behaviour 144: # in F14. 145: conn = conn[0] if conn.kind_of?(Array) 146: 147: nm = @@nm_service.object('/org/freedesktop/NetworkManager') 148: nm.introspect 149: nm.default_iface = NETWORKMANAGER 150: nm.ActivateConnection('org.freedesktop.NetworkManagerSystemSettings', 151: conn, @nm_obj, '/') 152: end