Skip to content

Commit b70cce4

Browse files
committed
rebase
1 parent 1c47c38 commit b70cce4

File tree

1 file changed

+67
-227
lines changed

1 file changed

+67
-227
lines changed

cloudstack/resource_cloudstack_traffic_type.go

Lines changed: 67 additions & 227 deletions
Original file line numberDiff line numberDiff line change
@@ -39,46 +39,60 @@ func resourceCloudStackTrafficType() *schema.Resource {
3939
},
4040

4141
Schema: map[string]*schema.Schema{
42-
"physical_network_id": {
43-
Type: schema.TypeString,
44-
Required: true,
45-
ForceNew: true,
42+
"hyperv_network_label": {
43+
Description: "The network name label of the physical device dedicated to this traffic on a Hyperv host",
44+
Type: schema.TypeString,
45+
Optional: true,
46+
ForceNew: true,
4647
},
47-
48-
"type": {
49-
Type: schema.TypeString,
50-
Required: true,
51-
ForceNew: true,
48+
"isolation_method": {
49+
Description: "Used if physical network has multiple isolation types and traffic type is public. Choose which isolation method. Valid options currently 'vlan' or 'vxlan', defaults to 'vlan'.",
50+
Type: schema.TypeString,
51+
Optional: true,
52+
ForceNew: true,
5253
},
53-
5454
"kvm_network_label": {
55-
Type: schema.TypeString,
56-
Optional: true,
55+
Description: "The network name label of the physical device dedicated to this traffic on a KVM host",
56+
Type: schema.TypeString,
57+
Optional: true,
58+
ForceNew: true,
5759
},
58-
59-
"vlan": {
60-
Type: schema.TypeString,
61-
Optional: true,
60+
"ovm3_network_label": {
61+
Description: "The network name of the physical device dedicated to this traffic on an OVM3 host",
62+
Type: schema.TypeString,
63+
Optional: true,
64+
ForceNew: true,
6265
},
63-
64-
"xen_network_label": {
65-
Type: schema.TypeString,
66-
Optional: true,
66+
"physical_network_id": {
67+
Description: "the Physical Network ID",
68+
Type: schema.TypeString,
69+
Required: true,
70+
ForceNew: true,
6771
},
68-
69-
"vmware_network_label": {
70-
Type: schema.TypeString,
71-
Optional: true,
72+
"traffic_type": {
73+
Description: "the trafficType to be added to the physical network",
74+
Type: schema.TypeString,
75+
Required: true,
76+
ForceNew: true,
77+
ValidateFunc: validateTrafficType,
7278
},
73-
74-
"hyperv_network_label": {
75-
Type: schema.TypeString,
76-
Optional: true,
79+
"vlan": {
80+
Description: "The VLAN id to be used for Management traffic by VMware host",
81+
Type: schema.TypeString,
82+
Optional: true,
83+
ForceNew: true,
7784
},
78-
79-
"ovm3_network_label": {
80-
Type: schema.TypeString,
81-
Optional: true,
85+
"vmware_network_label": {
86+
Description: "The network name label of the physical device dedicated to this traffic on a VMware host",
87+
Type: schema.TypeString,
88+
Optional: true,
89+
ForceNew: true,
90+
},
91+
"xen_network_label": {
92+
Description: "The network name label of the physical device dedicated to this traffic on a XenServer host",
93+
Type: schema.TypeString,
94+
Optional: true,
95+
ForceNew: true,
8296
},
8397
},
8498
}
@@ -98,6 +112,10 @@ func resourceCloudStackTrafficTypeCreate(d *schema.ResourceData, meta interface{
98112
p.SetKvmnetworklabel(kvmNetworkLabel.(string))
99113
}
100114

115+
if v, ok := d.GetOk("isolation_method"); ok {
116+
p.SetIsolationmethod(v.(string))
117+
}
118+
101119
if vlan, ok := d.GetOk("vlan"); ok {
102120
p.SetVlan(vlan.(string))
103121
}
@@ -126,6 +144,14 @@ func resourceCloudStackTrafficTypeCreate(d *schema.ResourceData, meta interface{
126144

127145
d.SetId(r.Id)
128146

147+
d.Set("physical_network_id", d.Get("physical_network_id").(string))
148+
d.Set("hyperv_network_label", r.Hypervnetworklabel)
149+
d.Set("kvm_network_label", r.Kvmnetworklabel)
150+
d.Set("ovm3_network_label", r.Ovm3networklabel)
151+
d.Set("traffic_type", r.Traffictype)
152+
d.Set("vmware_network_label", r.Vmwarenetworklabel)
153+
d.Set("xen_network_label", r.Xennetworklabel)
154+
129155
return resourceCloudStackTrafficTypeRead(d, meta)
130156
}
131157

@@ -198,11 +224,18 @@ func resourceCloudStackTrafficTypeUpdate(d *schema.ResourceData, meta interface{
198224
// so we can't update the VLAN
199225

200226
// Update the traffic type
201-
_, err := cs.Usage.UpdateTrafficType(p)
227+
r, err := cs.Usage.UpdateTrafficType(p)
202228
if err != nil {
203229
return fmt.Errorf("Error updating traffic type %s: %s", d.Get("type").(string), err)
204230
}
205231

232+
d.Set("hyperv_network_label", r.Hypervnetworklabel)
233+
d.Set("kvm_network_label", r.Kvmnetworklabel)
234+
d.Set("ovm3_network_label", r.Ovm3networklabel)
235+
d.Set("traffic_type", r.Traffictype)
236+
d.Set("vmware_network_label", r.Vmwarenetworklabel)
237+
d.Set("xen_network_label", r.Xennetworklabel)
238+
206239
return resourceCloudStackTrafficTypeRead(d, meta)
207240
}
208241

@@ -281,199 +314,6 @@ func resourceCloudStackTrafficTypeImport(d *schema.ResourceData, meta interface{
281314
return nil, fmt.Errorf("could not find physical network for traffic type %s", d.Id())
282315
}
283316

284-
//
285-
// Licensed to the Apache Software Foundation (ASF) under one
286-
// or more contributor license agreements. See the NOTICE file
287-
// distributed with this work for additional information
288-
// regarding copyright ownership. The ASF licenses this file
289-
// to you under the Apache License, Version 2.0 (the
290-
// "License"); you may not use this file except in compliance
291-
// with the License. You may obtain a copy of the License at
292-
//
293-
// http://www.apache.org/licenses/LICENSE-2.0
294-
//
295-
// Unless required by applicable law or agreed to in writing,
296-
// software distributed under the License is distributed on an
297-
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
298-
// KIND, either express or implied. See the License for the
299-
// specific language governing permissions and limitations
300-
// under the License.
301-
//
302-
303-
package cloudstack
304-
305-
import (
306-
"fmt"
307-
308-
"github.com/apache/cloudstack-go/v2/cloudstack"
309-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
310-
)
311-
312-
func resourceCloudStackTrafficType() *schema.Resource {
313-
return &schema.Resource{
314-
Create: resourceCloudStackTrafficTypeCreate,
315-
Read: resourceCloudStackTrafficTypeRead,
316-
// Update: resourceCloudStackTrafficTypeUpdate,
317-
Delete: resourceCloudStackTrafficTypeDelete,
318-
Schema: map[string]*schema.Schema{
319-
"hyperv_network_label": {
320-
Description: "The network name label of the physical device dedicated to this traffic on a Hyperv host",
321-
Type: schema.TypeString,
322-
Optional: true,
323-
ForceNew: true,
324-
},
325-
"isolation_method": {
326-
Description: "Used if physical network has multiple isolation types and traffic type is public. Choose which isolation method. Valid options currently 'vlan' or 'vxlan', defaults to 'vlan'.",
327-
Type: schema.TypeString,
328-
Optional: true,
329-
ForceNew: true,
330-
},
331-
"kvm_network_label": {
332-
Description: "The network name label of the physical device dedicated to this traffic on a KVM host",
333-
Type: schema.TypeString,
334-
Optional: true,
335-
ForceNew: true,
336-
},
337-
"ovm3_network_label": {
338-
Description: "The network name of the physical device dedicated to this traffic on an OVM3 host",
339-
Type: schema.TypeString,
340-
Optional: true,
341-
ForceNew: true,
342-
},
343-
"physical_network_id": {
344-
Description: "the Physical Network ID",
345-
Type: schema.TypeString,
346-
Required: true,
347-
ForceNew: true,
348-
},
349-
"traffic_type": {
350-
Description: "the trafficType to be added to the physical network",
351-
Type: schema.TypeString,
352-
Required: true,
353-
ForceNew: true,
354-
ValidateFunc: validateTrafficType,
355-
},
356-
"vlan": {
357-
Description: "The VLAN id to be used for Management traffic by VMware host",
358-
Type: schema.TypeString,
359-
Optional: true,
360-
ForceNew: true,
361-
},
362-
"vmware_network_label": {
363-
Description: "The network name label of the physical device dedicated to this traffic on a VMware host",
364-
Type: schema.TypeString,
365-
Optional: true,
366-
ForceNew: true,
367-
},
368-
"xen_network_label": {
369-
Description: "The network name label of the physical device dedicated to this traffic on a XenServer host",
370-
Type: schema.TypeString,
371-
Optional: true,
372-
ForceNew: true,
373-
},
374-
},
375-
}
376-
}
377-
378-
func resourceCloudStackTrafficTypeCreate(d *schema.ResourceData, meta interface{}) error {
379-
cs := meta.(*cloudstack.CloudStackClient)
380-
381-
p := cs.Usage.NewAddTrafficTypeParams(d.Get("physical_network_id").(string), d.Get("traffic_type").(string))
382-
if v, ok := d.GetOk("hyperv_network_label"); ok {
383-
p.SetHypervnetworklabel(v.(string))
384-
}
385-
if v, ok := d.GetOk("isolation_method"); ok {
386-
p.SetIsolationmethod(v.(string))
387-
}
388-
if v, ok := d.GetOk("kvm_network_label"); ok {
389-
p.SetKvmnetworklabel(v.(string))
390-
}
391-
if v, ok := d.GetOk("ovm3_network_label"); ok {
392-
p.SetOvm3networklabel(v.(string))
393-
}
394-
if v, ok := d.GetOk("vlan"); ok {
395-
p.SetVlan(v.(string))
396-
}
397-
if v, ok := d.GetOk("vmware_network_label"); ok {
398-
p.SetVmwarenetworklabel(v.(string))
399-
}
400-
if v, ok := d.GetOk("xen_network_label"); ok {
401-
p.SetXennetworklabel(v.(string))
402-
}
403-
404-
r, err := cs.Usage.AddTrafficType(p)
405-
if err != nil {
406-
return err
407-
}
408-
d.SetId(r.Id)
409-
d.Set("physical_network_id", d.Get("physical_network_id").(string))
410-
411-
//
412-
d.Set("hyperv_network_label", r.Hypervnetworklabel)
413-
d.Set("kvm_network_label", r.Kvmnetworklabel)
414-
d.Set("ovm3_network_label", r.Ovm3networklabel)
415-
d.Set("traffic_type", r.Traffictype)
416-
d.Set("vmware_network_label", r.Vmwarenetworklabel)
417-
d.Set("xen_network_label", r.Xennetworklabel)
418-
419-
return resourceCloudStackTrafficTypeRead(d, meta)
420-
}
421-
422-
func resourceCloudStackTrafficTypeRead(d *schema.ResourceData, meta interface{}) error {
423-
// Nothing to read. While these fields are returned by the API
424-
// they are not documented in the client or ListApi spec.
425-
// see https://github.com/apache/cloudstack/issues/7837
426-
427-
return nil
428-
}
429-
430-
func resourceCloudStackTrafficTypeUpdate(d *schema.ResourceData, meta interface{}) error {
431-
// All fields are ForceNew or Computed w/out Optional, Update is superfluous
432-
cs := meta.(*cloudstack.CloudStackClient)
433-
434-
p := cs.Usage.NewUpdateTrafficTypeParams(d.Id())
435-
if v, ok := d.GetOk("hyperv_network_label"); ok {
436-
p.SetHypervnetworklabel(v.(string))
437-
}
438-
if v, ok := d.GetOk("kvm_network_label"); ok {
439-
p.SetKvmnetworklabel(v.(string))
440-
}
441-
if v, ok := d.GetOk("ovm3_network_label"); ok {
442-
p.SetOvm3networklabel(v.(string))
443-
}
444-
if v, ok := d.GetOk("vmware_network_label"); ok {
445-
p.SetVmwarenetworklabel(v.(string))
446-
}
447-
if v, ok := d.GetOk("xen_network_label"); ok {
448-
p.SetXennetworklabel(v.(string))
449-
}
450-
451-
r, err := cs.Usage.UpdateTrafficType(p)
452-
if err != nil {
453-
return err
454-
}
455-
456-
d.Set("hyperv_network_label", r.Hypervnetworklabel)
457-
d.Set("kvm_network_label", r.Kvmnetworklabel)
458-
d.Set("ovm3_network_label", r.Ovm3networklabel)
459-
d.Set("traffic_type", r.Traffictype)
460-
d.Set("vmware_network_label", r.Vmwarenetworklabel)
461-
d.Set("xen_network_label", r.Xennetworklabel)
462-
463-
return resourceCloudStackTrafficTypeRead(d, meta)
464-
}
465-
466-
func resourceCloudStackTrafficTypeDelete(d *schema.ResourceData, meta interface{}) error {
467-
cs := meta.(*cloudstack.CloudStackClient)
468-
469-
_, err := cs.Usage.DeleteTrafficType(cs.Usage.NewDeleteTrafficTypeParams(d.Id()))
470-
if err != nil {
471-
return fmt.Errorf("Error deleting traffic type: %s", err)
472-
}
473-
474-
return nil
475-
}
476-
477317
func validateTrafficType(v interface{}, _ string) (warnings []string, errors []error) {
478318
input := v.(string)
479319

@@ -487,4 +327,4 @@ func validateTrafficType(v interface{}, _ string) (warnings []string, errors []e
487327
errors = append(errors, fmt.Errorf("traffic_type identifier (%q) not found, expecting %v", input, allowed))
488328

489329
return warnings, errors
490-
}
330+
}

0 commit comments

Comments
 (0)