github.com/vmware/go-vcloud-director/v2@v2.24.0/govcd/vdc_network_profile.go (about) 1 /* 2 * Copyright 2022 VMware, Inc. All rights reserved. Licensed under the Apache v2 License. 3 */ 4 5 package govcd 6 7 import ( 8 "fmt" 9 10 "github.com/vmware/go-vcloud-director/v2/types/v56" 11 ) 12 13 const labelVdcNetworkProfile = "VDC Network Profile" 14 15 // VDC Network profiles have 1:1 mapping with VDC - each VDC has an option to configure VDC Network 16 // Profiles. types.VdcNetworkProfile holds more information about possible configurations 17 18 // GetVdcNetworkProfile retrieves VDC Network Profile configuration 19 // vdc.Vdc.ID must be set and valid present 20 func (vdc *Vdc) GetVdcNetworkProfile() (*types.VdcNetworkProfile, error) { 21 if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { 22 return nil, fmt.Errorf("cannot lookup VDC Network Profile configuration without VDC ID") 23 } 24 25 return getVdcNetworkProfile(vdc.client, vdc.Vdc.ID) 26 } 27 28 // GetVdcNetworkProfile retrieves VDC Network Profile configuration 29 // vdc.Vdc.ID must be set and valid present 30 func (adminVdc *AdminVdc) GetVdcNetworkProfile() (*types.VdcNetworkProfile, error) { 31 if adminVdc == nil || adminVdc.AdminVdc == nil || adminVdc.AdminVdc.ID == "" { 32 return nil, fmt.Errorf("cannot lookup VDC Network Profile configuration without VDC ID") 33 } 34 35 return getVdcNetworkProfile(adminVdc.client, adminVdc.AdminVdc.ID) 36 } 37 38 // UpdateVdcNetworkProfile updates the VDC Network Profile configuration 39 // 40 // Note. Whenever updating VDC Network Profile it is required to send all fields (not only the 41 // changed ones) as VCD will remove other configuration. Best practice is to fetch current 42 // configuration of VDC Network Profile using GetVdcNetworkProfile, alter it with new values and 43 // submit it to UpdateVdcNetworkProfile. 44 func (vdc *Vdc) UpdateVdcNetworkProfile(vdcNetworkProfileConfig *types.VdcNetworkProfile) (*types.VdcNetworkProfile, error) { 45 if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { 46 return nil, fmt.Errorf("cannot update VDC Network Profile configuration without ID") 47 } 48 49 return updateVdcNetworkProfile(vdc.client, vdc.Vdc.ID, vdcNetworkProfileConfig) 50 } 51 52 // UpdateVdcNetworkProfile updates the VDC Network Profile configuration 53 func (adminVdc *AdminVdc) UpdateVdcNetworkProfile(vdcNetworkProfileConfig *types.VdcNetworkProfile) (*types.VdcNetworkProfile, error) { 54 if adminVdc == nil || adminVdc.AdminVdc == nil || adminVdc.AdminVdc.ID == "" { 55 return nil, fmt.Errorf("cannot update VDC Network Profile configuration without ID") 56 } 57 58 return updateVdcNetworkProfile(adminVdc.client, adminVdc.AdminVdc.ID, vdcNetworkProfileConfig) 59 } 60 61 // DeleteVdcNetworkProfile deletes VDC Network Profile Configuration 62 func (vdc *Vdc) DeleteVdcNetworkProfile() error { 63 if vdc == nil || vdc.Vdc == nil || vdc.Vdc.ID == "" { 64 return fmt.Errorf("cannot lookup VDC Network Profile without VDC ID") 65 } 66 67 return deleteVdcNetworkProfile(vdc.client, vdc.Vdc.ID) 68 } 69 70 // DeleteVdcNetworkProfile deletes VDC Network Profile Configuration 71 func (adminVdc *AdminVdc) DeleteVdcNetworkProfile() error { 72 if adminVdc == nil || adminVdc.AdminVdc == nil || adminVdc.AdminVdc.ID == "" { 73 return fmt.Errorf("cannot lookup VDC Network Profile without VDC ID") 74 } 75 76 return deleteVdcNetworkProfile(adminVdc.client, adminVdc.AdminVdc.ID) 77 } 78 79 func getVdcNetworkProfile(client *Client, vdcId string) (*types.VdcNetworkProfile, error) { 80 c := crudConfig{ 81 endpoint: types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile, 82 endpointParams: []string{vdcId}, 83 entityLabel: labelVdcNetworkProfile, 84 } 85 return getInnerEntity[types.VdcNetworkProfile](client, c) 86 } 87 88 func updateVdcNetworkProfile(client *Client, vdcId string, vdcNetworkProfileConfig *types.VdcNetworkProfile) (*types.VdcNetworkProfile, error) { 89 c := crudConfig{ 90 endpoint: types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile, 91 endpointParams: []string{vdcId}, 92 entityLabel: labelVdcNetworkProfile, 93 } 94 return updateInnerEntity(client, c, vdcNetworkProfileConfig) 95 } 96 97 func deleteVdcNetworkProfile(client *Client, vdcId string) error { 98 c := crudConfig{ 99 endpoint: types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointVdcNetworkProfile, 100 endpointParams: []string{vdcId}, 101 entityLabel: labelVdcNetworkProfile, 102 } 103 return deleteEntityById(client, c) 104 }