@@ -288,6 +288,39 @@ public class NetworkExtensionElement extends AdapterBase implements
288288 /** CLI argument carrying per-action parameters as a JSON object. */
289289 public static final String ARG_ACTION_PARAMS = "--action-params" ;
290290
291+ // ---- Script command names ----
292+
293+ public static final String CMD_IMPLEMENT_NETWORK = "implement-network" ;
294+ public static final String CMD_SHUTDOWN_NETWORK = "shutdown-network" ;
295+ public static final String CMD_DESTROY_NETWORK = "destroy-network" ;
296+ public static final String CMD_ENSURE_NETWORK_DEVICE = "ensure-network-device" ;
297+ public static final String CMD_ASSIGN_IP = "assign-ip" ;
298+ public static final String CMD_RELEASE_IP = "release-ip" ;
299+ public static final String CMD_ADD_STATIC_NAT = "add-static-nat" ;
300+ public static final String CMD_DELETE_STATIC_NAT = "delete-static-nat" ;
301+ public static final String CMD_ADD_PORT_FORWARD = "add-port-forward" ;
302+ public static final String CMD_DELETE_PORT_FORWARD = "delete-port-forward" ;
303+ public static final String CMD_ADD_DHCP_ENTRY = "add-dhcp-entry" ;
304+ public static final String CMD_CONFIG_DHCP_SUBNET = "config-dhcp-subnet" ;
305+ public static final String CMD_REMOVE_DHCP_SUBNET = "remove-dhcp-subnet" ;
306+ public static final String CMD_SET_DHCP_OPTIONS = "set-dhcp-options" ;
307+ public static final String CMD_REMOVE_DHCP_ENTRY = "remove-dhcp-entry" ;
308+ public static final String CMD_ADD_DNS_ENTRY = "add-dns-entry" ;
309+ public static final String CMD_CONFIG_DNS_SUBNET = "config-dns-subnet" ;
310+ public static final String CMD_REMOVE_DNS_SUBNET = "remove-dns-subnet" ;
311+ public static final String CMD_SAVE_VM_DATA = "save-vm-data" ;
312+ public static final String CMD_SAVE_PASSWORD = "save-password" ;
313+ public static final String CMD_SAVE_USERDATA = "save-userdata" ;
314+ public static final String CMD_SAVE_SSHKEY = "save-sshkey" ;
315+ public static final String CMD_SAVE_HYPERVISOR_HOSTNAME = "save-hypervisor-hostname" ;
316+ public static final String CMD_APPLY_LB_RULES = "apply-lb-rules" ;
317+ public static final String CMD_APPLY_FW_RULES = "apply-fw-rules" ;
318+ public static final String CMD_RESTORE_NETWORK = "restore-network" ;
319+ public static final String CMD_IMPLEMENT_VPC = "implement-vpc" ;
320+ public static final String CMD_SHUTDOWN_VPC = "shutdown-vpc" ;
321+ public static final String CMD_UPDATE_VPC_SOURCE_NAT_IP = "update-vpc-source-nat-ip" ;
322+ public static final String CMD_APPLY_NETWORK_ACL = "apply-network-acl" ;
323+
291324 // ---- Network detail key ----
292325
293326 /**
@@ -465,7 +498,7 @@ public boolean implement(Network network, NetworkOffering offering, DeployDestin
465498 implArgs .add ("--extension-ip" ); implArgs .add (safeStr (extensionIp ));
466499 implArgs .addAll (vpcArgs );
467500
468- boolean result = executeScript (network , "implement-network" , implArgs .toArray (new String [0 ]));
501+ boolean result = executeScript (network , CMD_IMPLEMENT_NETWORK , implArgs .toArray (new String [0 ]));
469502
470503 if (!result ) {
471504 return false ;
@@ -638,7 +671,7 @@ public boolean shutdown(Network network, ReservationContext context, boolean cle
638671 args .add ("--network-id" ); args .add (String .valueOf (network .getId ()));
639672 args .add ("--vlan" ); args .add (safeStr (getVlanId (network )));
640673 args .addAll (getVpcIdArgs (network ));
641- boolean result = executeScript (network , "shutdown-network" , args .toArray (new String [0 ]));
674+ boolean result = executeScript (network , CMD_SHUTDOWN_NETWORK , args .toArray (new String [0 ]));
642675 if (result ) {
643676 // Remove stored per-network extension details (e.g. namespace). For VPC-backed networks
644677 // the namespace is named cs-vpc-<vpcId>, stored in the extension details. Removing the
@@ -663,7 +696,7 @@ public boolean destroy(Network network, ReservationContext context)
663696 // For both isolated and VPC tier networks, use destroy-network.
664697 // For VPC tiers, the script preserves the shared namespace;
665698 // the VPC namespace is removed only when shutdownVpc() calls shutdown-vpc.
666- boolean result = executeScript (network , "destroy-network" , args .toArray (new String [0 ]));
699+ boolean result = executeScript (network , CMD_DESTROY_NETWORK , args .toArray (new String [0 ]));
667700 if (result ) {
668701 cleanupPlaceholderNicIp (network , context );
669702 networkDetailsDao .removeDetail (network .getId (), NETWORK_DETAIL_EXTENSION_DETAILS );
@@ -774,7 +807,7 @@ protected void ensureExtensionDetails(Network network) {
774807
775808 List <String > cmdLine = new ArrayList <>();
776809 cmdLine .add (scriptFile .getAbsolutePath ());
777- cmdLine .add ("ensure-network-device" );
810+ cmdLine .add (CMD_ENSURE_NETWORK_DEVICE );
778811 cmdLine .add ("--network-id" );
779812 cmdLine .add (String .valueOf (network .getId ()));
780813 cmdLine .add ("--vlan" );
@@ -875,7 +908,7 @@ public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddre
875908 for (PublicIpAddress ip : ipAddress ) {
876909 boolean isSourceNat = ip .isSourceNat ();
877910 boolean isRevoke = ip .getState () == IpAddress .State .Releasing ;
878- String action = isRevoke ? "release-ip" : "assign-ip" ;
911+ String action = isRevoke ? CMD_RELEASE_IP : CMD_ASSIGN_IP ;
879912
880913 // Public VLAN tag (e.g. "101") from the IP's VLAN record.
881914 String publicVlanTag = safeStr (ip .getVlanTag ());
@@ -956,7 +989,7 @@ public boolean applyStaticNats(Network config, List<? extends StaticNat> rules)
956989 List <String > vpcArgs = getVpcIdArgs (config );
957990
958991 for (StaticNat rule : rules ) {
959- String action = rule .isForRevoke () ? "delete-static-nat" : "add-static-nat" ;
992+ String action = rule .isForRevoke () ? CMD_DELETE_STATIC_NAT : CMD_ADD_STATIC_NAT ;
960993 String publicCidr = getPublicCidr (rule .getSourceIpAddressId ());
961994 String publicVlanTag = getPublicVlanTag (rule .getSourceIpAddressId ());
962995
@@ -994,7 +1027,7 @@ public boolean applyPFRules(Network network, List<PortForwardingRule> rules)
9941027
9951028 for (PortForwardingRule rule : rules ) {
9961029 boolean isRevoke = rule .getState () == FirewallRule .State .Revoke ;
997- String action = isRevoke ? "delete-port-forward" : "add-port-forward" ;
1030+ String action = isRevoke ? CMD_DELETE_PORT_FORWARD : CMD_ADD_PORT_FORWARD ;
9981031 String publicPort = PortForwardingServiceProvider .getPublicPortRange (rule );
9991032 String privatePort = PortForwardingServiceProvider .getPrivatePFPortRange (rule );
10001033 String publicCidr = getPublicCidr (rule .getSourceIpAddressId ());
@@ -1460,7 +1493,7 @@ public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfi
14601493 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
14611494 args .addAll (getNicUuidArgs (network , nic ));
14621495 args .addAll (getVpcIdArgs (network ));
1463- return executeScript (network , "add-dhcp-entry" , args .toArray (new String [0 ]));
1496+ return executeScript (network , CMD_ADD_DHCP_ENTRY , args .toArray (new String [0 ]));
14641497 }
14651498
14661499 @ Override
@@ -1481,7 +1514,7 @@ public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, Virtu
14811514 args .add ("--domain" ); args .add (safeStr (network .getNetworkDomain ()));
14821515 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
14831516 args .addAll (getVpcIdArgs (network ));
1484- return executeScript (network , "config-dhcp-subnet" , args .toArray (new String [0 ]));
1517+ return executeScript (network , CMD_CONFIG_DHCP_SUBNET , args .toArray (new String [0 ]));
14851518 }
14861519
14871520 @ Override
@@ -1495,7 +1528,7 @@ public boolean removeDhcpSupportForSubnet(Network network) throws ResourceUnavai
14951528 args .add ("--network-id" ); args .add (String .valueOf (network .getId ()));
14961529 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
14971530 args .addAll (getVpcIdArgs (network ));
1498- return executeScript (network , "remove-dhcp-subnet" , args .toArray (new String [0 ]));
1531+ return executeScript (network , CMD_REMOVE_DHCP_SUBNET , args .toArray (new String [0 ]));
14991532 }
15001533
15011534 @ Override
@@ -1526,7 +1559,7 @@ public boolean setExtraDhcpOptions(Network network, long nicId, Map<Integer, Str
15261559 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
15271560 args .addAll (getVpcIdArgs (network ));
15281561 try {
1529- return executeScript (network , "set-dhcp-options" , args .toArray (new String [0 ]));
1562+ return executeScript (network , CMD_SET_DHCP_OPTIONS , args .toArray (new String [0 ]));
15301563 } catch (Exception e ) {
15311564 logger .warn ("setExtraDhcpOptions failed for network {}: {}" , network .getId (), e .getMessage ());
15321565 return false ;
@@ -1549,7 +1582,7 @@ public boolean removeDhcpEntry(Network network, NicProfile nic, VirtualMachinePr
15491582 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
15501583 args .addAll (getNicUuidArgs (network , nic ));
15511584 args .addAll (getVpcIdArgs (network ));
1552- return executeScript (network , "remove-dhcp-entry" , args .toArray (new String [0 ]));
1585+ return executeScript (network , CMD_REMOVE_DHCP_ENTRY , args .toArray (new String [0 ]));
15531586 }
15541587
15551588 // ---- DnsServiceProvider ----
@@ -1572,7 +1605,7 @@ public boolean addDnsEntry(Network network, NicProfile nic, VirtualMachineProfil
15721605 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
15731606 args .addAll (getNicUuidArgs (network , nic ));
15741607 args .addAll (getVpcIdArgs (network ));
1575- return executeScript (network , "add-dns-entry" , args .toArray (new String [0 ]));
1608+ return executeScript (network , CMD_ADD_DNS_ENTRY , args .toArray (new String [0 ]));
15761609 }
15771610
15781611 @ Override
@@ -1593,7 +1626,7 @@ public boolean configDnsSupportForSubnet(Network network, NicProfile nic, Virtua
15931626 args .add ("--domain" ); args .add (safeStr (network .getNetworkDomain ()));
15941627 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
15951628 args .addAll (getVpcIdArgs (network ));
1596- return executeScript (network , "config-dns-subnet" , args .toArray (new String [0 ]));
1629+ return executeScript (network , CMD_CONFIG_DNS_SUBNET , args .toArray (new String [0 ]));
15971630 }
15981631
15991632 @ Override
@@ -1607,7 +1640,7 @@ public boolean removeDnsSupportForSubnet(Network network) throws ResourceUnavail
16071640 args .add ("--network-id" ); args .add (String .valueOf (network .getId ()));
16081641 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
16091642 args .addAll (getVpcIdArgs (network ));
1610- return executeScript (network , "remove-dns-subnet" , args .toArray (new String [0 ]));
1643+ return executeScript (network , CMD_REMOVE_DNS_SUBNET , args .toArray (new String [0 ]));
16111644 }
16121645
16131646 // ---- UserDataServiceProvider ----
@@ -1749,7 +1782,7 @@ public boolean addPasswordAndUserdata(Network network, NicProfile nic, VirtualMa
17491782 args .add ("--extension-ip" ); args .add (safeStr (ensureExtensionIp (network )));
17501783 args .addAll (getNicUuidArgs (network , nic ));
17511784 args .addAll (getVpcIdArgs (network ));
1752- return executeScriptWithFilePayload (network , "save-vm-data" , "--vm-data-file" ,
1785+ return executeScriptWithFilePayload (network , CMD_SAVE_VM_DATA , "--vm-data-file" ,
17531786 vmDataArg , args .toArray (new String [0 ]));
17541787 }
17551788
@@ -1773,7 +1806,7 @@ public boolean savePassword(Network network, NicProfile nic, VirtualMachineProfi
17731806 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
17741807 args .addAll (getNicUuidArgs (network , nic ));
17751808 args .addAll (getVpcIdArgs (network ));
1776- return executeScript (network , "save-password" , args .toArray (new String [0 ]));
1809+ return executeScript (network , CMD_SAVE_PASSWORD , args .toArray (new String [0 ]));
17771810 }
17781811
17791812 @ Override
@@ -1800,7 +1833,7 @@ public boolean saveUserData(Network network, NicProfile nic, VirtualMachineProfi
18001833 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
18011834 args .addAll (getNicUuidArgs (network , nic ));
18021835 args .addAll (getVpcIdArgs (network ));
1803- return executeScript (network , "save-userdata" , args .toArray (new String [0 ]));
1836+ return executeScript (network , CMD_SAVE_USERDATA , args .toArray (new String [0 ]));
18041837 }
18051838
18061839 @ Override
@@ -1824,7 +1857,7 @@ public boolean saveSSHKey(Network network, NicProfile nic, VirtualMachineProfile
18241857 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
18251858 args .addAll (getNicUuidArgs (network , nic ));
18261859 args .addAll (getVpcIdArgs (network ));
1827- return executeScript (network , "save-sshkey" , args .toArray (new String [0 ]));
1860+ return executeScript (network , CMD_SAVE_SSHKEY , args .toArray (new String [0 ]));
18281861 }
18291862
18301863 @ Override
@@ -1848,7 +1881,7 @@ public boolean saveHypervisorHostname(NicProfile nic, Network network, VirtualMa
18481881 args .add ("--extension-ip" ); args .add (safeStr (extensionIp ));
18491882 args .addAll (getNicUuidArgs (network , nic ));
18501883 args .addAll (getVpcIdArgs (network ));
1851- return executeScript (network , "save-hypervisor-hostname" , args .toArray (new String [0 ]));
1884+ return executeScript (network , CMD_SAVE_HYPERVISOR_HOSTNAME , args .toArray (new String [0 ]));
18521885 }
18531886
18541887 // ---- LoadBalancingServiceProvider ----
@@ -1905,7 +1938,7 @@ public boolean applyLBRules(Network network, List<LoadBalancingRule> rules)
19051938 args .add ("--vlan" ); args .add (safeStr (vlanId ));
19061939 args .add ("--lb-rules" ); args .add (json .toString ());
19071940 args .addAll (vpcArgs );
1908- boolean result = executeScript (network , "apply-lb-rules" , args .toArray (new String [0 ]));
1941+ boolean result = executeScript (network , CMD_APPLY_LB_RULES , args .toArray (new String [0 ]));
19091942 if (!result ) {
19101943 throw new ResourceUnavailableException ("Failed to apply LB rules for network " + network .getId (),
19111944 Network .class , network .getId ());
@@ -2091,7 +2124,7 @@ public boolean applyFWRules(Network network, List<? extends FirewallRule> rules)
20912124 args .add ("--cidr" ); args .add (safeStr (network .getCidr ()));
20922125 args .addAll (getVpcIdArgs (network ));
20932126
2094- boolean result = executeScriptWithFilePayload (network , "apply-fw-rules" , "--fw-rules-file" ,
2127+ boolean result = executeScriptWithFilePayload (network , CMD_APPLY_FW_RULES , "--fw-rules-file" ,
20952128 rulesBase64 , args .toArray (new String [0 ]));
20962129 if (!result ) {
20972130 throw new ResourceUnavailableException (
@@ -2170,7 +2203,7 @@ public boolean completeAggregatedExecution(Network network, DeployDestination de
21702203 args .add ("--domain" ); args .add (safeStr (network .getNetworkDomain ()));
21712204 args .addAll (getVpcIdArgs (network ));
21722205
2173- return executeScriptWithFilePayload (network , "restore-network" , "--restore-data-file" ,
2206+ return executeScriptWithFilePayload (network , CMD_RESTORE_NETWORK , "--restore-data-file" ,
21742207 restoreDataBase64 , args .toArray (new String [0 ]));
21752208 }
21762209
@@ -2439,7 +2472,7 @@ protected void ensureExtensionDetails(Vpc vpc) {
24392472
24402473 List <String > cmdLine = new ArrayList <>();
24412474 cmdLine .add (scriptFile .getAbsolutePath ());
2442- cmdLine .add ("ensure-network-device" );
2475+ cmdLine .add (CMD_ENSURE_NETWORK_DEVICE );
24432476 cmdLine .add ("--vpc-id" );
24442477 cmdLine .add (String .valueOf (vpc .getId ()));
24452478 cmdLine .add ("--zone-id" );
@@ -2606,7 +2639,7 @@ public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext
26062639 implArgs .add ("--source-nat" ); implArgs .add ("true" );
26072640 }
26082641
2609- if (!executeVpcScript (vpc , "implement-vpc" , implArgs .toArray (new String [0 ]))) {
2642+ if (!executeVpcScript (vpc , CMD_IMPLEMENT_VPC , implArgs .toArray (new String [0 ]))) {
26102643 return false ;
26112644 }
26122645
@@ -2639,15 +2672,15 @@ public boolean shutdownVpc(Vpc vpc, ReservationContext context)
26392672 args .add ("--vlan" ); args .add (safeStr (getVlanId (network )));
26402673 args .addAll (getVpcIdArgs (network ));
26412674
2642- final boolean tierResult = executeScript (network , "destroy-network" , args .toArray (new String [0 ]));
2675+ final boolean tierResult = executeScript (network , CMD_DESTROY_NETWORK , args .toArray (new String [0 ]));
26432676 result = result && tierResult ;
26442677 }
26452678 }
26462679
26472680 // Remove the VPC namespace and VPC-level details regardless of tier result.
26482681 List <String > vpcArgs = new ArrayList <>();
26492682 vpcArgs .add ("--vpc-id" ); vpcArgs .add (String .valueOf (vpc .getId ()));
2650- boolean vpcResult = executeVpcScript (vpc , "shutdown-vpc" , vpcArgs .toArray (new String [0 ]));
2683+ boolean vpcResult = executeVpcScript (vpc , CMD_SHUTDOWN_VPC , vpcArgs .toArray (new String [0 ]));
26512684 if (vpcResult ) {
26522685 try {
26532686 vpcDetailsDao .removeDetail (vpc .getId (), NETWORK_DETAIL_EXTENSION_DETAILS );
@@ -2704,7 +2737,7 @@ public boolean updateVpcSourceNatIp(Vpc vpc, IpAddress address) {
27042737 args .add ("--public-cidr" ); args .add (safeStr (getPublicCidr (address .getId ())));
27052738 args .add ("--source-nat" ); args .add ("true" );
27062739
2707- final boolean result = executeVpcScript (vpc , "update-vpc-source-nat-ip" , args .toArray (new String [0 ]));
2740+ final boolean result = executeVpcScript (vpc , CMD_UPDATE_VPC_SOURCE_NAT_IP , args .toArray (new String [0 ]));
27082741 if (!result ) {
27092742 logger .warn ("updateVpcSourceNatIp: failed to update source NAT IP for VPC {} to {}" ,
27102743 vpc .getId (), address .getAddress ().addr ());
@@ -2743,7 +2776,7 @@ public boolean applyNetworkACLs(Network config, List<? extends NetworkACLItem> r
27432776 args .add ("--cidr" ); args .add (safeStr (config .getCidr ()));
27442777 args .addAll (getVpcIdArgs (config ));
27452778
2746- boolean result = executeScriptWithFilePayload (config , "apply-network-acl" ,
2779+ boolean result = executeScriptWithFilePayload (config , CMD_APPLY_NETWORK_ACL ,
27472780 "--acl-rules-file" , aclRulesBase64 , args .toArray (new String [0 ]));
27482781 if (!result ) {
27492782 throw new ResourceUnavailableException (
@@ -2784,7 +2817,7 @@ public boolean reorderAclRules(Vpc vpc, List<? extends Network> networks,
27842817 args .add ("--cidr" ); args .add (safeStr (network .getCidr ()));
27852818 args .addAll (getVpcIdArgs (network ));
27862819
2787- boolean r = executeScriptWithFilePayload (network , "apply-network-acl" ,
2820+ boolean r = executeScriptWithFilePayload (network , CMD_APPLY_NETWORK_ACL ,
27882821 "--acl-rules-file" , aclRulesBase64 , args .toArray (new String [0 ]));
27892822 result = result && r ;
27902823 } catch (Exception e ) {
0 commit comments