diff --git a/api/api_file_template.yaml b/api/api_file_template.yaml deleted file mode 100644 index 9f49ff221..000000000 --- a/api/api_file_template.yaml +++ /dev/null @@ -1,16 +0,0 @@ -|2+ - //nolint:revive - package $pkg_name - - // The following file has been autogenerated. Please avoid any changes! - import ( - "errors" - - vapiProtocolClient_ "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client" - $imports - - $utl_pkg_import - ) - - type $context_type - diff --git a/api/api_list.yaml b/api/api_list.yaml deleted file mode 100644 index f76a5d54e..000000000 --- a/api/api_list.yaml +++ /dev/null @@ -1,1144 +0,0 @@ -################### -### API implementations: -# - api_packages: -### API client package path -# - client: -### API model path -# model: -### API type (Local/Global/Multitenancy/VPC) -# type: -### Attributes to be ignored while implementing a method -# ignore_params: -### List results Model path -# list_result_model: -### Name of model within model path package (should be same in all implementations) -# model_name: -### Used to create client name, variable names etc. -# obj_name: -### List of methods which are supported by API -# supported_method: -### Variable name (for cases when variable isn't compliant with ${obj_name}Param template -# var_name: -### List API results type (for cases when results struct isn't compliant with ${model_name}ListResult template -# list_result_name: -### Prefix for model type in API code -# model_prefix: -### Model value is passed as pointer (true/false, defaults to false) -# model_pass_ptr: -### File name for API wrapper output -# file_name: -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: IPDiscoveryProfile - obj_name: IpDiscoveryProfile - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: PolicyContextProfile - obj_name: ContextProfile - var_name: policyContextProfileParam - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/context_profiles/custom_attributes - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/context_profiles/custom_attributes - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/context_profiles/custom_attributes - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - client_name: DefaultClient - model_name: PolicyCustomAttributes - obj_name: ContextProfileCustomAttribute - var_name: policyCustomAttributesParam - list_result_name: PolicyContextProfileListResult - supported_method: - - New - - Create - - List - - Patch -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: DhcpRelayConfig - obj_name: DhcpRelayConfig - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: DhcpServerConfig - obj_name: DhcpServerConfig - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: PolicyDnsForwarderZone - obj_name: DnsForwarderZone - var_name: policyDnsForwarderZoneParam - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_0s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - model_name: PolicyDnsForwarder - obj_name: DnsForwarder - client_name: DnsForwarderClient - var_name: policyDnsForwarderParam - supported_method: - - New - - Get - - Patch - - Update - - Delete -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: PolicyDnsForwarder - obj_name: DnsForwarder - client_name: DnsForwarderClient - var_name: policyDnsForwarderParam - supported_method: - - New - - Get - - Patch - - Update - - Delete -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/domains - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/domains - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/domains - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: VPC - model_name: GatewayPolicy - obj_name: GatewayPolicy - client_name: GatewayPoliciesClient - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - model_name: Tier0 - obj_name: Tier0 - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_0s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - model_name: LocaleServices - obj_name: LocaleService - var_name: localeServicesParam - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/domains - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/domains - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/domains - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: VPC - ignore_params: - Delete: - - failIfSubtreeExistsParam - - forceParam - model_name: Group - obj_name: Group - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: IpAddressPool - obj_name: IpPool - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/ip_pools - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/ip_pools - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: IpAddressAllocation - obj_name: IpAllocation - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: IpAddressBlock - obj_name: IpBlock - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/realized_state - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/realized_state - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/realized_state - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: RealizedEntity - obj_name: RealizedEntity - client_name: RealizedEntitiesClient - list_result_name: GenericPolicyRealizedResourceListResult - supported_method: - - New - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/ip_pools - model: github.com/vmware/vsphere-automation-sdk-go/runtime/data - list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/ip_pools - model: github.com/vmware/vsphere-automation-sdk-go/runtime/data - list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: StructValue - obj_name: IpSubnets - client_name: IpSubnetsClient - list_result_name: IpAddressPoolSubnetListResult - model_prefix: vapiData_ - model_pass_ptr: true - file_name: IpSubnetsClient - supported_method: - - New - - Get - - Delete - - Patch - - Update - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/runtime/data - list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/runtime/data - list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/runtime/data - list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: StructValue - obj_name: DhcpStaticBindingConfig - client_name: DhcpStaticBindingConfigsClient - list_result_name: DhcpStaticBindingConfigListResult - model_prefix: vapiData_ - model_pass_ptr: true - file_name: DhcpStaticBindingConfig - supported_method: - - New - - Get - - Delete - - Patch - - Update - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: MacDiscoveryProfile - obj_name: MacDiscoveryProfile - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: Tier1 - obj_name: Tier1 - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List - -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/nat - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_0s/nat - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - model_name: PolicyNatRule - obj_name: NatRule - var_name: policyNatRuleParam - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/nat - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_1s/nat - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/tier_1s/nat - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: PolicyNatRule - obj_name: NatRule - var_name: policyNatRuleParam - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/domains - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/domains - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/domains - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: VPC - model_name: SecurityPolicy - obj_name: SecurityPolicy - client_name: SecurityPoliciesClient - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: QosProfile - obj_name: QosProfile - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: Service - obj_name: Service - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_0s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - model_name: StaticRoutes - obj_name: StaticRoute - var_name: staticRoutesParam - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: StaticRoutes - obj_name: StaticRoute - var_name: staticRoutesParam - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: GatewayQosProfile - obj_name: GatewayQosProfile - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: Ipv6DadProfile - obj_name: Ipv6DadProfile - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: Ipv6NdraProfile - obj_name: Ipv6NdraProfile - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: Segment - obj_name: Segment - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: SegmentConfigurationState - obj_name: State - client_name: StateClient - supported_method: - - New - - Get - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: SegmentSecurityProfile - obj_name: SegmentSecurityProfile - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: SpoofGuardProfile - obj_name: SpoofguardProfile - var_name: spoofGuardProfileParam - supported_method: - - New - - Get - - Patch - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: LocaleServices - obj_name: LocaleService - var_name: localeServicesParam - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/realized_state - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/realized_state - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: VirtualMachine - obj_name: VirtualMachine - supported_method: - - New - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: SegmentPort - obj_name: Port - var_name: segmentPortParam - supported_method: - - New - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: SegmentPort - obj_name: Port - var_name: segmentPortParam - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/locale_services - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_1s/locale_services - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/tier_1s/locale_services - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: Tier1Interface - obj_name: Interface - var_name: tier1InterfaceParam - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: Segment - obj_name: Segment - supported_method: - - New - - Get - - Patch - - Update - - Delete - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/segments - model: github.com/vmware/vsphere-automation-sdk-go/runtime/data - list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_1s/segments - model: github.com/vmware/vsphere-automation-sdk-go/runtime/data - list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/tier_1s/segments - model: github.com/vmware/vsphere-automation-sdk-go/runtime/data - list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: StructValue - obj_name: DhcpStaticBindingConfig - client_name: DhcpStaticBindingConfigsClient - list_result_name: DhcpStaticBindingConfigListResult - model_prefix: vapiData_ - model_pass_ptr: true - file_name: DhcpStaticBindingConfig - supported_method: - - New - - Get - - Delete - - Patch - - Update - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/tier_1s/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: SegmentPort - obj_name: Port - var_name: segmentPortParam - supported_method: - - New - - List - - Update -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: Infra - obj_name: Infra - client_name: InfraClient - supported_method: - - New - - Get - - Patch -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: SegmentDiscoveryProfileBindingMap - obj_name: SegmentDiscoveryProfileBindingMap - supported_method: - - New - - Get - - Delete - - Patch - - Update - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: SegmentQosProfileBindingMap - obj_name: SegmentQosProfileBindingMap - supported_method: - - New - - Get - - Delete - - Patch - - Update - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/segments - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: SegmentSecurityProfileBindingMap - obj_name: SegmentSecurityProfileBindingMap - supported_method: - - New - - Get - - Delete - - Patch - - Update - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/context_profiles - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/context_profiles - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/context_profiles - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: Attribute - obj_name: Attribute - list_result_name: PolicyContextProfileListResult - supported_method: - - New - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/domains/security_policies - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/domains/security_policies - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/domains/security_policies - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: Rule - obj_name: Rule - client_name: RulesClient - list_result_name: RuleListResult - supported_method: - - New - - Get - - Delete - - Patch - - Update - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/settings/firewall/security - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/settings/firewall/security - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - model_name: PolicyExcludeList - obj_name: PolicyExcludeList - client_name: ExcludeListClient - supported_method: - - New - - Get - - Patch - - Update -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/domains - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/domains - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: IdsSecurityPolicy - obj_name: IdsSecurityPolicy - client_name: IntrusionServicePoliciesClient - supported_method: - - New - - Get - - Delete - - List - - Patch - - Update - -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/settings/firewall/security/intrusion_services - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/settings/firewall/security/intrusion_services - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: IdsProfile - obj_name: IdsProfile - client_name: ProfilesClient - supported_method: - - New - - Get - - Delete - - List - - Patch - - Update -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/runtime/data - list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra - model: github.com/vmware/vsphere-automation-sdk-go/runtime/data - list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/runtime/data - list_result_model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: StructValue - obj_name: FloodProtectionProfiles - client_name: FloodProtectionProfilesClient - list_result_name: FloodProtectionProfileListResult - model_prefix: vapiData_ - model_pass_ptr: true - file_name: FloodProtectionProfilesClient - supported_method: - - New - - Get - - Delete - - Patch - - Update - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/domains/groups - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/domains/groups - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/domains/groups - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: PolicyFirewallFloodProtectionProfileBindingMap - obj_name: PolicyFirewallFloodProtectionProfileBindingMap - client_name: FirewallFloodProtectionProfileBindingMapsClient - list_result_name: PolicyFirewallFloodProtectionProfileBindingMapListResult - supported_method: - - New - - Get - - Delete - - Patch - - Update - - List -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_0s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - model_name: FloodProtectionProfileBindingMap - obj_name: FloodProtectionProfileBindingMap - client_name: FloodProtectionProfileBindingsClient - supported_method: - - New - - Get - - Delete - - Patch - - Update -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_0s/locale_services - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_0s/locale_services - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - model_name: FloodProtectionProfileBindingMap - obj_name: FloodProtectionProfileBindingMap - client_name: FloodProtectionProfileBindingsClient - supported_method: - - New - - Get - - Delete - - Patch - - Update -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/tier_1s - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: FloodProtectionProfileBindingMap - obj_name: FloodProtectionProfileBindingMap - client_name: FloodProtectionProfileBindingsClient - supported_method: - - New - - Get - - Delete - - Patch - - Update -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/tier_1s/locale_services - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra/tier_1s/locale_services - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model - type: Global - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/tier_1s/locale_services - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: FloodProtectionProfileBindingMap - obj_name: FloodProtectionProfileBindingMap - client_name: FloodProtectionProfileBindingsClient - supported_method: - - New - - Get - - Delete - - Patch - - Update -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: Share - obj_name: Share - client_name: SharesClient - supported_method: - - New - - Get - - Delete - - Patch - - Update -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/shares - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/shares - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: SharedResource - obj_name: ShareResource - client_name: ResourcesClient - supported_method: - - New - - Get - - Delete - - Patch - - Update -- api_packages: - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Local - - client: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra - model: github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model - type: Multitenancy - model_name: L7AccessProfile - obj_name: L7AccessProfile - supported_method: - - New - - Get - - Delete - - Patch - - Update diff --git a/api/api_templates.yaml b/api/api_templates.yaml deleted file mode 100644 index a9e04d54b..000000000 --- a/api/api_templates.yaml +++ /dev/null @@ -1,200 +0,0 @@ -New: - Convert: |2 - - case utl.${type}: - client = ${client_import}.${api_func_call} - NoConvert: |2 - - case utl.${type}: - client = ${client_import}.${api_func_call} - main: |2 - - func ${api_func_def} { - var client interface{} - - switch sessionContext.ClientType { - ${case_items} - default: - return nil - } - return &${model_name}ClientContext{Client: client, ClientType: sessionContext.ClientType, ProjectID: sessionContext.ProjectID, VPCID: sessionContext.VPCID} - } -Get: - Convert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - gmObj, err1 := client.${api_func_call} - if err1 != nil { - return obj, err1 - } - var rawObj interface{} - rawObj, err = utl.ConvertModelBindingType(gmObj, ${model_import}.${model_name}BindingType(), ${main_model_import}.${model_name}BindingType()) - obj = rawObj.(${main_model_import}.${model_name}) - NoConvert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - obj, err = client.${api_func_call} - if err != nil { - return obj, err - } - main: |2 - - func ${api_func_def} { - var obj ${ptr_prefix}${main_model_import}.${model_name} - var err error - - switch c.ClientType { - ${case_items} - default: - return obj, errors.New("invalid infrastructure for model") - } - return obj, err - } -Patch: - Convert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - gmObj, err1 := utl.ConvertModelBindingType(${var_name}, ${main_model_import}.${model_name}BindingType(), ${model_import}.${model_name}BindingType()) - if err1 != nil { - return err1 - } - err = client.${api_func_call} - NoConvert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - err = client.${api_func_call} - main: |2 - - func ${api_func_def} { - var err error - - switch c.ClientType { - ${case_items} - default: - err = errors.New("invalid infrastructure for model") - } - return err - } -Update: - Convert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - gmObj, err := utl.ConvertModelBindingType(${var_name}, ${main_model_import}.${model_name}BindingType(), ${model_import}.${model_name}BindingType()) - if err != nil { - return obj, err - } - gmObj, err = client.${api_func_call} - if err != nil { - return obj, err - } - obj1, err1 := utl.ConvertModelBindingType(gmObj, ${model_import}.${model_name}BindingType(), ${main_model_import}.${model_name}BindingType()) - if err1 != nil { - return obj, err1 - } - obj = obj1.(${main_model_import}.${model_name}) - NoConvert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - obj, err = client.${api_func_call} - main: |2 - - func ${api_func_def} { - var err error - var obj ${ptr_prefix}${main_model_import}.${model_name} - - switch c.ClientType { - ${case_items} - default: - err = errors.New("invalid infrastructure for model") - } - return obj, err - } -Delete: - Convert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - err = client.${api_func_call} - NoConvert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - err = client.${api_func_call} - main: |2 - - func ${api_func_def} { - var err error - - switch c.ClientType { - ${case_items} - default: - err = errors.New("invalid infrastructure for model") - } - return err - } -List: - Convert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - gmObj, err := client.${api_func_call} - if err != nil { - return obj, err - } - obj1, err1 := utl.ConvertModelBindingType(gmObj, ${list_model_import}.${list_result_name}BindingType(), ${list_main_model_import}.${list_result_name}BindingType()) - if err1 != nil { - return obj, err1 - } - obj = obj1.(${list_main_model_import}.${list_result_name}) - NoConvert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - obj, err = client.${api_func_call} - main: |2 - - func ${api_func_def} { - var err error - var obj ${list_main_model_import}.${list_result_name} - - switch c.ClientType { - ${case_items} - default: - err = errors.New("invalid infrastructure for model") - } - return obj, err - } - -Create: - Convert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - gmObj, err1 := utl.ConvertModelBindingType(${var_name}, ${main_model_import}.${model_name}BindingType(), ${model_import}.${model_name}BindingType()) - if err1 != nil { - return err1 - } - err = client.${api_func_call} - NoConvert: |2 - - case utl.${type}: - client := c.Client.(${client_import}.${client_name}) - err = client.${api_func_call} - main: |2 - - func ${api_func_def} { - var err error - - switch c.ClientType { - ${case_items} - default: - err = errors.New("invalid infrastructure for model") - } - return err - } diff --git a/api/utl_file_template.yaml b/api/utl_file_template.yaml deleted file mode 100644 index 5fecfdf6b..000000000 --- a/api/utl_file_template.yaml +++ /dev/null @@ -1,40 +0,0 @@ -|2+ - //nolint:revive - package $pkg_name - - // The following file has been autogenerated. Please avoid any changes! - import "github.com/vmware/vsphere-automation-sdk-go/runtime/bindings" - - type ClientType int - - const ( - DefaultOrgID = "default" - $const - ) - - type SessionContext struct { - ClientType ClientType - ProjectID string - VPCID string - } - type ClientContext struct { - Client interface{} - ClientType ClientType - ProjectID string - VPCID string - } - - func ConvertModelBindingType(obj interface{}, sourceType bindings.BindingType, destType bindings.BindingType) (interface{}, error) { - converter := bindings.NewTypeConverter() - dataValue, err := converter.ConvertToVapi(obj, sourceType) - if err != nil { - return nil, err[0] - } - - gmObj, err := converter.ConvertToGolang(dataValue, destType) - if err != nil { - return nil, err[0] - } - - return gmObj, nil - } diff --git a/tools/api-wrapper-generator.py b/tools/api-wrapper-generator.py deleted file mode 100644 index fe626e551..000000000 --- a/tools/api-wrapper-generator.py +++ /dev/null @@ -1,348 +0,0 @@ -#!/usr/bin/python3 - -# © Broadcom. All Rights Reserved. -# The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. -# SPDX-License-Identifier: MPL-2.0 - -import argparse -import atexit -import git -import os -import re -import shutil -import string -import tempfile -import yaml - -SDK_REPO = 'github.com/vmware/vsphere-automation-sdk-go' -SDK_BASE_PATH = 'services/nsxt' -TF_PROVIDER_REPO = 'github.com/vmware/terraform-provider-nsxt' - - -def cleanup(): - try: - # TODO: uncomment - shutil.rmtree(get_func_definition.repo_path) - pass - except (FileNotFoundError, AttributeError): - pass - - -def mkpath(path): - if not os.path.isdir(path): - os.makedirs(path) - - -def get_pkg_name_from_path(path): - return path.split('/')[-1].replace("_", "") - - -def camel_to_snake(name): - name = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) - return re.sub('([a-z0-9])([A-Z])', r'\1_\2', name).lower() - - -def get_yaml_file(fname): - with open(fname) as f: - return yaml.safe_load(f) - - -def var_name(var): - # Variable names within function defs are the obj_name but with 1st char lowercase - return var[0].lower() + var[1:] - - -def get_arglist(arg_str): - # Retrieve function argument list from function definition - arg_list = arg_str.replace(', ', ',').split(',') - return [arg[0] for arg in [a.split(' ') for a in arg_list]] - - -def parse_new_call(func_def): - # Parse New* definition - try: - r = parse_new_call.regex - except AttributeError: - r = re.compile('func\s+(.*)\((.*)\)\s+(.*)\s+\{.*') - parse_new_call.regex = r - - m = r.match(func_def) - return m.groups() - - -def new_func_call_setup(api, subs_dict): - g = parse_new_call(subs_dict['func_def']) - arg_list = get_arglist(g[1]) - return '%s(%s)' % (g[0], ', '.join(arg_list)) - - -def find_api_package_attributes(api, type): - for a in api['api_packages']: - if type == a['type']: - return a - - -def api_func_call_setup(api, subs_dict): - g = parse_api_call(subs_dict['func_def']) - arg_list = get_arglist(g[2]) - if subs_dict['type'] == "Multitenancy": - arg_list = ['utl.DefaultOrgID', 'c.ProjectID'] + arg_list - elif subs_dict['type'] == "VPC": - arg_list = ['utl.DefaultOrgID', 'c.ProjectID', 'c.VPCID'] + arg_list - arg_list.remove('domainIdParam') - attrs = find_api_package_attributes(api, subs_dict['type']) - x = attrs.get('ignore_params', {}) - for n in attrs.get('ignore_params', {}).get(g[1], []): - arg_list.remove(n) - - return '%s(%s)' % (g[1], ', '.join(arg_list)) - - -def patch_func_call_setup(api, subs_dict): - g = parse_api_call(subs_dict['func_def']) - arg_list = get_arglist(g[2]) - if api['template_type'] == 'Convert': - for n in range(0, len(arg_list)): - if arg_list[n] == subs_dict['var_name']: - arg_list[n] = 'gmObj.(%s.%s)' % (subs_dict['model_import'], subs_dict['model_name']) - elif subs_dict['type'] == "Multitenancy": - arg_list = ['utl.DefaultOrgID', 'c.ProjectID'] + arg_list - elif subs_dict['type'] == "VPC": - arg_list = ['utl.DefaultOrgID', 'c.ProjectID', 'c.VPCID'] + arg_list - arg_list.remove('domainIdParam') - return '%s(%s)' % (g[1], ', '.join(arg_list)) - - -def parse_api_call(func_def): - # Parse API definition - try: - r = parse_api_call.regex - except AttributeError: - r = re.compile('func\s+(.*)\s+(.*)\((.*)\)\s+(.*)\s+\{') - parse_api_call.regex = r - - m = r.match(func_def) - return m.groups() - - -def new_func_def_setup(subs_dict): - # Prepare New* definition from function definition - g = parse_new_call(subs_dict['func_def']) - return '%s(sessionContext utl.SessionContext, %s) *%sClientContext' % (g[0], g[1], subs_dict['model_name']) - - -def api_func_def_setup(subs_dict): - # Prepare API definition from function definition - func_def = subs_dict['func_def'].replace('%s.' % subs_dict['model_prefix'], '%s.' % subs_dict['main_model_import']) - g = parse_api_call(func_def) - return '(c %sClientContext) %s(%s) %s' % (subs_dict['model_name'], g[1], g[2], g[3]) - - -def list_func_def_setup(subs_dict): - # Prepare API definition from function definition - func_def = subs_dict['func_def'].replace('nsx_policyModel.', '%s.' % subs_dict['list_main_model_import']) - g = parse_api_call(func_def) - return '(c %sClientContext) %s(%s) %s' % (subs_dict['model_name'], g[1], g[2], g[3]) - - -def get_func_definition(api, func, path): - # Retrieve func definition from SDK repo - try: - repo_path = get_func_definition.repo_path - - except AttributeError: - # Get SDK repo from GitHub - repo_path = tempfile.mkdtemp() - git.Repo.clone_from('https://%s' % SDK_REPO, repo_path) - get_func_definition.repo_path = repo_path - - fname = api.get('client_name', '%ssClient' % api['obj_name']) - with open('%s/%s/%s.go' % (repo_path, path.replace(SDK_REPO, ''), fname), 'r') as f: - for line in f: - if line.startswith('func ') and ' ' + func + '(' in line: - return line - raise Exception('No function definition found for %s for model %s' % (func, api['model_name'])) - - -FUNC_DEF_CALLBACK = { - 'New': new_func_def_setup, - 'Create': api_func_def_setup, - 'Get': api_func_def_setup, - 'Patch': api_func_def_setup, - 'Update': api_func_def_setup, - 'Delete': api_func_def_setup, - 'List': list_func_def_setup -} - -FUNC_CALL_CALLBACK = { - 'New': new_func_call_setup, - 'Get': api_func_call_setup, - 'Create': patch_func_call_setup, - 'Patch': patch_func_call_setup, - 'Update': patch_func_call_setup, - 'Delete': api_func_call_setup, - 'List': api_func_call_setup -} - -atexit.register(cleanup) - - -def get_args(): - parser = argparse.ArgumentParser( - prog='api-wrapper-generator.py', - description='Generate API wrappers for NSX Golang SDK') - parser.add_argument('--api_list', required=True) - parser.add_argument('--api_templates', required=True) - parser.add_argument('--api_file_template', required=True) - parser.add_argument('--utl_file_template', required=True) - parser.add_argument('--out_dir', required=True) - return parser.parse_args() - - -def get_dicts_from_yaml(api_list_file, api_template_file, api_file_template_file, utl_file_template_file): - api_list = get_yaml_file(api_list_file) - api_templates = get_yaml_file(api_template_file) - api_file_template = get_yaml_file(api_file_template_file) - utl_file_template = get_yaml_file(utl_file_template_file) - - return api_list, api_templates, api_file_template, utl_file_template - - -def format_file(f): - os.system('gofmt -s -w %s' % f) - - -def write_utl_file(out_dir, utl_file_template): - # Create type definitions - type_set = set() - for api in api_list: - for pkg in api['api_packages']: - type_set.add(pkg['type']) - - # Build type list - n = 0 - type_list = [] - for t in sorted(type_set): - type_list.append(" %s = %d" % (t, n)) - n += 1 - - template = string.Template(utl_file_template) - output = template.substitute({ - "const": "\n".join(type_list), - "pkg_name": get_pkg_name_from_path(out_dir)}) - - utl_dir = out_dir + '/utl' - mkpath(utl_dir) - outfile = '%s/api_util.go' % utl_dir - with open(outfile, 'w') as f: - f.write(output) - - format_file(outfile) - - -def write_api_file(api, out_dir, api_file_template): - client_dict = {} - model_dict = {} - list_model_dict = {} - - for pkg in api['api_packages']: - if not client_dict.get(pkg['client']): - client_dict[pkg['client']] = 'client%d' % len(client_dict) - if not model_dict.get(pkg['model']): - model_dict[pkg['model']] = 'model%d' % len(model_dict) - if pkg.get('list_result_model') and not list_model_dict.get(pkg['list_result_model']): - list_model_dict[pkg['list_result_model']] = 'lrmodel%d' % len(list_model_dict) - # Build import list - import_dict = client_dict.copy() - import_dict.update(model_dict.copy()) - import_dict.update(list_model_dict.copy()) - import_list = [' %s "%s"' % (import_dict[s], s) for s in sorted(import_dict.keys())] - - template = string.Template(api_file_template) - context_type = '%sClientContext utl.ClientContext' % api['model_name'] - - pkg_name = get_pkg_name_from_path(api['api_packages'][0]['client']) - output = template.substitute({ - "imports": "\n".join(import_list), - "context_type": context_type, - "utl_pkg_import": 'utl "%s/%s"' % (TF_PROVIDER_REPO, os.path.relpath(out_dir + '/utl')), - "pkg_name": pkg_name}) - - subs_dict = { - "client_name": api.get('client_name', '%ssClient' % api['obj_name']), - "obj_name": api['obj_name'], - "model_name": api['model_name'], - "var_name": api.get('var_name', '%sParam' % var_name(api['obj_name'])), - "list_result_name": api.get('list_result_name', '%sListResult' % api['model_name']), - "model_prefix": api.get('model_prefix', 'nsx_policyModel'), - "ptr_prefix": '*' if api.get('model_pass_ptr') else '' - } - main_model_import = None - list_main_model_import = None - out_path = None - api_list = api.get('supported_method', api_templates.keys()) - for api_name in api_list: - tpl = api_templates[api_name] - case_items = "" - for pkg in api['api_packages']: - model_import = model_dict[pkg["model"]] - client_import = client_dict[pkg["client"]] - list_model_import = list_model_dict.get(pkg.get("list_result_model"), model_import) - if main_model_import is None: - main_model_import = model_import - list_main_model_import = list_model_import - out_path = pkg["client"].replace(SDK_REPO, '').replace(SDK_BASE_PATH, '') - if api_name == 'New': - if api.get('client_name'): - func_name = 'New%s' % api['client_name'] - else: - func_name = 'New%ssClient' % api['obj_name'] - else: - func_name = api_name - func_def = get_func_definition(api, func_name, api['api_packages'][0]['client']) - subs_dict.update({ - "client_import": client_import, - "model_import": model_import, - "main_model_import": main_model_import, - "list_model_import": list_model_import, - "list_main_model_import": list_main_model_import, - "func_def": func_def, - "type": pkg['type'] - }) - if api_name != 'List' and model_import == main_model_import: - api['template_type'] = "NoConvert" - elif api_name == 'List' and list_model_import == list_main_model_import: - api['template_type'] = "NoConvert" - else: - api['template_type'] = "Convert" - if FUNC_DEF_CALLBACK.get(api_name): - subs_dict['api_func_def'] = FUNC_DEF_CALLBACK[api_name](subs_dict) - if FUNC_CALL_CALLBACK.get(api_name): - subs_dict['api_func_call'] = FUNC_CALL_CALLBACK[api_name](api, subs_dict) - template = string.Template(tpl[api['template_type']]) - case_items += template.substitute(subs_dict) - - template = string.Template(tpl['main']) - subs_dict['case_items'] = case_items - output += template.substitute(subs_dict) - - mkpath('%s/%s' % (out_dir, out_path)) - outfile = '%s/%s/%s.go' % (out_dir, out_path, camel_to_snake(api.get('file_name', api['model_name']))) - with open(outfile, 'w') as f: - f.write(output) - - format_file(outfile) - - -args = get_args() -api_list, api_templates, api_file_template, utl_file_template = get_dicts_from_yaml(args.api_list, args.api_templates, - args.api_file_template, - args.utl_file_template) -out_dir = args.out_dir - -write_utl_file(out_dir, utl_file_template) - -for api in api_list: - write_api_file(api, out_dir, api_file_template) - -exit(0) diff --git a/tools/data_source_nsxt_policy_doc_template b/tools/data_source_nsxt_policy_doc_template deleted file mode 100644 index 8077e0326..000000000 --- a/tools/data_source_nsxt_policy_doc_template +++ /dev/null @@ -1,33 +0,0 @@ ---- -subcategory: "FIXME" -page_title: "NSXT: policy_" -description: Policy data source. ---- - -# nsxt_policy_ - -This data source provides information about policy configured on NSX. - -This data source is applicable to NSX Global Manager, NSX Policy Manager and VMC. - -## Example Usage - -```hcl -data "nsxt_policy_" "test" { - display_name = "1" -} -``` - -## Argument Reference - -* `id` - (Optional) The ID of to retrieve. - -* `display_name` - (Optional) The Display Name prefix of the to retrieve. - -## Attributes Reference - -In addition to arguments listed above, the following attributes are exported: - -* `description` - The description of the resource. - -* `path` - The NSX path of the policy resource. diff --git a/tools/data_source_nsxt_policy_template b/tools/data_source_nsxt_policy_template deleted file mode 100644 index 407ad1e54..000000000 --- a/tools/data_source_nsxt_policy_template +++ /dev/null @@ -1,38 +0,0 @@ -// © Broadcom. All Rights Reserved. -// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. -// SPDX-License-Identifier: MPL-2.0 - -package nsxt - -import ( - "fmt" - "strings" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra" - "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" -) - -func dataSourceNsxtPolicy() *schema.Resource { - return &schema.Resource{ - Read: dataSourceNsxtPolicyRead, - - Schema: map[string]*schema.Schema{ - "id": getDataSourceIDSchema(), - "display_name": getDataSourceDisplayNameSchema(), - "description": getDataSourceDescriptionSchema(), - "path": getPathSchema(), - }, - } -} - -func dataSourceNsxtPolicyRead(d *schema.ResourceData, m interface{}) error { - connector := getPolicyConnector(m) - - _, err := policyDataSourceResourceRead(d, connector, isPolicyGlobalManager(m), "", nil) - if err != nil { - return err - } - - return nil -} diff --git a/tools/data_source_nsxt_policy_test_template b/tools/data_source_nsxt_policy_test_template deleted file mode 100644 index eaed237d5..000000000 --- a/tools/data_source_nsxt_policy_test_template +++ /dev/null @@ -1,129 +0,0 @@ -// © Broadcom. All Rights Reserved. -// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. -// SPDX-License-Identifier: MPL-2.0 - -package nsxt - -import ( - "fmt" - "testing" - - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra" - "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" - gm_infra "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra" - gm_model "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model" -) - -func TestAccDataSourceNsxtPolicy_basic(t *testing.T) { - name := getAccTestDataSourceName() - testResourceName := "data.nsxt_policy_.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: func(state *terraform.State) error { - return testAccDataSourceNsxtPolicyDeleteByName(name) - }, - Steps: []resource.TestStep{ - { - PreConfig: func() { - if err := testAccDataSourceNsxtPolicyCreate(name); err != nil { - panic(err) - } - }, - Config: testAccNsxtPolicyReadTemplate(name), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(testResourceName, "display_name", name), - resource.TestCheckResourceAttr(testResourceName, "description", name), - resource.TestCheckResourceAttrSet(testResourceName, "path"), - ), - }, - { - Config: testAccNsxtPolicyEmptyTemplate(), - }, - }, - }) -} - -func testAccDataSourceNsxtPolicyCreate(name string) error { - connector, err := testAccGetPolicyConnector() - if err != nil { - return fmt.Errorf("Error during test client initialization: %v", err) - } - - displayName := name - description := name - obj := model.{ - Description: &description, - DisplayName: &displayName, - } - - // Generate a random ID for the resource - uuid, _ := uuid.NewRandom() - id := uuid.String() - - if testAccIsGlobalManager() { - gmObj, convErr := convertModelBindingType(obj, model.BindingType(), gm_model.BindingType()) - if convErr != nil { - return convErr - } - - client := gm_infra.NewDefaultsClient(connector) - err = client.Patch(id, gmObj.(gm_model.)) - - } else { - client := infra.NewDefaultsClient(connector) - err = client.Patch(id, obj) - } - if err != nil { - return fmt.Errorf("Error during creation: %v", err) - } - return nil -} - -func testAccDataSourceNsxtPolicyDeleteByName(name string) error { - connector, err := testAccGetPolicyConnector() - if err != nil { - return fmt.Errorf("Error during test client initialization: %v", err) - } - - // Find the object by name - if testAccIsGlobalManager() { - objID, err := testGetObjIDByName(name, "") - if err == nil { - client := gm_infra.NewDefaultsClient(connector) - err := client.Delete(objID) - if err != nil { - return handleDeleteError("", objID, err) - } - return nil - } - } else { - client := infra.NewDefaultsClient(connector) - objList, err := client.List(nil, nil, nil, nil, nil, nil) - if err != nil { - return fmt.Errorf("Error while reading s: %v", err) - } - for _, objInList := range objList.Results { - if *objInList.DisplayName == name { - err := client.Delete(*objInList.Id) - if err != nil { - return fmt.Errorf("Error during deletion: %v", err) - } - return nil - } - } - } - return fmt.Errorf("Error while deleting '%s': resource not found", name) -} - -func testAccNsxtPolicyReadTemplate(name string) string { - return fmt.Sprintf(` -data "nsxt_policy_" "test" { - display_name = "%s" -}`, name) -} - diff --git a/tools/diffy/diffy.py b/tools/diffy/diffy.py deleted file mode 100755 index 948903288..000000000 --- a/tools/diffy/diffy.py +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/python -# -*- coding: latin-1 -*- - -# © Broadcom. All Rights Reserved. -# The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. -# SPDX-License-Identifier: MPL-2.0 - -# This script detects difference in model between different versions of NSX spec. List of relevant objects is for now hard-coded. - -import sys -import re -import os -import json - -OBJECTS = [ -"ContextProfile", -"DhcpRelayConfig", -"DhcpServerConfig", -"Domain", -"EvpnConfig", -"EvpnTenantConfig", -"GatewayPolicy", -"Group", -"IPSecVpnDpdProfile", -"IPSecVpnIkeProfile", -"IPSecVpnService", -"IPSecVpnTunnelProfile", -"IPSecVpnLocalEndpoint", -"IdsPolicy", -"IdsProfile", -"IpAddressBlock", -"IpAddressPool", -"L2VPNService", -"L2VPNSession", -"LBPool", -"LBService", -"LBVirtualServer", -"MacDiscoveryProfile", -"OspfConfig", -"PolicyDnsForwarder", -"PolicyNatRule", -"PrefixList", -"QoSProfile", -"SecurityPolicy", -"Segment", -"Service", -"StaticRoutes", -"Tier0", -"Tier0Interface", -"Tier1", -"Tier1Interface"] - -def load_spec(path): - - with open(path, 'r') as f: - spec = json.load(f) - - obj_map = {} - defs = spec["definitions"] - for key in defs: - if "allOf" not in defs[key]: - if "properties" in defs[key]: - # no inheritance - obj_map[key] = defs[key]["properties"] - continue - if len(defs[key]["allOf"]) == 2: - # object inheritance - if "properties" not in defs[key]["allOf"][1]: - continue - obj_map[key] = defs[key]["allOf"][1]["properties"] - - return obj_map - -def ref_to_def(ref): - return ref[len("#definitions/ "):] - -def print_ident(text, level): - ident = " "*level - print("%s%s" % (ident, text)) - -class color: - PURPLE = '\033[95m' - BLUE = '\033[94m' - GREEN = '\033[92m' - END = '\033[0m' - -def main(): - - if len(sys.argv) < 3: - print("Usage: %s " % sys.argv[0]) - sys.exit() - - baseline_file_path = sys.argv[1] - target_file_path = sys.argv[2] - baseline_map = load_spec(baseline_file_path) - target_map = load_spec(target_file_path) - level = 0 - - def analyze_obj(obj, level): - print_ident("analyzing %s.." % obj, level) - if obj not in baseline_map: - return - for attr in target_map[obj]: - if attr not in baseline_map[obj]: - print_ident(color.BLUE + "new attribute %s" % attr + color.END, level + 1) - - if "$ref" in target_map[obj][attr]: - analyze_obj(ref_to_def(target_map[obj][attr]["$ref"]), level + 1) - if "items" in target_map[obj][attr] and "$ref" in target_map[obj][attr]["items"]: - analyze_obj(ref_to_def(target_map[obj][attr]["items"]["$ref"]), level + 1) - if "enum" in target_map[obj][attr] and attr in baseline_map[obj]: - target_set = set(target_map[obj][attr]["enum"]) - baseline_set = set(baseline_map[obj][attr]["enum"]) - diff = target_set - baseline_set - if diff: - print_ident(color.GREEN + "new enum values for attribute %s: %s" % (attr, diff) + color.END, level + 1) - - for attr in baseline_map[obj]: - if obj not in target_map: - continue - if attr not in target_map[obj]: - print_ident(color.PURPLE + "deleted attribute %s" % attr + color.END, level + 1) - - for obj in OBJECTS: - analyze_obj(obj, level + 1) - - - print("Done.") - -main() diff --git a/tools/policygen.py b/tools/policygen.py deleted file mode 100755 index 0ea0d1fb6..000000000 --- a/tools/policygen.py +++ /dev/null @@ -1,629 +0,0 @@ -#!/usr/bin/python -# -*- coding: latin-1 -*- - -# © Broadcom. All Rights Reserved. -# The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. -# SPDX-License-Identifier: MPL-2.0s - -# Generating Resources: -# 1. Run the following command: python policygen.py -# 2. Format generated go files with: go fmt -# 3. The generated files end up in your current directory; move them to the proper directory. -# 4. Add the resource to provider.go. -# 5. Make sure go is happy with the format by running golint and go vet on the source files. -# 6. Run the generated test(s) to ensure they pass. - -import sys -import re -import os -import json - -PACKAGE_NAME = "nsxt" - -# TODO: clone when opensourced -# TODO: support non-infra resources/data sources -try: - GO_PATH = os.environ['GOPATH'] -except Exception: - print("Please set GOPATH in your environment") - exit(2) - -BASE_SDK_PATH = "%s/src/github.com/vmware/vsphere-automation-sdk-go/services/nsxt" % GO_PATH -NSX_SPEC_PATH = "nsx_policy_vapi.json" -STRUCTS_FILE = "%s/model/ModelPackageTypes.go" % BASE_SDK_PATH -TEMPLATE_RESOURCE_FILE = "resource_nsxt_policy_template" -TEMPLATE_RESOURCE_TEST_FILE = "resource_nsxt_policy_test_template" -TEMPLATE_RESOURCE_DOC_FILE = "resource_nsxt_policy_doc_template" -TEMPLATE_DATA_SOURCE_FILE = "data_source_nsxt_policy_template" -TEMPLATE_DATA_SOURCE_TEST_FILE = "data_source_nsxt_policy_test_template" -TEMPLATE_DATA_SOURCE_DOC_FILE = "data_source_nsxt_policy_doc_template" - -DONT_SPLIT_US = ["IP", "LB", "SSL", "TCP", "UDP"] - -# Resource-specific attributes are either in the beginning or the end -FIRST_COMMON_ATTR = "Links []ResourceLink" -LAST_COMMON_ATTR = "Overridden *bool" - -TYPE_MAP = {"string": "schema.TypeString", - "integer": "schema.TypeInt", - "boolean": "schema.TypeBool"} - -DEFAULT_VALUES_MAP = {"string": '"test"', - "int32": 2, - "int64": 2, - "bool": 'true'} - -TEST_CREATE_VALUES_MAP = {"string": '"test-create"', - "int32": '"2"', - "int64": '"2"', - "bool": '"true"'} - -TEST_UPDATE_VALUES_MAP = {"string": '"test-update"', - "int32": '"5"', - "int64": '"5"', - "bool": '"false"'} - -TYPECAST_MAP = {"int64": "int", "int32": "int"} - -# Metadata will contain all attributes of the given object, including nested ones -# Parent attribute will have `object_type` key set to indicate model type of the child object -# Child attributes will have `parent` key set -metadata = {} -api_spec = {} - -def to_lower_separated(name): - tmp = re.sub(r'([A-Z])', r'_\1', name).lower() - for abbr in DONT_SPLIT_US: - split_abbr = re.sub(r'([A-Z])', r'_\1', abbr).lower() - tmp = tmp.replace(split_abbr[1:], abbr.lower()) - - return tmp[1:] - -def lowercase_first(name): - return name[:1].lower() + name[1:] - -def name_to_upper(name): - return name.title().replace('_', '') - -def to_upper_separated(name): - tmp = re.sub(r'([A-Z])', r'_\1', name).upper()[1:] - for abbr in DONT_SPLIT_US: - split_abbr = re.sub(r'([A-Z])', r'_\1', abbr) - tmp = tmp.replace(split_abbr[1:], abbr) - - return tmp - -def get_const_values_name(attr_name): - return "%s%sValues" % (lowercase_first(metadata['resource']), attr_name) - -def build_enums(): - - result = "" - for attr in metadata['attrs']: - if not attr['const_needed']: - continue - - result += "\nvar %s = []string{\n" % get_const_values_name(attr['name']) - const_candidate = "%s_%s" % (metadata['resource'], to_upper_separated(attr['name'])) - for const in metadata['constants'].keys(): - if const.startswith(const_candidate): - result += "model.%s,\n" % const - - result += "}\n" - - return result - -def get_value_for_const(attr, num=1): - const_candidate = "%s_%s" % (metadata['resource'], to_upper_separated(attr['name'])) - for name, value in metadata['constants'].items(): - if name.startswith(const_candidate): - num -= 1 - if num == 0: - return value - - -def convert_value_to_hcl(attr_type, attr_value): - if attr_type == "string": - return "\"%s\"" % attr_value - - if attr_type == "bool": - if attr_value: - return "true" - return "false" - - # int and other - return attr_value - -def build_schema_attr(attr): - - result = "" - is_array = False - is_object = False - attr['const_needed'] = False - attr['object_type'] = "" - attr_type = attr['type'] - print(attr_type) - # Computed and required attributes are not ref. At the moment we can't - # distinguish between them and assume required, since this will necessarily - # error out in test. - # TODO: parse spec json for this purpose - - optional = not attr['required'] - if attr['list'] and attr_type != 'object': - # Handle arrays. By default, arrays are translated to sets - # assuming in most cases order is not significant. When order is - # significant, these should be changed to lists - attr['helper'] = "%sListFromSchemaSet" % name_to_upper(attr_type) - is_array = True - - if attr_type == 'object': - load_resource_metadata(attr_type, attr['name']) - attr['object_type'] = attr_type - is_object = True - is_array = True - - result += "\"%s\": {\n" % attr['schema_name'] - - if is_array: - result += "Type: schema.TypeList,\n" - else: - result += "Type: %s,\n" % attr_type - - #TODO: concatenate multi-string comment, and remove enum specs - #if attr['description']: - # result += "Description: \"%s\"," % attr['description'] - - const_candidate = "%s_%s" % (metadata['resource'], to_upper_separated(attr['name'])) - if attr['type'] == "string": - for const in metadata['constants'].keys(): - if const.startswith(const_candidate): - attr['const_needed'] = True - - validation = None - if attr['const_needed']: - validation = "ValidateFunc: validation.StringInSlice(%s, false),\n" % get_const_values_name(attr['name']) - - if is_array: - if is_object: - result += "Elem: &schema.Resource{\n" - result += "Schema: map[string]*schema.Schema{\n" - result += build_schema_attrs(attr['name']) - result += "},\n" - else: - result += "Elem: &schema.Schema{\n" - result += "Type: %s,\n" % attr_type - if validation: - result += validation - result += "},\n" - elif validation: - result += validation - - if optional: - result += "Optional: true,\n" - else: - result += "Required: true,\n" - - if attr['default']: - result += "Default: %s,\n" % convert_value_to_hcl(attr['type'], attr['default']) - - result += "},\n" - - return result - -def build_get_attr_from_schema(attr): - if attr['object_type'] != "": - # sub-clause - nameBase = lowercase_first(attr['name']) - result = '%sList := d.Get("%s").(%s)\n' % ( - nameBase, - attr['schema_name'], - '[]interface{}') - if attr["list"]: - result += 'var %s []model.%s\n' % (nameBase, attr['object_type']) - else: - result += 'var %s *model.%s\n' % (nameBase, attr['object_type']) - - result += 'for _, item := range %sList {\n' % nameBase - result += 'data := item.(map[string]interface{})\n' - for childAttr in metadata['attrs']: - if childAttr['parent'] == attr['name']: - result += build_get_attr_from_schema(childAttr) - - result += 'obj := model.%s{\n' % attr['object_type'] - result += build_set_attrs_in_obj(attr['name']) - result += '}\n' - if attr["list"]: - result += '%s = append(%s, obj)\n}\n' % (nameBase, nameBase) - else: - result += '%s = &obj\nbreak}\n' % nameBase - - return result - - if 'helper' in attr: - # helper function name already computed - this is the case for arrays - return '%s := get%s(d, "%s")\n' % ( - lowercase_first(attr['name']), - attr['helper'], - attr['schema_name']) - - if attr['parent'] != "": - if attr['type'] in TYPECAST_MAP: - # type casting is needed - return '%s := %s(data["%s"].(%s))\n' % ( - lowercase_first(attr['name']), - attr['type'], - attr['schema_name'], - TYPECAST_MAP[attr['type']]) - return '%s := data["%s"].(%s)\n' % ( - lowercase_first(attr['name']), - attr['schema_name'], - attr['type']) - - if attr['type'] in TYPECAST_MAP: - # type casting is needed - return '%s := %s(d.Get("%s").(%s))\n' % ( - lowercase_first(attr['name']), - attr['type'], - attr['schema_name'], - TYPECAST_MAP[attr['type']]) - return '%s := d.Get("%s").(%s)\n' % ( - lowercase_first(attr['name']), - attr['schema_name'], - attr['type']) - - -def build_enum_var_name(resource, attr, value): - return "model.%s_%s_%s" % (resource, to_upper_separated(attr), to_upper_separated(value)) - -def standartize(v): - if isinstance(v, unicode): - return v.encode('ascii','ignore') - return v - -def load_resource_metadata(resource, parent=""): - - stage = "" - description = "" - api_spec = load_json_spec(resource) - for attr, attr_spec in api_spec.items(): - schema_name = standartize(attr) - sdk_name = name_to_upper(schema_name) - attr_type = standartize(attr_spec.get('type')) - if 'enum' in attr_spec: - for enum_value in attr_spec['enum']: - enum_value = standartize(enum_value) - var_name = build_enum_var_name(resource, schema_name, enum_value) - metadata['constants'][var_name] = enum_value - - print(schema_name) - print(attr_type) - if attr_type not in TYPE_MAP: - if schema_name.endswith('es'): - schema_name = schema_name[:-2] - if schema_name.endswith('s'): - schema_name = schema_name[:-1] - - default = standartize(attr_spec.get('default')) - if attr_spec.get('x-deprecated'): - print("Skipping deprecated attribute %s" % schema_name) - continue - - full_type = TYPE_MAP.get(attr_type) - is_ref = False - is_list = False - if attr_type == 'None': - if '$ref' in attr_spec: - print("REF") - is_ref = True - full_type = attr_spec['$ref'].split('/')[:1] - - if attr_type == 'array': - is_list = True - items = attr_spec.get('items') - if '$ref' in items: - full_type = standartize(items['$ref'].split('/')[:1]) - if 'type' in items: - full_type = standartize(items['type']) - - metadata['attrs'].append({'name': sdk_name, - 'parent': parent, - 'description': standartize(attr_spec.get('description')), - 'type': full_type, - 'list': is_list, - 'ref': is_ref, - 'schema_name': schema_name, - 'default': default, - 'required': False}) - metadata["name_map"][sdk_name] = schema_name - print(metadata) - - -def build_schema_attrs(parent=""): - result = "" - for attr in metadata['attrs']: - if attr['parent'] == parent: - result += build_schema_attr(attr) - - return result - - -def build_get_attrs_from_schema(parent=""): - result = "" - for attr in metadata['attrs']: - if parent != attr['parent']: - continue - result += build_get_attr_from_schema(attr) - - return result - - -def build_set_attrs_in_obj(parent=""): - result = "" - for attr in metadata['attrs']: - if attr['parent'] != parent: - continue - if attr['list'] or attr['object_type'] != "": - result += "%s: %s,\n" % (attr['name'], lowercase_first(attr['name'])) - else: - result += "%s: &%s,\n" % (attr['name'], lowercase_first(attr['name'])) - - return result - - -def build_set_obj_attrs_in_schema(parent=""): - result = "" - for attr in metadata['attrs']: - if attr['parent'] != parent: - continue - if attr['object_type'] != "": - nameBase = lowercase_first(attr['name']) - result += 'var %sList []map[string]interface{}\n' % nameBase - if attr['list']: - result += 'for _, item := range obj.%s {\n' % attr['name'] - else: - result += 'item := obj.%s\n' % attr['name'] - result += 'data := make(map[string]interface{})\n' - result += build_set_obj_attrs_in_schema(attr['name']) - result += '%sList = append(%sList, data)\n' % (nameBase, nameBase) - if attr['list']: - result += '}\n' - result += 'd.Set("%s", %sList)\n'% (attr['schema_name'], nameBase) - return result - - if attr['parent']: - result += 'data["%s"] = item.%s\n'% (attr['schema_name'], attr['name']) - else: - result += 'd.Set("%s", obj.%s)\n'% (attr['schema_name'], attr['name']) - - return result - - -def build_test_attrs(required_only=False, parent="", indent=" "): - - result = "" - for attr in metadata['attrs']: - if required_only and not attr['required']: - continue - if parent != attr['parent']: - continue - if attr['object_type'] != "": - result += "\n%s%s {\n" % (indent, attr['schema_name']) - result += build_test_attrs(required_only, attr['name'], indent + " ") - result += "%s}\n\n" % indent - continue - - result += "%s%s = " % (indent, attr['schema_name']) - if attr['list']: - result += '[' - if attr['type'] == 'string': - result += '"%s"' - else: - result += '%s' - if attr['list']: - result += ']' - - result += "\n" - - return result - - -def build_test_attrs_map(is_create=True): - - result = "" - values_map = TEST_CREATE_VALUES_MAP if is_create else TEST_UPDATE_VALUES_MAP - for attr in metadata['attrs']: - value = "" - if attr['const_needed']: - num = 1 if is_create else 2 - value = get_value_for_const(attr, num) - elif attr['type'] in values_map: - value = values_map[attr['type']] - if value: - result += '"%s": %s,\n' % (attr["schema_name"], value) - - return result - - -def build_check_test_attrs(is_create=True): - - result = "" - for attr in metadata['attrs']: - attrStr = attr['schema_name'] - if attr['parent']: - parentSchemaName = metadata['name_map'][attr['parent']] - attrStr = "%s.0.%s" % (parentSchemaName, attr['schema_name']) - if attr['object_type']: - result += 'resource.TestCheckResourceAttr(testResourceName, "%s.#", "1"),\n' % attrStr - continue - if attr['list']: - result += 'resource.TestCheckResourceAttr(testResourceName, "%s.0", ' % attrStr - else: - result += 'resource.TestCheckResourceAttr(testResourceName, "%s", ' % attrStr - result += 'accTestPolicy%s%sAttributes["%s"]),\n' % (metadata['resource'], "Create" if is_create else "Update", attr['schema_name']) - - return result - - -def build_doc_attrs(): - doc_attrs = "" - for attr in metadata['attrs']: - if attr['object_type'] or attr['parent']: - continue - optional = attr['ref'] or attr['list'] - if attr['const_needed']: - value = get_value_for_const(attr) - else: - if attr['type'] in DEFAULT_VALUES_MAP: - value = DEFAULT_VALUES_MAP[attr['type']] - else: - value = "FILL VALUE FOR %s" % attr['type'] - - if not value: - value = "FILL ENUM VALUE" - doc_attrs += "%s = %s\n" % (attr['schema_name'], value) - - return doc_attrs - - -def build_doc_attrs_reference(parent="", indent=""): - result = "" - - for attr in metadata['attrs']: - if attr['parent'] != parent: - continue - result += "%s* `%s` - (%s) %s\n" % (indent, attr['schema_name'], - "Required" if attr['required'] else "Optional", attr['description']) - if attr['object_type']: - result += build_doc_attrs_reference(attr['name'], indent + " ") - return result - - -def build_test_attrs_sprintf(required_only=False): - result = "" - - for attr in metadata['attrs']: - if required_only and not attr['required']: - continue - if attr['object_type']: - continue - result += ', attrMap["%s"]' % attr['schema_name'] - return result - - -def generate_replace_targets(): - metadata['schema_attrs'] = build_schema_attrs() - metadata['enums'] = build_enums() - metadata['set_attrs_in_obj'] = build_set_attrs_in_obj() - metadata['get_attrs_from_schema'] = build_get_attrs_from_schema() - metadata['set_obj_attrs_in_schema'] = build_set_obj_attrs_in_schema() - metadata['doc_attrs'] = build_doc_attrs() - metadata['doc_attrs_reference'] = build_doc_attrs_reference() - metadata['test_attrs'] = build_test_attrs() - metadata['test_required_attrs'] = build_test_attrs(True) - metadata['test_attrs_create'] = build_test_attrs_map() - metadata['test_attrs_update'] = build_test_attrs_map(False) - metadata['check_attrs_create'] = build_check_test_attrs() - metadata['check_attrs_update'] = build_check_test_attrs(False) - metadata['test_attrs_sprintf'] = build_test_attrs_sprintf() - metadata['test_required_attrs_sprintf'] = build_test_attrs_sprintf(True) - - -def replace_templates(line): - result = line.replace("", metadata['resource']) - result = result.replace("", "%ss" % metadata['resource']) - result = result.replace("", metadata['module']) - result = result.replace("", metadata['schema_attrs']) - result = result.replace("", metadata['get_attrs_from_schema']) - result = result.replace("", metadata['set_attrs_in_obj']) - result = result.replace("", metadata['set_obj_attrs_in_schema']) - result = result.replace("", metadata['enums']) - result = result.replace("", metadata['resource_lower']) - result = result.replace("", metadata['resource-lower']) - result = result.replace("", metadata['test_attrs']) - result = result.replace("", metadata['test_required_attrs']) - result = result.replace("", metadata['test_attrs_create']) - result = result.replace("", metadata['test_attrs_update']) - result = result.replace("", metadata['test_attrs_sprintf']) - result = result.replace("", metadata['test_required_attrs_sprintf']) - result = result.replace("", metadata['check_attrs_create']) - result = result.replace("", metadata['check_attrs_update']) - result = result.replace("", metadata['doc_attrs']) - result = result.replace("", metadata['doc_attrs_reference']) - result = result.replace("PolicyPolicy", "Policy") - return result - -def load_json_spec(resource): - - with open(NSX_SPEC_PATH, 'r') as f: - spec = json.load(f) - - defs = spec["definitions"] - if resource not in defs: - return {} - - if "allOf" not in defs[resource]: - if "properties" in defs[resource]: - # no inheritance - return defs[resource]["properties"] - return {} - if len(defs[resource]["allOf"]) == 2: - # object inheritance - if "properties" not in defs[resource]["allOf"][1]: - return {} - return defs[resource]["allOf"][1]["properties"] - - return {} - -def main(): - - if len(sys.argv) < 2: - print("Usage: %s [data]" % sys.argv[0]) - sys.exit() - - generate_data_source = False - if len(sys.argv) == 3 and sys.argv[2] == 'data': - generate_data_source = True - - resource = sys.argv[1] - metadata['resource'] = resource - metadata['module'] = resource[0].lower() + resource[1:] + 's' - resource_lower = to_lower_separated(resource) - if resource_lower.startswith("policy_"): - # remove double "policy" indication - resource_lower = resource_lower[len("policy_"):] - metadata['resource_lower'] = resource_lower - metadata['resource-lower'] = resource_lower.replace('_','-') - metadata["constants"] = {} - metadata["attrs"] = [] - metadata["name_map"] = {} - print("Building resource from %s" % resource) - - print("Loading metadata..") - load_resource_metadata(resource) - generate_replace_targets() - - spec = {} - if generate_data_source: - spec = {TEMPLATE_DATA_SOURCE_FILE: "data_source_nsxt_policy_%s.go" % resource_lower, - TEMPLATE_DATA_SOURCE_TEST_FILE: "data_source_nsxt_policy_%s_test.go" % resource_lower, - TEMPLATE_DATA_SOURCE_DOC_FILE: "policy_%s.md" % resource_lower} - - else: - spec = {TEMPLATE_RESOURCE_FILE: "resource_nsxt_policy_%s.go" % resource_lower, - TEMPLATE_RESOURCE_TEST_FILE: "resource_nsxt_policy_%s_test.go" % resource_lower, - TEMPLATE_RESOURCE_DOC_FILE: "policy_%s.md" % resource_lower} - - for source, target in spec.items(): - print("Generating %s.." % target) - with open(source, 'r') as f: - lines = f.readlines() - - with open(target, 'w') as f: - for line in lines: - f.write(replace_templates(line)) - - print("Formatting..") - os.system("go fmt") - print("Done.") - -main() diff --git a/tools/resource_nsxt_policy_doc_template b/tools/resource_nsxt_policy_doc_template deleted file mode 100644 index bbc929ad7..000000000 --- a/tools/resource_nsxt_policy_doc_template +++ /dev/null @@ -1,51 +0,0 @@ ---- -subcategory: "FIXME" -page_title: "NSXT: nsxt_policy_" -description: A resource to configure a . ---- - -# nsxt_policy_ - -This resource provides a method for the management of a . - -This resource is applicable to NSX Global Manager, NSX Policy Manager and VMC. - -## Example Usage - -```hcl -resource "nsxt_policy_" "test" { - display_name = "test" - description = "Terraform provisioned " - -} -``` - -## Argument Reference - -The following arguments are supported: - -* `display_name` - (Required) Display name of the resource. -* `description` - (Optional) Description of the resource. -* `tag` - (Optional) A list of scope + tag pairs to associate with this resource. -* `nsx_id` - (Optional) The NSX ID of this resource. If set, this ID will be used to create the resource. - - -## Attributes Reference - -In addition to arguments listed above, the following attributes are exported: - -* `id` - ID of the resource. -* `revision` - Indicates current revision number of the object as seen by NSX-T API server. This attribute can be useful for debugging. -* `path` - The NSX path of the policy resource. - -## Importing - -An existing object can be [imported][docs-import] into this resource, via the following command: - -[docs-import]: https://developer.hashicorp.com/terraform/cli/import - -```shell -terraform import nsxt_policy_.test UUID -``` - -The above command imports named `test` with the NSX ID `UUID`. diff --git a/tools/resource_nsxt_policy_template b/tools/resource_nsxt_policy_template deleted file mode 100644 index ee0b0eb3e..000000000 --- a/tools/resource_nsxt_policy_template +++ /dev/null @@ -1,190 +0,0 @@ -// © Broadcom. All Rights Reserved. -// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. -// SPDX-License-Identifier: MPL-2.0 - -package nsxt - -import ( - "fmt" - "log" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/vmware/vsphere-automation-sdk-go/runtime/protocol/client" - "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra" - "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/model" - gm_infra "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/global_infra" - gm_model "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-gm/model" -) - - - -func resourceNsxtPolicy() *schema.Resource { - return &schema.Resource{ - Create: resourceNsxtPolicyCreate, - Read: resourceNsxtPolicyRead, - Update: resourceNsxtPolicyUpdate, - Delete: resourceNsxtPolicyDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "nsx_id": getNsxIDSchema(), - "path": getPathSchema(), - "display_name": getDisplayNameSchema(), - "description": getDescriptionSchema(), - "revision": getRevisionSchema(), - "tag": getTagsSchema(), - - }, - } -} - -func resourceNsxtPolicyExists(id string, connector client.Connector, isGlobalManager bool) (bool, error) { - var err error - if isGlobalManager { - client := gm_infra.NewsClient(connector) - _, err = client.Get(id) - } else { - client := infra.NewsClient(connector) - _, err = client.Get(id) - } - if err == nil { - return true, nil - } - - if isNotFoundError(err) { - return false, nil - } - - return false, logAPIError("Error retrieving resource", err) -} - -func resourceNsxtPolicyPatch(d *schema.ResourceData, m interface{}, id string) error { - connector := getPolicyConnector(m) - - displayName := d.Get("display_name").(string) - description := d.Get("description").(string) - tags := getPolicyTagsFromSchema(d) - - - obj := model.{ - DisplayName: &displayName, - Description: &description, - Tags: tags, - - } - - log.Printf("[INFO] Patching with ID %s", id) - if isPolicyGlobalManager(m) { - gmObj, convErr := convertModelBindingType(obj, model.BindingType(), gm_model.BindingType()) - if convErr != nil { - return convErr - } - client := gm_infra.NewsClient(connector) - return client.Patch(id, gmObj.(gm_model.)) - } - - client := infra.NewsClient(connector) - return client.Patch(id, obj) -} - -func resourceNsxtPolicyCreate(d *schema.ResourceData, m interface{}) error { - - // Initialize resource Id and verify this ID is not yet used - id, err := getOrGenerateID(d, m, resourceNsxtPolicyExists) - if err != nil { - return err - } - - err = resourceNsxtPolicyPatch(d, m, id) - if err != nil { - return handleCreateError("", id, err) - } - - d.SetId(id) - d.Set("nsx_id", id) - - return resourceNsxtPolicyRead(d, m) -} - -func resourceNsxtPolicyRead(d *schema.ResourceData, m interface{}) error { - connector := getPolicyConnector(m) - - id := d.Id() - if id == "" { - return fmt.Errorf("Error obtaining ID") - } - - var obj model. - if isPolicyGlobalManager(m) { - client := gm_infra.NewsClient(connector) - gmObj, err := client.Get(id) - if err != nil { - return handleReadError(d, "", id, err) - } - - lmObj, err := convertModelBindingType(gmObj, gm_model.BindingType(), model.BindingType()) - if err != nil { - return err - } - obj = lmObj.(model.) - } else { - client := infra.NewsClient(connector) - var err error - obj, err = client.Get(id) - if err != nil { - return handleReadError(d, "", id, err) - } - } - - d.Set("display_name", obj.DisplayName) - d.Set("description", obj.Description) - setPolicyTagsInSchema(d, obj.Tags) - d.Set("nsx_id", id) - d.Set("path", obj.Path) - d.Set("revision", obj.Revision) - - - - return nil -} - -func resourceNsxtPolicyUpdate(d *schema.ResourceData, m interface{}) error { - - id := d.Id() - if id == "" { - return fmt.Errorf("Error obtaining ID") - } - - err := resourceNsxtPolicyPatch(d, m, id) - if err != nil { - return handleUpdateError("", id, err) - } - - return resourceNsxtPolicyRead(d, m) -} - -func resourceNsxtPolicyDelete(d *schema.ResourceData, m interface{}) error { - id := d.Id() - if id == "" { - return fmt.Errorf("Error obtaining ID") - } - - connector := getPolicyConnector(m) - var err error - if isPolicyGlobalManager(m) { - client := gm_infra.NewsClient(connector) - err = client.Delete(id) - } else { - client := infra.NewsClient(connector) - err = client.Delete(id) - } - - if err != nil { - return handleDeleteError("", id, err) - } - - return nil -} diff --git a/tools/resource_nsxt_policy_test_template b/tools/resource_nsxt_policy_test_template deleted file mode 100644 index c4e62f849..000000000 --- a/tools/resource_nsxt_policy_test_template +++ /dev/null @@ -1,174 +0,0 @@ -// © Broadcom. All Rights Reserved. -// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. -// SPDX-License-Identifier: MPL-2.0 - -package nsxt - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" -) - -var accTestPolicyCreateAttributes = map[string]string{ - "display_name": getAccTestResourceName(), - "description": "terraform created", - -} - -var accTestPolicyUpdateAttributes = map[string]string{ - "display_name": getAccTestResourceName(), - "description": "terraform updated", - -} - -func TestAccResourceNsxtPolicy_basic(t *testing.T) { - testResourceName := "nsxt_policy_.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: func(state *terraform.State) error { - return testAccNsxtPolicyCheckDestroy(state, accTestPolicyUpdateAttributes["display_name"]) - }, - Steps: []resource.TestStep{ - { - Config: testAccNsxtPolicyTemplate(true), - Check: resource.ComposeTestCheckFunc( - testAccNsxtPolicyExists(accTestPolicyCreateAttributes["display_name"], testResourceName), - resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyCreateAttributes["display_name"]), - resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyCreateAttributes["description"]), - - resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), - resource.TestCheckResourceAttrSet(testResourceName, "path"), - resource.TestCheckResourceAttrSet(testResourceName, "revision"), - resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), - ), - }, - { - Config: testAccNsxtPolicyTemplate(false), - Check: resource.ComposeTestCheckFunc( - testAccNsxtPolicyExists(accTestPolicyUpdateAttributes["display_name"], testResourceName), - resource.TestCheckResourceAttr(testResourceName, "display_name", accTestPolicyUpdateAttributes["display_name"]), - resource.TestCheckResourceAttr(testResourceName, "description", accTestPolicyUpdateAttributes["description"]), - - resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), - resource.TestCheckResourceAttrSet(testResourceName, "path"), - resource.TestCheckResourceAttrSet(testResourceName, "revision"), - resource.TestCheckResourceAttr(testResourceName, "tag.#", "1"), - ), - }, - { - Config: testAccNsxtPolicyMinimalistic(), - Check: resource.ComposeTestCheckFunc( - testAccNsxtPolicyExists(accTestPolicyCreateAttributes["display_name"], testResourceName), - resource.TestCheckResourceAttr(testResourceName, "description", ""), - resource.TestCheckResourceAttrSet(testResourceName, "nsx_id"), - resource.TestCheckResourceAttrSet(testResourceName, "path"), - resource.TestCheckResourceAttrSet(testResourceName, "revision"), - resource.TestCheckResourceAttr(testResourceName, "tag.#", "0"), - ), - }, - }, - }) -} - -func TestAccResourceNsxtPolicy_importBasic(t *testing.T) { - name := getAccTestResourceName() - testResourceName := "nsxt_policy_.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: func(state *terraform.State) error { - return testAccNsxtPolicyCheckDestroy(state, name) - }, - Steps: []resource.TestStep{ - { - Config: testAccNsxtPolicyMinimalistic(), - }, - { - ResourceName: testResourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccNsxtPolicyExists(displayName string, resourceName string) resource.TestCheckFunc { - return func(state *terraform.State) error { - - connector := getPolicyConnector(testAccProvider.Meta().(nsxtClients)) - - rs, ok := state.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Policy resource %s not found in resources", resourceName) - } - - resourceID := rs.Primary.ID - if resourceID == "" { - return fmt.Errorf("Policy resource ID not set in resources") - } - - exists, err := resourceNsxtPolicyExists(resourceID, connector, testAccIsGlobalManager()) - if err != nil { - return err - } - if !exists { - return fmt.Errorf("Policy %s does not exist", resourceID) - } - - return nil - } -} - -func testAccNsxtPolicyCheckDestroy(state *terraform.State, displayName string) error { - connector := getPolicyConnector(testAccProvider.Meta().(nsxtClients)) - for _, rs := range state.RootModule().Resources { - - if rs.Type != "nsxt_policy_" { - continue - } - - resourceID := rs.Primary.Attributes["id"] - exists, err := resourceNsxtPolicyExists(resourceID, connector, testAccIsGlobalManager()) - if err == nil { - return err - } - - if exists { - return fmt.Errorf("Policy %s still exists", displayName) - } - } - return nil -} - -func testAccNsxtPolicyTemplate(createFlow bool) string { - var attrMap map[string]string - if createFlow { - attrMap = accTestPolicyCreateAttributes - } else { - attrMap = accTestPolicyUpdateAttributes - } - return fmt.Sprintf(` -resource "nsxt_policy_" "test" { - display_name = "%s" - description = "%s" - - tag { - scope = "scope1" - tag = "tag1" - } -}`, attrMap["display_name"], attrMap["description"]) -} - -func testAccNsxtPolicyMinimalistic() string { - return fmt.Sprintf(` -resource "nsxt_policy_" "test" { - display_name = "%s" - -}`, accTestPolicyUpdateAttributes["display_name"]) -} diff --git a/tools/terragen.py b/tools/terragen.py deleted file mode 100755 index be3287e12..000000000 --- a/tools/terragen.py +++ /dev/null @@ -1,530 +0,0 @@ -#!/usr/bin/python -# -*- coding: latin-1 -*- - -# © Broadcom. All Rights Reserved. -# The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. -# SPDX-License-Identifier: MPL-2.0 - -import sys -import re - -PACKAGE_NAME = "nsxt" -SDK_PACKAGE_NAME = "api" -MANAGER_PACKAGE_NAME = "manager" - -IGNORE_ATTRS = ["Links", "Schema", "Self", "Id", "ResourceType", "CreateTime", "CreateUser", "LastModifiedTime", "LastModifiedUser", "SystemOwned", "Protection"] -COMPUTED_ATTRS = ["CreateTime", "CreateUser", "LastModifiedTime", "LastModifiedUser", "SystemOwned"] -COMPUTED_AND_OPTIONAL_ATTRS = ["DisplayName"] -FORCENEW_ATTRS = ["TransportZoneId"] -# TODO: ServiceBindings -VIP_SCHEMA_ATTRS = ["Tags", "SwitchingProfileIds", "Revision", "AddressBindings"] -VIP_GETTER_ATTRS = ["Tags", "SwitchingProfileIds", "AddressBindings"] -VIP_SETTER_ATTRS = VIP_GETTER_ATTRS - -TYPE_MAP = {"string": "schema.TypeString", - "int32": "schema.TypeInt", - "int64": "schema.TypeInt", - "bool": "schema.TypeBool"} - -TYPECAST_MAP = {"int64": "int", "int32": "int"} - -indent = 0 - - -def name_to_lower(name): - tmp = re.sub(r'([A-Z])', r'_\1', name).lower() - return tmp[1:] - -def lowercase_first(name): - return name[:1].lower() + name[1:] - -def name_to_upper(name): - return name.title().replace('_', '') - -def is_list_complex_attr(attr): - if attr['type'].startswith('[]'): - # this is a list. - if attr['type'][2:] not in TYPE_MAP: - # complex type: needs to be in a single form - return True - return False - - -def get_attr_fixed_name(attr): - fixed_name = attr['name'] - if is_list_complex_attr(attr) and fixed_name.endswith('s'): - # remove last s - fixed_name = fixed_name[:-1] - fixed_name = name_to_lower(fixed_name) - return fixed_name - - -def shift(): - global indent - indent += 1 - - -def unshift(): - global indent - indent -= 1 - - -def pretty_writeln(f, line): - for i in range(indent): - f.write("\t") - f.write(line) - f.write("\n") - - -def write_header(f): - pretty_writeln(f, "// © Broadcom. All Rights Reserved.") - pretty_writeln(f, "// The term \"Broadcom\" refers to Broadcom Inc. and/or its subsidiaries.") - pretty_writeln(f, "// SPDX-License-Identifier: MPL-2.0\n") - - pretty_writeln(f, "package %s\n" % PACKAGE_NAME) - pretty_writeln(f, "import (") - shift() - pretty_writeln(f, "\"fmt\"") - pretty_writeln(f, "\"github.com/hashicorp/terraform/helper/schema\"") - pretty_writeln(f, "%s \"github.com/vmware/go-vmware-nsxt\"" % SDK_PACKAGE_NAME) - pretty_writeln(f, "\"github.com/vmware/go-vmware-nsxt/%s\"" % MANAGER_PACKAGE_NAME) - pretty_writeln(f, "\"log\"") - pretty_writeln(f, "\"net/http\"") - unshift() - pretty_writeln(f, ")\n") - - -def write_attr(f, attr): - fixed_name = get_attr_fixed_name(attr) - if attr['name'] in VIP_SCHEMA_ATTRS: - pretty_writeln(f, "\"%s\": get%sSchema()," % (fixed_name, attr['name'])) - return - - is_array = False - attr_type = attr['type'] - if attr_type.startswith("[]") and attr_type[2:] in TYPE_MAP: - # Handle arrays. By default, arrays are translated to sets - # assuming in most cases order is not significant. When order is - # significant, these should be changed to lists - # TODO: add both with choice comment - is_array = True - attr_type = attr_type[2:] - attr['helper'] = "%sListFromSchemaSet" % name_to_upper(attr_type) - - if attr_type not in TYPE_MAP: - print("Skipping attribute %s due to mysterious type %s" % (attr['name'], attr_type)) - return - - pretty_writeln(f, "\"%s\": &schema.Schema{" % fixed_name) - shift() - if is_array: - pretty_writeln(f, "Type: schema.TypeSet,") - else: - pretty_writeln(f, "Type: %s," % TYPE_MAP[attr_type]) - - comment = ' ' - if attr['comment']: - comment = attr['comment'] - if attr['name'] == 'DisplayName' and comment == 'Defaults to ID if not set': - comment = "The display name of this resource. " + comment - pretty_writeln(f, "Description: \"%s\"," % comment) - - if is_array: - pretty_writeln(f, "Elem: &schema.Schema{") - shift() - pretty_writeln(f, "Type: %s," % TYPE_MAP[attr_type]) - pretty_writeln(f, "ValidateFunc: validate%s," % name_to_upper(fixed_name)) - unshift() - pretty_writeln(f, "},") - - if attr['optional']: - pretty_writeln(f, "Optional: true,") - else: - pretty_writeln(f, "Required: true,") - if attr['name'] in FORCENEW_ATTRS: - pretty_writeln(f, "ForceNew: true,") - if attr['name'] in COMPUTED_ATTRS or attr['name'] in COMPUTED_AND_OPTIONAL_ATTRS: - pretty_writeln(f, "Computed: true,") - - unshift() - pretty_writeln(f, "},") - -def write_func_header(f, resource, operation): - f.write("\n") - pretty_writeln(f, "func resourceNsxt%s%s(d *schema.ResourceData, m interface{}) error {" % - (resource, operation)) - shift() - -def write_nsxclient(f): - pretty_writeln(f, "nsxClient := m.(*%s.APIClient)" % SDK_PACKAGE_NAME) - - -def write_get_id(f): - pretty_writeln(f, "id := d.Id()") - pretty_writeln(f, "if id == \"\" {") - shift() - pretty_writeln(f, "return fmt.Errorf(\"Error obtaining logical object id\")") - unshift() - pretty_writeln(f, "}\n") - - -def write_error_check(f, resource, operation): - if operation == "update": - pretty_writeln(f, "if err != nil || resp.StatusCode == http.StatusNotFound {") - else: - pretty_writeln(f, "if err != nil {") - - shift() - pretty_writeln(f, "return fmt.Errorf(\"Error during %s %s: " % (resource, operation) + '%v", err)') - unshift() - pretty_writeln(f, "}\n") - -def write_object(f, resource, attrs, is_create=True): - used_attrs = [] - for attr in attrs: - if (is_create and attr['name'] == 'Revision') or attr['name'] in COMPUTED_ATTRS: - # Revision is irrelevant in create - continue - - used_attrs.append(attr['name']) - fixed_name = get_attr_fixed_name(attr) - if 'helper' in attr: - # helper function name already computed - this is the case for arrays - pretty_writeln(f, '%s := get%s(d, "%s")' % ( - lowercase_first(attr['name']), - attr['helper'], - fixed_name)) - continue - - if attr['name'] in VIP_GETTER_ATTRS: - pretty_writeln(f, "%s := get%sFromSchema(d)" % ( - lowercase_first(attr['name']), attr['name'])) - continue - - if attr['type'] in TYPECAST_MAP: - # type casting is needed - pretty_writeln(f, "%s := %s(d.Get(\"%s\").(%s))" % - (lowercase_first(attr['name']), - attr['type'], - fixed_name, - TYPECAST_MAP[attr['type']])) - else: - pretty_writeln(f, "%s := d.Get(\"%s\").(%s)" % - (lowercase_first(attr['name']), - fixed_name, - attr['type'])) - - pretty_writeln(f, "%s := %s.%s{" % (lowercase_first(resource), MANAGER_PACKAGE_NAME, resource)) - shift() - for attr in used_attrs: - pretty_writeln(f, "%s: %s," % (attr, lowercase_first(attr))) - - unshift() - - pretty_writeln(f, "}\n") - -def write_create_func(f, resource, attrs, api_section): - - lower_resource = lowercase_first(resource) - - write_func_header(f, resource, "Create") - - write_nsxclient(f) - - write_object(f, resource, attrs) - - pretty_writeln(f, "%s, resp, err := nsxClient.%s.Create%s(nsxClient.Context, %s)" % ( - lower_resource, api_section, resource, lower_resource)) - - f.write("\n") - write_error_check(f, resource, "create") - - pretty_writeln(f, "if resp.StatusCode != http.StatusCreated {") - shift() - pretty_writeln(f, "return fmt.Errorf(\"Unexpected status returned during %s create: " % resource + '%v", resp.StatusCode)') - unshift() - pretty_writeln(f, "}") - - - pretty_writeln(f, "d.SetId(%s.Id)\n" % lower_resource) - - pretty_writeln(f, "return resourceNsxt%sRead(d, m)" % resource) - unshift() - pretty_writeln(f, "}") - - -def write_read_func(f, resource, attrs, api_section): - - lower_resource = lowercase_first(resource) - write_func_header(f, resource, "Read") - - write_nsxclient(f) - write_get_id(f) - - # For some resources this is GET and for other it is read - pretty_writeln(f, "//TerraGen TODO - select the right command for this resource, and delete this comment") - pretty_writeln(f, "%s, resp, err := nsxClient.%s.Get%s(nsxClient.Context, id)" % - (lower_resource, api_section, resource)) - pretty_writeln(f, "%s, resp, err := nsxClient.%s.Read%s(nsxClient.Context, id)" % - (lower_resource, api_section, resource)) - - write_error_check(f, resource, "read") - - pretty_writeln(f, "if resp.StatusCode == http.StatusNotFound {") - shift() - pretty_writeln(f, "log.Printf(\"[DEBUG] %s " % resource + '%s not found\", id)') - pretty_writeln(f, 'd.SetId("")') - pretty_writeln(f, "return nil") - unshift() - pretty_writeln(f, "}") - - - for attr in attrs: - if attr['name'] in IGNORE_ATTRS: - continue - - if attr['name'] in VIP_SETTER_ATTRS: - pretty_writeln(f, "set%sInSchema(d, %s.%s)" % ( - attr['name'], lower_resource, attr['name'])) - continue - - fixed_name = get_attr_fixed_name(attr) - pretty_writeln(f, "d.Set(\"%s\", %s.%s)" % - (fixed_name, lower_resource, attr['name'])) - - f.write("\n") - pretty_writeln(f, "return nil") - unshift() - pretty_writeln(f, "}") - - -def write_update_func(f, resource, attrs, api_section): - - lower_resource = lowercase_first(resource) - write_func_header(f, resource, "Update") - - write_nsxclient(f) - write_get_id(f) - - write_object(f, resource, attrs, is_create=False) - pretty_writeln(f, "%s, resp, err := nsxClient.%s.Update%s(nsxClient.Context, id, %s)" % ( - lower_resource, api_section, resource, lower_resource)) - - f.write("\n") - write_error_check(f, resource, "update") - - pretty_writeln(f, "return resourceNsxt%sRead(d, m)" % resource) - unshift() - pretty_writeln(f, "}") - - -def write_delete_func(f, resource, attrs, api_section): - - write_func_header(f, resource, "Delete") - - write_nsxclient(f) - write_get_id(f) - - pretty_writeln(f, "//TerraGen TODO - select the right command for this resource, and delete this comment") - pretty_writeln(f, "localVarOptionals := make(map[string]interface{})") - pretty_writeln(f, "resp, err := nsxClient.%s.Delete%s(nsxClient.Context, id, localVarOptionals)" % ( - api_section, resource)) - pretty_writeln(f, "resp, err := nsxClient.%s.Delete%s(nsxClient.Context, id)" % ( - api_section, resource)) - - write_error_check(f, resource, "delete") - - - pretty_writeln(f, "if resp.StatusCode == http.StatusNotFound {") - shift() - pretty_writeln(f, "log.Printf(\"[DEBUG] %s " % resource + '%s not found\", id)') - pretty_writeln(f, 'd.SetId("")') - unshift() - pretty_writeln(f, "}") - - pretty_writeln(f, "return nil") - unshift() - pretty_writeln(f, "}") - - -def write_doc_header(f, resource): - description = "Provides a resource to configure %s on NSX-T manager" % re.sub('_', ' ', resource) - pretty_writeln(f, "---") - pretty_writeln(f, "layout: \"nsxt\"") - pretty_writeln(f, "page_title: \"NSXT: nsxt_%s\"" % resource) - pretty_writeln(f, "sidebar_current: \"docs-nsxt-resource-%s\"" % re.sub('_', '-', resource)) - pretty_writeln(f, "description: |-") - pretty_writeln(f, " %s" % description) - pretty_writeln(f, "---\n") - pretty_writeln(f, "# nsxt_%s\n" % resource) - pretty_writeln(f, "%s\n" % description) - - -def write_doc_example(f, resource, attrs): - obj_name = resource - pretty_writeln(f, "## Example Usage\n") - pretty_writeln(f, "```hcl") - - pretty_writeln(f, "resource \"nsxt_%s\" \"%s\" {" % (resource, obj_name)) - for attr in attrs: - if attr['name'] == 'Revision' or attr['name'] in COMPUTED_ATTRS or attr['name'] in IGNORE_ATTRS: - continue - name = get_attr_fixed_name(attr) - val = "..." - eq = " = " - if name == 'display_name': - val = "\"%s\"" % obj_name - elif name == 'description': - val = "\"%s provisioned by Terraform\"" % obj_name - elif name == 'tag': - pretty_writeln(f, "") - val = "{\n scope = \"color\"\n tag = \"red\"\n }\n" - pretty_writeln(f, " %s%s%s" % (name, eq, val)) - - pretty_writeln(f, "}") - pretty_writeln(f, "```\n") - - -def write_arguments_reference(f, resource, attrs): - pretty_writeln(f, "## Argument Reference\n") - pretty_writeln(f, "The following arguments are supported:\n") - for attr in attrs: - if attr['name'] == 'Revision' or attr['name'] in COMPUTED_ATTRS or attr['name'] in IGNORE_ATTRS: - continue - name = get_attr_fixed_name(attr) - desc = attr['comment'] - optional = 'Optional' if attr['optional'] else 'Required' - if name == 'display_name': - desc = "The display name of this resource. " + desc - if name == 'tag': - desc = "A list of scope + tag pairs to associate with this %s" % re.sub('_', ' ', resource) - pretty_writeln(f, "* `%s` - (%s) %s." % (name, optional, desc)) - pretty_writeln(f, "\n") - -def write_attributes_reference(f, resource, attrs): - res = re.sub('_', ' ', resource) - pretty_writeln(f, "## Attributes Reference\n") - pretty_writeln(f, "In addition to arguments listed above, the following attributes are exported:\n") - pretty_writeln(f, "* `id` - ID of the %s." % res) - for attr in attrs: - if attr['name'] == 'Revision' or attr['name'] in COMPUTED_ATTRS or attr['name'] in IGNORE_ATTRS: - name = name_to_lower(attr['name']) - desc = attr['comment'] - if name == 'revision': - desc = 'Indicates current revision number of the object as seen by NSX-T API server. This attribute can be useful for debugging' - - pretty_writeln(f, "* `%s` - %s." % (name, desc)) - pretty_writeln(f, "\n") - - -def write_import_doc(f, resource): - name = re.sub('_', ' ', resource) - pretty_writeln(f, "## Importing\n") - pretty_writeln(f, "An existing %s can be [imported][docs-import] into this resource, via the following command:\n" % name) - pretty_writeln(f, "[docs-import]: /docs/import/index.html\n"); - pretty_writeln(f, "```") - pretty_writeln(f, "terraform import nsxt_%s.%s UUID" % (resource, resource)) - pretty_writeln(f, "```\n") - pretty_writeln(f, "The above would import the %s named `%s` with the nsx id `UUID`" % (name, resource)) - - -def main(): - - if len(sys.argv) != 3: - print("Usage: %s " % sys.argv[0]) - sys.exit() - - print("Building resource from %s" % sys.argv[1]) - api_section = sys.argv[2] - - with open(sys.argv[1], 'r') as f: - lines = f.readlines() - - resource = None - resource_started = False - attr_comment = None - attrs = [] - for line in lines: - line = line.strip() - match = re.match("type (.+?) struct", line) - if match: - resource = match.group(1) - resource_started = True - continue - - if not resource_started: - continue - - if line.startswith('//'): - attr_comment = line[3:] - # remove dot if exists - if attr_comment.endswith('.'): - attr_comment = attr_comment[:-1] - continue - - match = re.match("(.+?) (.+?) `json:\"(.+?)\"`", line) - if match: - attr_name = match.group(1).strip() - attr_type = match.group(2).strip() - attr_meta = match.group(3).strip() - attr_optional = 'omitempty' in attr_meta - if attr_name not in IGNORE_ATTRS: - attrs.append({'name': attr_name, - 'type': attr_type, - 'meta': attr_meta, - 'comment': attr_comment, - 'optional': attr_optional}) - attr_comment = None - - - print("Resource: %s" % resource) - resource_lower = name_to_lower(resource) - print(resource_lower) - - # write the resource file - with open("resource_nsxt_%s.go" % resource_lower, 'w') as f: - write_header(f) - - pretty_writeln(f, "func resourceNsxt%s() *schema.Resource {" % resource) - shift() - pretty_writeln(f, "return &schema.Resource{") - shift() - for op in ("Create", "Read", "Update", "Delete"): - spaces = " " if op == "Read" else "" - pretty_writeln(f, "%s: %sresourceNsxt%s%s," % (op, spaces, resource, op)) - # Add the importer line - pretty_writeln(f, "Importer: &schema.ResourceImporter{") - shift() - pretty_writeln(f, "State: schema.ImportStatePassthrough,") - unshift() - pretty_writeln(f, "},") - - f.write("\n") - pretty_writeln(f, "Schema: map[string]*schema.Schema{") - shift() - - for attr in attrs: - write_attr(f, attr) - - unshift() - pretty_writeln(f, "},") - unshift() - pretty_writeln(f, "}") - unshift() - pretty_writeln(f, "}") - - write_create_func(f, resource, attrs, api_section) - write_read_func(f, resource, attrs, api_section) - write_update_func(f, resource, attrs, api_section) - write_delete_func(f, resource, attrs, api_section) - - # write the documentation file - with open("%s.md" % resource_lower, 'w') as f: - write_doc_header(f, resource_lower) - write_doc_example(f, resource_lower, attrs) - write_arguments_reference(f, resource_lower, attrs) - write_attributes_reference(f, resource_lower, attrs) - write_import_doc(f, resource_lower) - - -main()