@@ -243,6 +243,8 @@ public class NetworkExtensionElement extends AdapterBase implements
243243 public static final String CMD_UPDATE_VPC_SOURCE_NAT_IP = "update-vpc-source-nat-ip" ;
244244 public static final String CMD_APPLY_NETWORK_ACL = "apply-network-acl" ;
245245 public static final String CMD_CUSTOM_ACTION = "custom-action" ;
246+ public static final String CMD_PREPARE_NIC = "prepare-nic" ;
247+ public static final String CMD_RELEASE_NIC = "release-nic" ;
246248
247249 // ---- Network detail key ----
248250
@@ -432,10 +434,6 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
432434 public boolean prepare (Network network , NicProfile nic , VirtualMachineProfile vm ,
433435 DeployDestination dest , ReservationContext context )
434436 throws ConcurrentOperationException , ResourceUnavailableException , InsufficientCapacityException {
435- // Copy from VirtualRouterElement.java
436- if (vm .getType () != VirtualMachine .Type .User || vm .getHypervisorType () == Hypervisor .HypervisorType .BareMetal ) {
437- return false ;
438- }
439437
440438 if (!canHandle (network , null )) {
441439 return false ;
@@ -448,9 +446,33 @@ public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm
448446 // Sync nic with network
449447 applyNicUpdateFromNetwork (network , nic .getId ());
450448
451- final NetworkOfferingVO offering = networkOfferingDao .findById (network .getNetworkOfferingId ());
449+ // Build payload for prepare-nic script command
450+ try {
451+ JsonObject payload = new JsonObject ();
452+ payload .addProperty ("network_id" , String .valueOf (network .getId ()));
453+ payload .addProperty ("vlan" , safeStr (getVlanId (network )));
454+ if (nic != null ) {
455+ payload .addProperty ("mac" , safeStr (nic .getMacAddress ()));
456+ payload .addProperty ("ip" , safeStr (nic .getIPv4Address ()));
457+ addNicIpv6ToPayload (payload , nic );
458+ addNicUuidToPayload (payload , nic );
459+ payload .addProperty ("default_nic" , String .valueOf (nic .isDefaultNic ()));
460+ }
461+ if (vm != null ) {
462+ payload .addProperty ("hostname" , safeStr (vm .getHostName ()));
463+ }
464+ payload .addProperty ("gateway" , safeStr (network .getGateway ()));
465+ payload .addProperty ("cidr" , safeStr (network .getCidr ()));
466+ payload .addProperty ("extension_ip" , safeStr (ensureExtensionIp (network )));
467+ addVpcIdToPayload (payload , network );
452468
453- return implement (network , offering , dest , context );
469+ logger .debug ("Preparing NIC via extension script: network={} nicMac={} nicIp={}" , network , nic != null ? nic .getMacAddress () : null , nic != null ? nic .getIPv4Address () : null );
470+
471+ return executeScript (network , CMD_PREPARE_NIC , payload );
472+ } catch (Exception e ) {
473+ logger .warn ("prepare: failed to prepare NIC for network {}: {}" , network , e .getMessage ());
474+ return false ;
475+ }
454476 }
455477
456478 private void applyNicUpdateFromNetwork (Network network , Long nicId ) {
@@ -471,7 +493,30 @@ private void applyNicUpdateFromNetwork(Network network, Long nicId) {
471493 @ Override
472494 public boolean release (Network network , NicProfile nic , VirtualMachineProfile vm ,
473495 ReservationContext context ) throws ConcurrentOperationException , ResourceUnavailableException {
474- return true ;
496+ if (!canHandle (network , null )) {
497+ return true ;
498+ }
499+
500+ try {
501+ JsonObject payload = new JsonObject ();
502+ payload .addProperty ("network_id" , String .valueOf (network .getId ()));
503+ payload .addProperty ("vlan" , safeStr (getVlanId (network )));
504+ if (nic != null ) {
505+ payload .addProperty ("mac" , safeStr (nic .getMacAddress ()));
506+ payload .addProperty ("ip" , safeStr (nic .getIPv4Address ()));
507+ addNicIpv6ToPayload (payload , nic );
508+ addNicUuidToPayload (payload , nic );
509+ }
510+ payload .addProperty ("extension_ip" , safeStr (ensureExtensionIp (network )));
511+ addVpcIdToPayload (payload , network );
512+
513+ logger .debug ("Releasing NIC via extension script: network={} nicMac={} nicIp={}" , network , nic != null ? nic .getMacAddress () : null , nic != null ? nic .getIPv4Address () : null );
514+
515+ return executeScript (network , CMD_RELEASE_NIC , payload );
516+ } catch (Exception e ) {
517+ logger .warn ("release: failed to release NIC for network {}: {}" , network , e .getMessage ());
518+ return false ;
519+ }
475520 }
476521
477522 @ Override
0 commit comments