1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one
3+ * or more contributor license agreements. See the NOTICE file
4+ * distributed with this work for additional information
5+ * regarding copyright ownership. The ASF licenses this file
6+ * to you under the Apache License, Version 2.0 (the
7+ * "License"); you may not use this file except in compliance
8+ * with the License. You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing,
13+ * software distributed under the License is distributed on an
14+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+ * KIND, either express or implied. See the License for the
16+ * specific language governing permissions and limitations
17+ * under the License.
18+ */
19+
20+ package com .cloud .hypervisor .kvm .resource ;
21+
22+ import com .cloud .agent .api .to .NicTO ;
23+ import com .cloud .exception .InternalErrorException ;
24+ import com .cloud .network .Networks ;
25+ import org .apache .log4j .Logger ;
26+ import org .libvirt .LibvirtException ;
27+
28+ import javax .naming .ConfigurationException ;
29+ import java .util .Map ;
30+
31+ public class DirectVifDriver extends VifDriverBase {
32+
33+ private static final Logger s_logger = Logger .getLogger (DirectVifDriver .class );
34+
35+ /**
36+ * Experimental driver to configure direct networking in libvirt. This should only
37+ * be used on an LXC cluster that does not run any system VMs.
38+ *
39+ * @param nic
40+ * @param guestOsType
41+ * @return
42+ * @throws InternalErrorException
43+ * @throws LibvirtException
44+ */
45+ public LibvirtVMDef .InterfaceDef plug (NicTO nic , String guestOsType ) throws InternalErrorException ,
46+ LibvirtException {
47+ LibvirtVMDef .InterfaceDef intf = new LibvirtVMDef .InterfaceDef ();
48+
49+ if (nic .getType () == Networks .TrafficType .Guest ) {
50+ intf .defDirectNet (_libvirtComputingResource .getNetworkDirectDevice (), null , nic .getMac (), getGuestNicModel (guestOsType ),
51+ _libvirtComputingResource .getNetworkDirectSourceMode ());
52+
53+ } else if (nic .getType () == Networks .TrafficType .Public ) {
54+ intf .defDirectNet (_libvirtComputingResource .getNetworkDirectDevice (), null , nic .getMac (), getGuestNicModel (guestOsType ),
55+ _libvirtComputingResource .getNetworkDirectSourceMode ());
56+ }
57+
58+ return intf ;
59+ }
60+
61+ public void unplug (LibvirtVMDef .InterfaceDef iface ) {
62+ // not needed, libvirt will cleanup
63+ }
64+
65+ }
0 commit comments