"Fossies" - the Fresh Open Source Software Archive 
Member "nova-22.0.1/nova/virt/libvirt/designer.py" (19 Nov 2020, 6251 Bytes) of package /linux/misc/openstack/nova-22.0.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "designer.py" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
22.0.0_vs_22.0.1.
1 # Copyright (C) 2013 Red Hat, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 """
16 Policy based configuration of libvirt objects
17
18 This module provides helper APIs for populating the config.py
19 classes based on common operational needs / policies
20 """
21
22
23 from nova.pci import utils as pci_utils
24
25
26 def set_vif_guest_frontend_config(conf, mac, model, driver, queues,
27 rx_queue_size):
28 """Populate a LibvirtConfigGuestInterface instance
29 with guest frontend details.
30
31 NOTE: @model, @driver, @queues and @rx_queue_size can be None.
32 """
33 conf.mac_addr = mac
34 if model is not None:
35 conf.model = model
36 if driver is not None:
37 conf.driver_name = driver
38 if queues is not None:
39 conf.vhost_queues = queues
40 if rx_queue_size:
41 conf.vhost_rx_queue_size = rx_queue_size
42
43
44 def set_vif_host_backend_ethernet_config(conf, tapname):
45 """Populate a LibvirtConfigGuestInterface instance
46 with host backend details for an externally configured
47 host device.
48
49 NB use of this configuration is discouraged by
50 libvirt project and will mark domains as 'tainted'.
51 """
52
53 conf.net_type = "ethernet"
54 conf.target_dev = tapname
55 conf.script = None
56
57
58 def set_vif_host_backend_802qbg_config(conf, devname, managerid,
59 typeid, typeidversion,
60 instanceid, tapname=None):
61 """Populate a LibvirtConfigGuestInterface instance
62 with host backend details for an 802.1qbg device.
63 """
64
65 conf.net_type = "direct"
66 conf.source_dev = devname
67 conf.source_mode = "vepa"
68 conf.vporttype = "802.1Qbg"
69 conf.add_vport_param("managerid", managerid)
70 conf.add_vport_param("typeid", typeid)
71 conf.add_vport_param("typeidversion", typeidversion)
72 conf.add_vport_param("instanceid", instanceid)
73 if tapname:
74 conf.target_dev = tapname
75
76
77 def set_vif_host_backend_802qbh_config(conf, net_type, devname, profileid,
78 tapname=None):
79 """Populate a LibvirtConfigGuestInterface instance
80 with host backend details for an 802.1qbh device.
81 """
82
83 conf.net_type = net_type
84 if net_type == 'direct':
85 conf.source_mode = 'passthrough'
86 conf.source_dev = pci_utils.get_ifname_by_pci_address(devname)
87 conf.driver_name = 'vhost'
88 else:
89 conf.source_dev = devname
90 conf.model = None
91 conf.vporttype = "802.1Qbh"
92 conf.add_vport_param("profileid", profileid)
93 if tapname:
94 conf.target_dev = tapname
95
96
97 def set_vif_host_backend_hw_veb(conf, net_type, devname, vlan,
98 tapname=None):
99 """Populate a LibvirtConfigGuestInterface instance
100 with host backend details for an device that supports hardware
101 virtual ethernet bridge.
102 """
103
104 conf.net_type = net_type
105 conf.vlan = vlan
106 if net_type == 'direct':
107 conf.source_mode = 'passthrough'
108 conf.source_dev = pci_utils.get_ifname_by_pci_address(devname)
109 conf.driver_name = 'vhost'
110 else: # net_type == network_model.VNIC_TYPE_DIRECT
111 conf.source_dev = devname
112 conf.model = None
113 if tapname:
114 conf.target_dev = tapname
115
116
117 def set_vif_host_backend_hostdev_pci_config(conf, pci_slot):
118 """Populate a LibvirtConfigGuestHostdev instance with pci address data."""
119
120 conf.domain, conf.bus, conf.slot, conf.function = (
121 pci_utils.get_pci_address_fields(pci_slot))
122
123
124 def set_vif_host_backend_direct_config(conf, devname, mode="passthrough"):
125 """Populate a LibvirtConfigGuestInterface instance
126 with direct Interface.
127 """
128
129 conf.net_type = "direct"
130 conf.source_mode = mode
131 conf.source_dev = devname
132 conf.model = "virtio"
133
134
135 def set_vif_host_backend_vhostuser_config(conf, mode, path, rx_queue_size,
136 tx_queue_size, tapname=None):
137 """Populate a LibvirtConfigGuestInterface instance
138 with host backend details for vhostuser socket.
139
140 NOTE: @rx_queue_size and @tx_queue_size can be None
141 """
142 conf.net_type = "vhostuser"
143 conf.vhostuser_type = "unix"
144 conf.vhostuser_mode = mode
145 conf.vhostuser_path = path
146 if rx_queue_size:
147 conf.vhost_rx_queue_size = rx_queue_size
148 if tx_queue_size:
149 conf.vhost_tx_queue_size = tx_queue_size
150 if tapname:
151 conf.target_dev = tapname
152
153
154 def set_vif_mtu_config(conf, mtu):
155 """Populate a LibvirtConfigGuestInterface instance
156 with network mtu.
157 """
158 conf.mtu = mtu
159
160
161 def set_vif_bandwidth_config(conf, inst_type):
162 """Config vif inbound/outbound bandwidth limit. parameters are
163 set in instance_type_extra_specs table, key is in the format
164 quota:vif_inbound_average.
165 """
166
167 bandwidth_items = ['vif_inbound_average', 'vif_inbound_peak',
168 'vif_inbound_burst', 'vif_outbound_average', 'vif_outbound_peak',
169 'vif_outbound_burst']
170 for key, value in inst_type.get('extra_specs', {}).items():
171 scope = key.split(':')
172 if len(scope) > 1 and scope[0] == 'quota':
173 if scope[1] in bandwidth_items:
174 setattr(conf, scope[1], value)
175
176
177 def set_numa_memnode(conf, guest_node_id, host_cell_id):
178 """Prepares numa memory node config for the guest.
179 """
180 conf.cellid = guest_node_id
181 conf.nodeset = [host_cell_id]
182 conf.mode = "strict"
183
184
185 def set_vcpu_realtime_scheduler(conf, vcpus_rt, priority):
186 """Prepares realtime config for the guest."""
187 conf.vcpus = vcpus_rt
188 conf.scheduler = "fifo"
189 conf.priority = priority
190
191
192 def set_driver_iommu_for_sev(conf):
193 for dev in conf.devices:
194 if dev.uses_virtio:
195 dev.driver_iommu = True