99 * @copyright © 2021 OnApp
1010 */
1111
12+ /** @var */
13+ define ('ONAPP_NAT_RULES_BATCH_DESTROY ' , 'nat_rules_batch_destroy ' );
14+
1215/**
1316 * NSX_EdgeGatewaystNatRules
1417 *
@@ -45,65 +48,81 @@ public function initFields( $version = null, $className = '' ) {
4548 switch ( $ version ) {
4649 case 6.5 :
4750 $ this ->fields = array (
48- 'id ' => array (
49- ONAPP_FIELD_MAP => '_id ' ,
51+ 'id ' => array (
52+ ONAPP_FIELD_MAP => '_id ' ,
5053 ONAPP_FIELD_TYPE => 'integer ' ,
5154 ONAPP_FIELD_READ_ONLY => true ,
5255 ),
53- 'identifier ' => array (
56+ 'identifier ' => array (
5457 ONAPP_FIELD_MAP => '_identifier ' ,
5558 ONAPP_FIELD_TYPE => 'string ' ,
5659 ),
57- 'label ' => array (
60+ 'label ' => array (
5861 ONAPP_FIELD_MAP => '_label ' ,
5962 ONAPP_FIELD_TYPE => 'string ' ,
6063 ),
61- 'description ' => array (
64+ 'description ' => array (
6265 ONAPP_FIELD_MAP => '_description ' ,
6366 ONAPP_FIELD_TYPE => 'string ' ,
6467 ),
65- 'enabled ' => array (
68+ 'enabled ' => array (
6669 ONAPP_FIELD_MAP => '_enabled ' ,
6770 ONAPP_FIELD_TYPE => 'boolean ' ,
6871 ),
69- 'rule_type ' => array (
72+ 'rule_type ' => array (
7073 ONAPP_FIELD_MAP => '_rule_type ' ,
7174 ONAPP_FIELD_TYPE => 'string ' ,
7275 ),
73- 'vcloud_nsxt_edge_gateway_id ' => array (
76+ 'vcloud_nsxt_edge_gateway_id ' => array (
7477 ONAPP_FIELD_MAP => '_vcloud_nsxt_edge_gateway_id ' ,
7578 ONAPP_FIELD_TYPE => 'integer ' ,
7679 ),
77- 'port ' => array (
80+ 'port ' => array (
7881 ONAPP_FIELD_MAP => '_port ' ,
7982 ONAPP_FIELD_TYPE => 'integer ' ,
8083 ),
81- 'logging ' => array (
84+ 'logging ' => array (
8285 ONAPP_FIELD_MAP => '_logging ' ,
8386 ONAPP_FIELD_TYPE => 'boolean ' ,
8487 ),
85- 'system ' => array (
88+ 'system ' => array (
8689 ONAPP_FIELD_MAP => '_system ' ,
8790 ONAPP_FIELD_TYPE => 'boolean ' ,
8891 ),
89- 'version ' => array (
92+ 'version ' => array (
9093 ONAPP_FIELD_MAP => '_version ' ,
9194 ONAPP_FIELD_TYPE => 'integer ' ,
9295 ),
93- 'created_at ' => array (
96+ 'created_at ' => array (
9497 ONAPP_FIELD_MAP => '_created_at ' ,
9598 ONAPP_FIELD_TYPE => 'datetime ' ,
9699 ONAPP_FIELD_READ_ONLY => true ,
97100 ),
98- 'updated_at ' => array (
101+ 'updated_at ' => array (
99102 ONAPP_FIELD_MAP => '_updated_at ' ,
100103 ONAPP_FIELD_TYPE => 'datetime ' ,
101104 ONAPP_FIELD_READ_ONLY => true ,
102105 ),
103- 'nsxt_edge_gateway_id ' => array (
106+ 'nsxt_edge_gateway_id ' => array (
104107 ONAPP_FIELD_MAP => '_nsxt_edge_gateway_id ' ,
105108 ONAPP_FIELD_TYPE => 'integer ' ,
106109 ),
110+ 'vcloud_nsxt_application_port_profile_id ' => array (
111+ ONAPP_FIELD_MAP => '_vcloud_nsxt_application_port_profile_id ' ,
112+ ONAPP_FIELD_TYPE => 'string ' ,
113+ ),
114+ 'vcloud_nsxt_external_ip_address ' => array (
115+ ONAPP_FIELD_MAP => '_vcloud_nsxt_external_ip_address ' ,
116+ ONAPP_FIELD_TYPE => 'string ' ,
117+ ),
118+ 'vcloud_nsxt_internal_ip_address ' => array (
119+ ONAPP_FIELD_MAP => '_vcloud_nsxt_internal_ip_address ' ,
120+ ONAPP_FIELD_TYPE => 'string ' ,
121+ ),
122+ 'vcloud_nsxt_destination_ip_address ' => array (
123+ ONAPP_FIELD_MAP => '_vcloud_nsxt_destination_ip_address ' ,
124+ ONAPP_FIELD_TYPE => 'string ' ,
125+ ),
107126 );
108127 break ;
109128 }
@@ -133,6 +152,15 @@ function getResource( $action = ONAPP_GETRESOURCE_DEFAULT ) {
133152 * @alias /nsxt_edge_gateways/:nsxt_edge_gateway_id/nat_rules(.:format)
134153 * @format {:controller=>"NSX_EdgeGatewaystNatRules", :action=>"getList"}
135154 */
155+ /**
156+ * ROUTE :
157+ *
158+ * @name Add NSX-T NAT Rule
159+ * @method POST
160+ *
161+ * @alias /nsxt_edge_gateways/:nsxt_edge_gateway_id/nat_rules(.:format)
162+ * @format {:controller=>"NSX_EdgeGatewaystNatRules", :action=>"save"}
163+ */
136164 if ( is_null ( $ this ->_nsxt_edge_gateway_id ) && is_null ( $ this ->_obj ->_nsxt_edge_gateway_id ) ) {
137165 $ this ->logger ->error (
138166 'getResource( ' . $ action . ' ): argument _nsxt_edge_gateway_id not set. ' ,
@@ -149,6 +177,33 @@ function getResource( $action = ONAPP_GETRESOURCE_DEFAULT ) {
149177 $ this ->logger ->debug ( 'getResource( ' . $ action . ' ): return ' . $ resource );
150178 break ;
151179
180+ case ONAPP_NAT_RULES_BATCH_DESTROY :
181+ /**
182+ * ROUTE :
183+ *
184+ * @name Delete NSX-T NAT Rule
185+ * @method DELETE
186+ *
187+ * @alias /nsxt_edge_gateways/:id/nat_rules_batch_destroy(.:format)
188+ * @format {:controller=>"NSX_EdgeGatewaystNatRules", :action=>"delete"}
189+ */
190+ if ( is_null ( $ this ->_nsxt_edge_gateway_id ) && is_null ( $ this ->_obj ->_nsxt_edge_gateway_id ) ) {
191+ $ this ->logger ->error (
192+ 'getResource( ' . $ action . ' ): argument _nsxt_edge_gateway_id not set. ' ,
193+ __FILE__ ,
194+ __LINE__
195+ );
196+ } else {
197+ if ( is_null ( $ this ->_nsxt_edge_gateway_id ) ) {
198+ $ this ->_nsxt_edge_gateway_id = $ this ->obj ->_nsxt_edge_gateway_id ;
199+ }
200+ }
201+
202+ $ resource = 'nsxt_edge_gateways/ ' . $ this ->_nsxt_edge_gateway_id . '/ ' . ONAPP_NAT_RULES_BATCH_DESTROY ;
203+ $ this ->logger ->debug ( 'getResource( ' . $ action . ' ): return ' . $ resource );
204+ break ;
205+
206+
152207 default :
153208 $ resource = parent ::getResource ( $ action );
154209 break ;
@@ -157,6 +212,47 @@ function getResource( $action = ONAPP_GETRESOURCE_DEFAULT ) {
157212 return $ resource ;
158213 }
159214
215+ public function save ()
216+ {
217+ $ data = array (
218+ 'nsxt_nat_rule ' => array (
219+ 'label ' => $ this ->_label ,
220+ 'description ' => $ this ->_description ,
221+ 'vcloud_nsxt_application_port_profile_id ' => $ this ->_vcloud_nsxt_application_port_profile_id ,
222+ 'enabled ' => $ this ->_enabled ,
223+ 'rule_type ' => $ this ->_rule_type ,
224+ 'vcloud_nsxt_external_ip_address ' => $ this ->_vcloud_nsxt_external_ip_address ,
225+ 'vcloud_nsxt_internal_ip_address ' => $ this ->_vcloud_nsxt_internal_ip_address ,
226+ 'vcloud_nsxt_destination_ip_address ' => $ this ->_vcloud_nsxt_destination_ip_address ,
227+ 'port ' => $ this ->_port ,
228+ 'logging ' => $ this ->_logging ,
229+ ),
230+ '_nsxt_edge_gateway_id ' => $ this ->_nsxt_edge_gateway_id ,
231+ );
232+
233+ $ dataJSON = json_encode ($ data );
234+ $ this ->setAPIResource ( $ this ->getResource ( ONAPP_GETRESOURCE_DEFAULT ) );
235+ $ response = $ this ->sendRequest ( ONAPP_REQUEST_METHOD_POST , $ dataJSON );
236+
237+ $ result = $ this ->_castResponseToClass ( $ response );
238+ $ this ->_obj = $ result ;
239+ }
240+
241+ public function deleteOnappNatRulesBatchDestroy ($ nsxtNatRulesIdentifiers )
242+ {
243+ $ data = array (
244+ 'nsxt_nat_rules_identifiers ' => $ nsxtNatRulesIdentifiers ,
245+ 'nsxt_edge_gateway_id ' => $ this ->_nsxt_edge_gateway_id ,
246+ );
247+
248+ $ dataJSON = json_encode ($ data );
249+ $ this ->setAPIResource ( $ this ->getResource ( ONAPP_NAT_RULES_BATCH_DESTROY ) );
250+ $ response = $ this ->sendRequest ( ONAPP_REQUEST_METHOD_DELETE , $ dataJSON );
251+
252+ $ result = $ this ->_castResponseToClass ( $ response );
253+ $ this ->_obj = $ result ;
254+ }
255+
160256 /**
161257 * Activates action performed with object
162258 *
@@ -167,7 +263,6 @@ function getResource( $action = ONAPP_GETRESOURCE_DEFAULT ) {
167263 function activateCheck ( $ action_name ) {
168264 switch ( $ action_name ) {
169265 case ONAPP_ACTIVATE_LOAD :
170- case ONAPP_ACTIVATE_SAVE :
171266 case ONAPP_ACTIVATE_DELETE :
172267 exit ( 'Call to undefined method ' . __CLASS__ . ':: ' . $ action_name . '() ' );
173268 break ;
0 commit comments