9090import com .cloud .vm .dao .UserVmDao ;
9191import com .cloud .vm .dao .UserVmDetailsDao ;
9292
93- public class ConfigDriveNetworkElement extends AdapterBase implements NetworkElement , UserDataServiceProvider ,
93+ public class ConfigDriveNetworkElement extends AdapterBase implements NetworkElement ,
94+ UserDataServiceProvider , DhcpServiceProvider , DnsServiceProvider ,
9495 StateListener <VirtualMachine .State , VirtualMachine .Event , VirtualMachine >, NetworkMigrationResponder {
9596
9697 private static final Map <Service , Map <Capability , String >> capabilities = setCapabilities ();
@@ -197,6 +198,8 @@ public Map<Service, Map<Capability, String>> getCapabilities() {
197198 private static Map <Service , Map <Capability , String >> setCapabilities () {
198199 Map <Service , Map <Capability , String >> capabilities = new HashMap <>();
199200 capabilities .put (Service .UserData , null );
201+ capabilities .put (Service .Dhcp , null );
202+ capabilities .put (Service .Dns , null );
200203 return capabilities ;
201204 }
202205
@@ -225,7 +228,7 @@ public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMa
225228 throws ConcurrentOperationException , InsufficientCapacityException , ResourceUnavailableException {
226229 return (canHandle (network .getTrafficType ())
227230 && configureConfigDriveData (profile , nic , dest ))
228- && createConfigDriveIso (profile , dest , null );
231+ && createConfigDriveIso (nic , profile , dest , null );
229232 }
230233
231234 @ Override
@@ -342,10 +345,13 @@ public boolean prepareMigration(NicProfile nic, Network network, VirtualMachineP
342345 configureConfigDriveData (vm , nic , dest );
343346
344347 // Create the config drive on dest host cache
345- createConfigDriveIsoOnHostCache (vm , dest .getHost ().getId ());
348+ createConfigDriveIsoOnHostCache (nic , vm , dest .getHost ().getId ());
346349 } else {
347350 vm .setConfigDriveLocation (getConfigDriveLocation (vm .getId ()));
348- addPasswordAndUserdata (network , nic , vm , dest , context );
351+ boolean result = addPasswordAndUserdata (network , nic , vm , dest , context );
352+ if (result ) {
353+ createConfigDriveIso (nic , vm , dest , null );
354+ }
349355 }
350356 } catch (InsufficientCapacityException | ResourceUnavailableException e ) {
351357 logger .error ("Failed to add config disk drive due to: " , e );
@@ -398,7 +404,7 @@ private void recreateConfigDriveIso(NicProfile nic, Network network, VirtualMach
398404 vm .getUuid (), nic .getMacAddress (), userVm .getDetail ("SSH.PublicKey" ), (String ) vm .getParameter (VirtualMachineProfile .Param .VmPassword ), isWindows , VirtualMachineManager .getHypervisorHostname (dest .getHost () != null ? dest .getHost ().getName () : "" ));
399405 vm .setVmData (vmData );
400406 vm .setConfigDriveLabel (VirtualMachineManager .VmConfigDriveLabel .value ());
401- createConfigDriveIso (vm , dest , diskToUse );
407+ createConfigDriveIso (nic , vm , dest , diskToUse );
402408 }
403409 }
404410 }
@@ -528,7 +534,7 @@ private boolean isConfigDriveIsoOnHostCache(long vmId) {
528534 return false ;
529535 }
530536
531- private boolean createConfigDriveIsoOnHostCache (VirtualMachineProfile profile , Long hostId ) throws ResourceUnavailableException {
537+ private boolean createConfigDriveIsoOnHostCache (NicProfile nic , VirtualMachineProfile profile , Long hostId ) throws ResourceUnavailableException {
532538 if (hostId == null ) {
533539 throw new ResourceUnavailableException ("Config drive iso creation failed, dest host not available" ,
534540 ConfigDriveNetworkElement .class , 0L );
@@ -540,7 +546,7 @@ private boolean createConfigDriveIsoOnHostCache(VirtualMachineProfile profile, L
540546
541547 final String isoFileName = ConfigDrive .configIsoFileName (profile .getInstanceName ());
542548 final String isoPath = ConfigDrive .createConfigDrivePath (profile .getInstanceName ());
543- final String isoData = ConfigDriveBuilder .buildConfigDrive (profile .getVmData (), isoFileName , profile .getConfigDriveLabel (), customUserdataParamMap );
549+ final String isoData = ConfigDriveBuilder .buildConfigDrive (nic , profile .getVmData (), isoFileName , profile .getConfigDriveLabel (), customUserdataParamMap );
544550 final HandleConfigDriveIsoCommand configDriveIsoCommand = new HandleConfigDriveIsoCommand (isoPath , isoData , null , false , true , true );
545551
546552 final HandleConfigDriveIsoAnswer answer = (HandleConfigDriveIsoAnswer ) agentManager .easySend (hostId , configDriveIsoCommand );
@@ -590,7 +596,7 @@ private boolean deleteConfigDriveIsoOnHostCache(final VirtualMachine vm, final L
590596 return true ;
591597 }
592598
593- private boolean createConfigDriveIso (VirtualMachineProfile profile , DeployDestination dest , DiskTO disk ) throws ResourceUnavailableException {
599+ public boolean createConfigDriveIso (NicProfile nic , VirtualMachineProfile profile , DeployDestination dest , DiskTO disk ) throws ResourceUnavailableException {
594600 DataStore dataStore = getDatastoreForConfigDriveIso (disk , profile , dest );
595601
596602 final Long agentId = findAgentId (profile , dest , dataStore );
@@ -605,7 +611,7 @@ private boolean createConfigDriveIso(VirtualMachineProfile profile, DeployDestin
605611
606612 final String isoFileName = ConfigDrive .configIsoFileName (profile .getInstanceName ());
607613 final String isoPath = ConfigDrive .createConfigDrivePath (profile .getInstanceName ());
608- final String isoData = ConfigDriveBuilder .buildConfigDrive (profile .getVmData (), isoFileName , profile .getConfigDriveLabel (), customUserdataParamMap );
614+ final String isoData = ConfigDriveBuilder .buildConfigDrive (nic , profile .getVmData (), isoFileName , profile .getConfigDriveLabel (), customUserdataParamMap );
609615 boolean useHostCacheOnUnsupportedPool = VirtualMachineManager .VmConfigDriveUseHostCacheOnUnsupportedPool .valueIn (dest .getDataCenter ().getId ());
610616 boolean preferHostCache = VirtualMachineManager .VmConfigDriveForceHostCacheUse .valueIn (dest .getDataCenter ().getId ());
611617 final HandleConfigDriveIsoCommand configDriveIsoCommand = new HandleConfigDriveIsoCommand (isoPath , isoData , dataStore .getTO (), useHostCacheOnUnsupportedPool , preferHostCache , true );
@@ -758,4 +764,52 @@ private boolean configureConfigDriveData(final VirtualMachineProfile profile, fi
758764 return true ;
759765 }
760766
767+ @ Override
768+ public boolean addDhcpEntry (Network network , NicProfile nic , VirtualMachineProfile vm , DeployDestination dest ,
769+ ReservationContext context ) throws ConcurrentOperationException , InsufficientCapacityException , ResourceUnavailableException {
770+ // Update nic profile with required information.
771+ // Add network checks
772+ return true ;
773+ }
774+
775+ @ Override
776+ public boolean configDhcpSupportForSubnet (Network network , NicProfile nic , VirtualMachineProfile vm ,
777+ DeployDestination dest ,
778+ ReservationContext context ) throws ConcurrentOperationException , InsufficientCapacityException , ResourceUnavailableException {
779+ return false ;
780+ }
781+
782+ @ Override
783+ public boolean removeDhcpSupportForSubnet (Network network ) throws ResourceUnavailableException {
784+ return true ;
785+ }
786+
787+ @ Override
788+ public boolean setExtraDhcpOptions (Network network , long nicId , Map <Integer , String > dhcpOptions ) {
789+ return false ;
790+ }
791+
792+ @ Override
793+ public boolean removeDhcpEntry (Network network , NicProfile nic ,
794+ VirtualMachineProfile vmProfile ) throws ResourceUnavailableException {
795+ return true ;
796+ }
797+
798+ @ Override
799+ public boolean addDnsEntry (Network network , NicProfile nic , VirtualMachineProfile vm , DeployDestination dest ,
800+ ReservationContext context ) throws ConcurrentOperationException , InsufficientCapacityException , ResourceUnavailableException {
801+ return true ;
802+ }
803+
804+ @ Override
805+ public boolean configDnsSupportForSubnet (Network network , NicProfile nic , VirtualMachineProfile vm ,
806+ DeployDestination dest ,
807+ ReservationContext context ) throws ConcurrentOperationException , InsufficientCapacityException , ResourceUnavailableException {
808+ return true ;
809+ }
810+
811+ @ Override
812+ public boolean removeDnsSupportForSubnet (Network network ) throws ResourceUnavailableException {
813+ return true ;
814+ }
761815}
0 commit comments