Change-Id: I02bb308612816a0e1851be47c3d966d1592e6eb5
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/4871
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Sharath George
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,193 @@ |
0 |
+#!/bin/bash |
|
1 |
+ |
|
2 |
+# This example script creates bonding network devices based on synthetic NIC |
|
3 |
+# (the virtual network adapter usually provided by Hyper-V) and the matching |
|
4 |
+# VF NIC (SRIOV virtual function). So the synthetic NIC and VF NIC can |
|
5 |
+# function as one network device, and fail over to the synthetic NIC if VF is |
|
6 |
+# down. |
|
7 |
+# |
|
8 |
+# Usage: |
|
9 |
+# - After configured vSwitch and vNIC with SRIOV, start Linux virtual |
|
10 |
+# machine (VM) |
|
11 |
+# - Run this scripts on the VM. It will create configuration files in |
|
12 |
+# distro specific directory. |
|
13 |
+# - Reboot the VM, so that the bonding config are enabled. |
|
14 |
+# |
|
15 |
+# The config files are DHCP by default. You may edit them if you need to change |
|
16 |
+# to Static IP or change other settings. |
|
17 |
+# |
|
18 |
+ |
|
19 |
+sysdir=/sys/class/net |
|
20 |
+netvsc_cls={f8615163-df3e-46c5-913f-f2d2f965ed0e} |
|
21 |
+bondcnt=0 |
|
22 |
+ |
|
23 |
+# Detect Distro |
|
24 |
+if [ -f /etc/redhat-release ]; |
|
25 |
+then |
|
26 |
+ cfgdir=/etc/sysconfig/network-scripts |
|
27 |
+ distro=redhat |
|
28 |
+elif grep -q 'Ubuntu' /etc/issue |
|
29 |
+then |
|
30 |
+ cfgdir=/etc/network |
|
31 |
+ distro=ubuntu |
|
32 |
+elif grep -q 'SUSE' /etc/issue |
|
33 |
+then |
|
34 |
+ cfgdir=/etc/sysconfig/network |
|
35 |
+ distro=suse |
|
36 |
+else |
|
37 |
+ echo "Unsupported Distro" |
|
38 |
+ exit 1 |
|
39 |
+fi |
|
40 |
+ |
|
41 |
+echo Detected Distro: $distro, or compatible |
|
42 |
+ |
|
43 |
+# Get a list of ethernet names |
|
44 |
+list_eth=(`cd $sysdir && ls -d */ | cut -d/ -f1 | grep -v bond`) |
|
45 |
+eth_cnt=${#list_eth[@]} |
|
46 |
+ |
|
47 |
+echo List of net devices: |
|
48 |
+ |
|
49 |
+# Get the MAC addresses |
|
50 |
+for (( i=0; i < $eth_cnt; i++ )) |
|
51 |
+do |
|
52 |
+ list_mac[$i]=`cat $sysdir/${list_eth[$i]}/address` |
|
53 |
+ echo ${list_eth[$i]}, ${list_mac[$i]} |
|
54 |
+done |
|
55 |
+ |
|
56 |
+# Find NIC with matching MAC |
|
57 |
+for (( i=0; i < $eth_cnt-1; i++ )) |
|
58 |
+do |
|
59 |
+ for (( j=i+1; j < $eth_cnt; j++ )) |
|
60 |
+ do |
|
61 |
+ if [ "${list_mac[$i]}" = "${list_mac[$j]}" ] |
|
62 |
+ then |
|
63 |
+ list_match[$i]=${list_eth[$j]} |
|
64 |
+ break |
|
65 |
+ fi |
|
66 |
+ done |
|
67 |
+done |
|
68 |
+ |
|
69 |
+function create_eth_cfg_redhat { |
|
70 |
+ local fn=$cfgdir/ifcfg-$1 |
|
71 |
+ |
|
72 |
+ rm -f $fn |
|
73 |
+ echo DEVICE=$1 >>$fn |
|
74 |
+ echo TYPE=Ethernet >>$fn |
|
75 |
+ echo BOOTPROTO=none >>$fn |
|
76 |
+ echo ONBOOT=yes >>$fn |
|
77 |
+ echo NM_CONTROLLED=no >>$fn |
|
78 |
+ echo PEERDNS=yes >>$fn |
|
79 |
+ echo IPV6INIT=yes >>$fn |
|
80 |
+ echo MASTER=$2 >>$fn |
|
81 |
+ echo SLAVE=yes >>$fn |
|
82 |
+} |
|
83 |
+ |
|
84 |
+function create_eth_cfg_pri_redhat { |
|
85 |
+ create_eth_cfg_redhat $1 $2 |
|
86 |
+} |
|
87 |
+ |
|
88 |
+function create_bond_cfg_redhat { |
|
89 |
+ local fn=$cfgdir/ifcfg-$1 |
|
90 |
+ |
|
91 |
+ rm -f $fn |
|
92 |
+ echo DEVICE=$1 >>$fn |
|
93 |
+ echo TYPE=Bond >>$fn |
|
94 |
+ echo BOOTPROTO=dhcp >>$fn |
|
95 |
+ echo ONBOOT=yes >>$fn |
|
96 |
+ echo NM_CONTROLLED=no >>$fn |
|
97 |
+ echo PEERDNS=yes >>$fn |
|
98 |
+ echo IPV6INIT=yes >>$fn |
|
99 |
+ echo BONDING_MASTER=yes >>$fn |
|
100 |
+ echo BONDING_OPTS=\"mode=active-backup miimon=100 primary=$2\" >>$fn |
|
101 |
+} |
|
102 |
+ |
|
103 |
+function create_eth_cfg_ubuntu { |
|
104 |
+ local fn=$cfgdir/interfaces |
|
105 |
+ |
|
106 |
+ echo $'\n'auto $1 >>$fn |
|
107 |
+ echo iface $1 inet manual >>$fn |
|
108 |
+ echo bond-master $2 >>$fn |
|
109 |
+} |
|
110 |
+ |
|
111 |
+function create_eth_cfg_pri_ubuntu { |
|
112 |
+ local fn=$cfgdir/interfaces |
|
113 |
+ |
|
114 |
+ create_eth_cfg_ubuntu $1 $2 |
|
115 |
+ echo bond-primary $1 >>$fn |
|
116 |
+} |
|
117 |
+ |
|
118 |
+function create_bond_cfg_ubuntu { |
|
119 |
+ local fn=$cfgdir/interfaces |
|
120 |
+ |
|
121 |
+ echo $'\n'auto $1 >>$fn |
|
122 |
+ echo iface $1 inet dhcp >>$fn |
|
123 |
+ echo bond-mode active-backup >>$fn |
|
124 |
+ echo bond-miimon 100 >>$fn |
|
125 |
+ echo bond-slaves none >>$fn |
|
126 |
+} |
|
127 |
+ |
|
128 |
+function create_eth_cfg_suse { |
|
129 |
+ local fn=$cfgdir/ifcfg-$1 |
|
130 |
+ |
|
131 |
+ rm -f $fn |
|
132 |
+ echo BOOTPROTO=none >>$fn |
|
133 |
+ echo STARTMODE=auto >>$fn |
|
134 |
+} |
|
135 |
+ |
|
136 |
+function create_eth_cfg_pri_suse { |
|
137 |
+ create_eth_cfg_suse $1 |
|
138 |
+} |
|
139 |
+ |
|
140 |
+function create_bond_cfg_suse { |
|
141 |
+ local fn=$cfgdir/ifcfg-$1 |
|
142 |
+ |
|
143 |
+ rm -f $fn |
|
144 |
+ echo BOOTPROTO=dhcp >>$fn |
|
145 |
+ echo STARTMODE=auto >>$fn |
|
146 |
+ echo BONDING_MASTER=yes >>$fn |
|
147 |
+ echo BONDING_SLAVE_0=$2 >>$fn |
|
148 |
+ echo BONDING_SLAVE_1=$3 >>$fn |
|
149 |
+ echo BONDING_MODULE_OPTS=\'mode=active-backup miimon=100 primary=$2\' >>$fn |
|
150 |
+} |
|
151 |
+ |
|
152 |
+function create_bond { |
|
153 |
+ local bondname=bond$bondcnt |
|
154 |
+ local primary |
|
155 |
+ local secondary |
|
156 |
+ |
|
157 |
+ local class_id1=`cat $sysdir/$1/device/class_id 2>/dev/null` |
|
158 |
+ local class_id2=`cat $sysdir/$2/device/class_id 2>/dev/null` |
|
159 |
+ |
|
160 |
+ if [ "$class_id1" = "$netvsc_cls" ] |
|
161 |
+ then |
|
162 |
+ primary=$2 |
|
163 |
+ secondary=$1 |
|
164 |
+ elif [ "$class_id2" = "$netvsc_cls" ] |
|
165 |
+ then |
|
166 |
+ primary=$1 |
|
167 |
+ secondary=$2 |
|
168 |
+ else |
|
169 |
+ return 0 |
|
170 |
+ fi |
|
171 |
+ |
|
172 |
+ echo $'\nBond name:' $bondname |
|
173 |
+ |
|
174 |
+ echo configuring $primary |
|
175 |
+ create_eth_cfg_pri_$distro $primary $bondname |
|
176 |
+ |
|
177 |
+ echo configuring $secondary |
|
178 |
+ create_eth_cfg_$distro $secondary $bondname |
|
179 |
+ |
|
180 |
+ echo creating: $bondname with primary slave: $primary |
|
181 |
+ create_bond_cfg_$distro $bondname $primary $secondary |
|
182 |
+ |
|
183 |
+ let bondcnt=bondcnt+1 |
|
184 |
+} |
|
185 |
+ |
|
186 |
+for (( i=0; i < $eth_cnt-1; i++ )) |
|
187 |
+do |
|
188 |
+ if [ -n "${list_match[$i]}" ] |
|
189 |
+ then |
|
190 |
+ create_bond ${list_eth[$i]} ${list_match[$i]} |
|
191 |
+ fi |
|
192 |
+done |
|
0 | 193 |
\ No newline at end of file |
1 | 194 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,28 @@ |
0 |
+#!/bin/bash |
|
1 |
+ |
|
2 |
+# This example script retrieves the DHCP state of a given interface. |
|
3 |
+# In the interest of keeping the KVP daemon code free of distro specific |
|
4 |
+# information; the kvp daemon code invokes this external script to gather |
|
5 |
+# DHCP setting for the specific interface. |
|
6 |
+# |
|
7 |
+# Input: Name of the interface |
|
8 |
+# |
|
9 |
+# Output: The script prints the string "Enabled" to stdout to indicate |
|
10 |
+# that DHCP is enabled on the interface. If DHCP is not enabled, |
|
11 |
+# the script prints the string "Disabled" to stdout. |
|
12 |
+# |
|
13 |
+# Each Distro is expected to implement this script in a distro specific |
|
14 |
+# fashion. For instance on Distros that ship with Network Manager enabled, |
|
15 |
+# this script can be based on the Network Manager APIs for retrieving DHCP |
|
16 |
+# information. |
|
17 |
+ |
|
18 |
+if_file="/etc/sysconfig/network-scripts/ifcfg-"$1 |
|
19 |
+ |
|
20 |
+dhcp=$(grep "dhcp" $if_file 2>/dev/null) |
|
21 |
+ |
|
22 |
+if [ "$dhcp" != "" ]; |
|
23 |
+then |
|
24 |
+echo "Enabled" |
|
25 |
+else |
|
26 |
+echo "Disabled" |
|
27 |
+fi |
|
0 | 28 |
\ No newline at end of file |
1 | 29 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,13 @@ |
0 |
+#!/bin/bash |
|
1 |
+ |
|
2 |
+# This example script parses /etc/resolv.conf to retrive DNS information. |
|
3 |
+# In the interest of keeping the KVP daemon code free of distro specific |
|
4 |
+# information; the kvp daemon code invokes this external script to gather |
|
5 |
+# DNS information. |
|
6 |
+# This script is expected to print the nameserver values to stdout. |
|
7 |
+# Each Distro is expected to implement this script in a distro specific |
|
8 |
+# fashion. For instance on Distros that ship with Network Manager enabled, |
|
9 |
+# this script can be based on the Network Manager APIs for retrieving DNS |
|
10 |
+# entries. |
|
11 |
+ |
|
12 |
+cat /etc/resolv.conf 2>/dev/null | awk '/^nameserver/ { print $2 }' |
|
0 | 13 |
\ No newline at end of file |
1 | 14 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,64 @@ |
0 |
+#!/bin/bash |
|
1 |
+ |
|
2 |
+# This example script activates an interface based on the specified |
|
3 |
+# configuration. |
|
4 |
+# |
|
5 |
+# In the interest of keeping the KVP daemon code free of distro specific |
|
6 |
+# information; the kvp daemon code invokes this external script to configure |
|
7 |
+# the interface. |
|
8 |
+# |
|
9 |
+# The only argument to this script is the configuration file that is to |
|
10 |
+# be used to configure the interface. |
|
11 |
+# |
|
12 |
+# Each Distro is expected to implement this script in a distro specific |
|
13 |
+# fashion. For instance on Distros that ship with Network Manager enabled, |
|
14 |
+# this script can be based on the Network Manager APIs for configuring the |
|
15 |
+# interface. |
|
16 |
+# |
|
17 |
+# This example script is based on a RHEL environment. |
|
18 |
+# |
|
19 |
+# Here is the format of the ip configuration file: |
|
20 |
+# |
|
21 |
+# HWADDR=macaddr |
|
22 |
+# DEVICE=interface name |
|
23 |
+# BOOTPROTO=<protocol> (where <protocol> is "dhcp" if DHCP is configured |
|
24 |
+# or "none" if no boot-time protocol should be used) |
|
25 |
+# |
|
26 |
+# IPADDR0=ipaddr1 |
|
27 |
+# IPADDR1=ipaddr2 |
|
28 |
+# IPADDRx=ipaddry (where y = x + 1) |
|
29 |
+# |
|
30 |
+# NETMASK0=netmask1 |
|
31 |
+# NETMASKx=netmasky (where y = x + 1) |
|
32 |
+# |
|
33 |
+# GATEWAY=ipaddr1 |
|
34 |
+# GATEWAYx=ipaddry (where y = x + 1) |
|
35 |
+# |
|
36 |
+# DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc) |
|
37 |
+# |
|
38 |
+# IPV6 addresses will be tagged as IPV6ADDR, IPV6 gateway will be |
|
39 |
+# tagged as IPV6_DEFAULTGW and IPV6 NETMASK will be tagged as |
|
40 |
+# IPV6NETMASK. |
|
41 |
+# |
|
42 |
+# The host can specify multiple ipv4 and ipv6 addresses to be |
|
43 |
+# configured for the interface. Furthermore, the configuration |
|
44 |
+# needs to be persistent. A subsequent GET call on the interface |
|
45 |
+# is expected to return the configuration that is set via the SET |
|
46 |
+# call. |
|
47 |
+# |
|
48 |
+ |
|
49 |
+ |
|
50 |
+ |
|
51 |
+echo "IPV6INIT=yes" >> $1 |
|
52 |
+echo "NM_CONTROLLED=no" >> $1 |
|
53 |
+echo "PEERDNS=yes" >> $1 |
|
54 |
+echo "ONBOOT=yes" >> $1 |
|
55 |
+ |
|
56 |
+ |
|
57 |
+cp $1 /etc/sysconfig/network-scripts/ |
|
58 |
+ |
|
59 |
+ |
|
60 |
+interface=$(echo $1 | awk -F - '{ print $2 }') |
|
61 |
+ |
|
62 |
+/sbin/ifdown $interface 2>/dev/null |
|
63 |
+/sbin/ifup $interface 2>/dev/null |
|
0 | 64 |
\ No newline at end of file |
1 | 65 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,116 @@ |
0 |
+Summary: Hyper-V tools |
|
1 |
+Name: hyper-v |
|
2 |
+Version: 4.9 |
|
3 |
+Release: 1%{?dist} |
|
4 |
+License: GPLv2+ |
|
5 |
+URL: https://elixir.bootlin.com/linux/v4.9/source/tools/hv |
|
6 |
+Group: System/Kernel |
|
7 |
+Vendor: VMware, Inc. |
|
8 |
+Distribution: Photon |
|
9 |
+Source0: %{name}-%{version}.tar.gz |
|
10 |
+%define sha1 hyper-v=f7801636573dbdc679dba8eadce86cf408b6ffc1 |
|
11 |
+Source1: bondvf.sh |
|
12 |
+Source2: hv_get_dns_info.sh |
|
13 |
+Source3: hv_get_dhcp_info.sh |
|
14 |
+Source4: hv_set_ifconfig.sh |
|
15 |
+Source5: lsvmbus |
|
16 |
+BuildRequires: systemd |
|
17 |
+Requires: systemd |
|
18 |
+%description |
|
19 |
+Hyper-V tools. |
|
20 |
+ |
|
21 |
+%prep |
|
22 |
+%setup |
|
23 |
+ |
|
24 |
+%build |
|
25 |
+make |
|
26 |
+ |
|
27 |
+%install |
|
28 |
+install -vdm 755 %{buildroot}/%{_sbindir} |
|
29 |
+install -m 755 %{SOURCE5} %{buildroot}/%{_sbindir}/lsvmbus |
|
30 |
+install -vdm 755 %{buildroot}/%{_bindir} |
|
31 |
+install -m 755 %{SOURCE1} %{buildroot}/%{_bindir}/bondvf.sh |
|
32 |
+install -m 755 %{SOURCE2} %{buildroot}/%{_bindir}/hv_get_dns_info.sh |
|
33 |
+install -m 755 %{SOURCE3} %{buildroot}/%{_bindir}/hv_get_dhcp_info.sh |
|
34 |
+install -m 755 %{SOURCE4} %{buildroot}/%{_bindir}/hv_set_ifconfig.sh |
|
35 |
+install -m 755 hv_fcopy_daemon %{buildroot}/%{_bindir}/hv_fcopy_daemon |
|
36 |
+install -m 755 hv_kvp_daemon %{buildroot}/%{_bindir}/hv_kvp_daemon |
|
37 |
+install -m 755 hv_vss_daemon %{buildroot}/%{_bindir}/hv_vss_daemon |
|
38 |
+install -vdm755 %{buildroot}%{_libdir}/systemd/system-preset |
|
39 |
+echo "disable hv_fcopy_daemon.service" > %{buildroot}%{_libdir}/systemd/system-preset/50-hyper-v.preset |
|
40 |
+echo "disable hv_kvp_daemon.service" >> %{buildroot}%{_libdir}/systemd/system-preset/50-hyper-v.preset |
|
41 |
+echo "disable hv_vss_daemon.service" >> %{buildroot}%{_libdir}/systemd/system-preset/50-hyper-v.preset |
|
42 |
+ |
|
43 |
+install -vdm755 %{buildroot}/usr/lib/systemd/system |
|
44 |
+cat << EOF >> %{buildroot}/usr/lib/systemd/system/hv_fcopy_daemon.service |
|
45 |
+[Unit] |
|
46 |
+Description=Hyper-v file copy daemon |
|
47 |
+ConditionVirtualization=microsoft |
|
48 |
+ |
|
49 |
+[Service] |
|
50 |
+ExecStart=/usr/bin/hv_fcopy_daemon -n |
|
51 |
+ |
|
52 |
+[Install] |
|
53 |
+WantedBy=multi-user.target |
|
54 |
+EOF |
|
55 |
+ |
|
56 |
+cat << EOF >> %{buildroot}/usr/lib/systemd/system/hv_kvp_daemon.service |
|
57 |
+[Unit] |
|
58 |
+Description=Hyper-v key value pair daemon |
|
59 |
+ConditionVirtualization=microsoft |
|
60 |
+ |
|
61 |
+[Service] |
|
62 |
+ExecStart=/usr/bin/hv_kvp_daemon -n |
|
63 |
+ |
|
64 |
+[Install] |
|
65 |
+WantedBy=multi-user.target |
|
66 |
+ |
|
67 |
+EOF |
|
68 |
+cat << EOF >> %{buildroot}/usr/lib/systemd/system/hv_vss_daemon.service |
|
69 |
+[Unit] |
|
70 |
+Description=Hyper-v vss daemon |
|
71 |
+ConditionVirtualization=microsoft |
|
72 |
+ |
|
73 |
+[Service] |
|
74 |
+ExecStart=/usr/bin/hv_vss_daemon -n |
|
75 |
+ |
|
76 |
+[Install] |
|
77 |
+WantedBy=multi-user.target |
|
78 |
+EOF |
|
79 |
+ |
|
80 |
+%post |
|
81 |
+/sbin/ldconfig |
|
82 |
+%systemd_post hv_fcopy_daemon.service |
|
83 |
+%systemd_post hv_kvp_daemon.service |
|
84 |
+%systemd_post hv_vss_daemon.service |
|
85 |
+ |
|
86 |
+%postun |
|
87 |
+/sbin/ldconfig |
|
88 |
+%systemd_postun_with_restart hv_fcopy_daemon.service |
|
89 |
+%systemd_postun_with_restart hv_kvp_daemon.service |
|
90 |
+%systemd_postun_with_restart hv_vss_daemon.service |
|
91 |
+ |
|
92 |
+%preun |
|
93 |
+%systemd_preun hv_fcopy_daemon.service |
|
94 |
+%systemd_preun hv_kvp_daemon.service |
|
95 |
+%systemd_preun hv_vss_daemon.service |
|
96 |
+ |
|
97 |
+%files |
|
98 |
+%defattr(-,root,root) |
|
99 |
+%{_sbindir}/lsvmbus |
|
100 |
+%{_bindir}/bondvf.sh |
|
101 |
+%{_bindir}/hv_get_dns_info.sh |
|
102 |
+%{_bindir}/hv_get_dhcp_info.sh |
|
103 |
+%{_bindir}/hv_set_ifconfig.sh |
|
104 |
+%{_bindir}/hv_fcopy_daemon |
|
105 |
+%{_bindir}/hv_kvp_daemon |
|
106 |
+%{_bindir}/hv_vss_daemon |
|
107 |
+%{_libdir}/systemd/system-preset/50-hyper-v.preset |
|
108 |
+%{_libdir}/systemd/system/hv_fcopy_daemon.service |
|
109 |
+%{_libdir}/systemd/system/hv_kvp_daemon.service |
|
110 |
+%{_libdir}/systemd/system/hv_vss_daemon.service |
|
111 |
+ |
|
112 |
+ |
|
113 |
+%changelog |
|
114 |
+* Tue Mar 13 2018 Xiaolin Li <xiaolinl@vmware.com> 4.9-1 |
|
115 |
+- Initial version. |
0 | 116 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,102 @@ |
0 |
+#!/usr/bin/env python |
|
1 |
+ |
|
2 |
+import os |
|
3 |
+from optparse import OptionParser |
|
4 |
+ |
|
5 |
+parser = OptionParser() |
|
6 |
+parser.add_option("-v", "--verbose", dest="verbose", |
|
7 |
+ help="print verbose messages. Try -vv, -vvv for \ |
|
8 |
+ more verbose messages", action="count") |
|
9 |
+ |
|
10 |
+(options, args) = parser.parse_args() |
|
11 |
+ |
|
12 |
+verbose = 0 |
|
13 |
+if options.verbose is not None: |
|
14 |
+ verbose = options.verbose |
|
15 |
+ |
|
16 |
+vmbus_sys_path = '/sys/bus/vmbus/devices' |
|
17 |
+if not os.path.isdir(vmbus_sys_path): |
|
18 |
+ print "%s doesn't exist: exiting..." % vmbus_sys_path |
|
19 |
+ exit(-1) |
|
20 |
+ |
|
21 |
+vmbus_dev_dict = { |
|
22 |
+ '{0e0b6031-5213-4934-818b-38d90ced39db}' : '[Operating system shutdown]', |
|
23 |
+ '{9527e630-d0ae-497b-adce-e80ab0175caf}' : '[Time Synchronization]', |
|
24 |
+ '{57164f39-9115-4e78-ab55-382f3bd5422d}' : '[Heartbeat]', |
|
25 |
+ '{a9a0f4e7-5a45-4d96-b827-8a841e8c03e6}' : '[Data Exchange]', |
|
26 |
+ '{35fa2e29-ea23-4236-96ae-3a6ebacba440}' : '[Backup (volume checkpoint)]', |
|
27 |
+ '{34d14be3-dee4-41c8-9ae7-6b174977c192}' : '[Guest services]', |
|
28 |
+ '{525074dc-8985-46e2-8057-a307dc18a502}' : '[Dynamic Memory]', |
|
29 |
+ '{cfa8b69e-5b4a-4cc0-b98b-8ba1a1f3f95a}' : 'Synthetic mouse', |
|
30 |
+ '{f912ad6d-2b17-48ea-bd65-f927a61c7684}' : 'Synthetic keyboard', |
|
31 |
+ '{da0a7802-e377-4aac-8e77-0558eb1073f8}' : 'Synthetic framebuffer adapter', |
|
32 |
+ '{f8615163-df3e-46c5-913f-f2d2f965ed0e}' : 'Synthetic network adapter', |
|
33 |
+ '{32412632-86cb-44a2-9b5c-50d1417354f5}' : 'Synthetic IDE Controller', |
|
34 |
+ '{ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}' : 'Synthetic SCSI Controller', |
|
35 |
+ '{2f9bcc4a-0069-4af3-b76b-6fd0be528cda}' : 'Synthetic fiber channel adapter', |
|
36 |
+ '{8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501}' : 'Synthetic RDMA adapter', |
|
37 |
+ '{44c4f61d-4444-4400-9d52-802e27ede19f}' : 'PCI Express pass-through', |
|
38 |
+ '{276aacf4-ac15-426c-98dd-7521ad3f01fe}' : '[Reserved system device]', |
|
39 |
+ '{f8e65716-3cb3-4a06-9a60-1889c5cccab5}' : '[Reserved system device]', |
|
40 |
+ '{3375baf4-9e15-4b30-b765-67acb10d607b}' : '[Reserved system device]', |
|
41 |
+} |
|
42 |
+ |
|
43 |
+def get_vmbus_dev_attr(dev_name, attr): |
|
44 |
+ try: |
|
45 |
+ f = open('%s/%s/%s' % (vmbus_sys_path, dev_name, attr), 'r') |
|
46 |
+ lines = f.readlines() |
|
47 |
+ f.close() |
|
48 |
+ except IOError: |
|
49 |
+ lines = [] |
|
50 |
+ |
|
51 |
+ return lines |
|
52 |
+ |
|
53 |
+class VMBus_Dev: |
|
54 |
+ pass |
|
55 |
+ |
|
56 |
+ |
|
57 |
+vmbus_dev_list = [] |
|
58 |
+ |
|
59 |
+for f in os.listdir(vmbus_sys_path): |
|
60 |
+ vmbus_id = get_vmbus_dev_attr(f, 'id')[0].strip() |
|
61 |
+ class_id = get_vmbus_dev_attr(f, 'class_id')[0].strip() |
|
62 |
+ device_id = get_vmbus_dev_attr(f, 'device_id')[0].strip() |
|
63 |
+ dev_desc = vmbus_dev_dict.get(class_id, 'Unknown') |
|
64 |
+ |
|
65 |
+ chn_vp_mapping = get_vmbus_dev_attr(f, 'channel_vp_mapping') |
|
66 |
+ chn_vp_mapping = [c.strip() for c in chn_vp_mapping] |
|
67 |
+ chn_vp_mapping = sorted(chn_vp_mapping, |
|
68 |
+ key = lambda c : int(c.split(':')[0])) |
|
69 |
+ |
|
70 |
+ chn_vp_mapping = ['\tRel_ID=%s, target_cpu=%s' % |
|
71 |
+ (c.split(':')[0], c.split(':')[1]) |
|
72 |
+ for c in chn_vp_mapping] |
|
73 |
+ d = VMBus_Dev() |
|
74 |
+ d.sysfs_path = '%s/%s' % (vmbus_sys_path, f) |
|
75 |
+ d.vmbus_id = vmbus_id |
|
76 |
+ d.class_id = class_id |
|
77 |
+ d.device_id = device_id |
|
78 |
+ d.dev_desc = dev_desc |
|
79 |
+ d.chn_vp_mapping = '\n'.join(chn_vp_mapping) |
|
80 |
+ if d.chn_vp_mapping: |
|
81 |
+ d.chn_vp_mapping += '\n' |
|
82 |
+ |
|
83 |
+ vmbus_dev_list.append(d) |
|
84 |
+ |
|
85 |
+ |
|
86 |
+vmbus_dev_list = sorted(vmbus_dev_list, key = lambda d : int(d.vmbus_id)) |
|
87 |
+ |
|
88 |
+format0 = '%2s: %s' |
|
89 |
+format1 = '%2s: Class_ID = %s - %s\n%s' |
|
90 |
+format2 = '%2s: Class_ID = %s - %s\n\tDevice_ID = %s\n\tSysfs path: %s\n%s' |
|
91 |
+ |
|
92 |
+for d in vmbus_dev_list: |
|
93 |
+ if verbose == 0: |
|
94 |
+ print ('VMBUS ID ' + format0) % (d.vmbus_id, d.dev_desc) |
|
95 |
+ elif verbose == 1: |
|
96 |
+ print ('VMBUS ID ' + format1) % \ |
|
97 |
+ (d.vmbus_id, d.class_id, d.dev_desc, d.chn_vp_mapping) |
|
98 |
+ else: |
|
99 |
+ print ('VMBUS ID ' + format2) % \ |
|
100 |
+ (d.vmbus_id, d.class_id, d.dev_desc, \ |
|
101 |
+ d.device_id, d.sysfs_path, d.chn_vp_mapping) |
|
0 | 102 |
\ No newline at end of file |