Best Syzkaller code snippet using vmm.Create
resource_aci_vmmctrlrp.go
Source:resource_aci_vmmctrlrp.go
...13 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"14)15func resourceAciVMMController() *schema.Resource {16 return &schema.Resource{17 CreateContext: resourceAciVMMControllerCreate,18 UpdateContext: resourceAciVMMControllerUpdate,19 ReadContext: resourceAciVMMControllerRead,20 DeleteContext: resourceAciVMMControllerDelete,21 Importer: &schema.ResourceImporter{22 State: resourceAciVMMControllerImport,23 },24 SchemaVersion: 1,25 Schema: AppendNameAliasAttrSchema(map[string]*schema.Schema{26 "vmm_domain_dn": {27 Type: schema.TypeString,28 Required: true,29 ForceNew: true,30 },31 "annotation": &schema.Schema{32 Type: schema.TypeString,33 Optional: true,34 // Default: "orchestrator:terraform",35 Computed: true,36 DefaultFunc: func() (interface{}, error) {37 return "orchestrator:terraform", nil38 }},39 "dvs_version": {40 Type: schema.TypeString,41 Optional: true,42 Computed: true,43 ValidateFunc: validation.StringInSlice([]string{44 "5.1",45 "5.5",46 "6.0",47 "6.5",48 "6.6",49 "7.0",50 "unmanaged",51 }, false),52 },53 "host_or_ip": {54 Type: schema.TypeString,55 Required: true,56 ForceNew: true,57 },58 "inventory_trig_st": {59 Type: schema.TypeString,60 Optional: true,61 Computed: true,62 ValidateFunc: validation.StringInSlice([]string{63 "autoTriggered",64 "triggered",65 "untriggered",66 }, false),67 },68 "mode": {69 Type: schema.TypeString,70 Optional: true,71 Computed: true,72 ValidateFunc: validation.StringInSlice([]string{73 "cf",74 "default",75 "k8s",76 "n1kv",77 "nsx",78 "openshift",79 "ovs",80 "rancher",81 "rhev",82 "unknown",83 }, false),84 },85 "msft_config_err_msg": {86 Type: schema.TypeString,87 Optional: true,88 Computed: true,89 },90 "msft_config_issues": {91 Type: schema.TypeList,92 Optional: true,93 Computed: true,94 Elem: &schema.Schema{95 Type: schema.TypeString,96 ValidateFunc: validation.StringInSlice([]string{97 "aaacert-invalid",98 "duplicate-mac-in-inventory",99 "duplicate-rootContName",100 "invalid-object-in-inventory",101 "invalid-rootContName",102 "inventory-failed",103 "missing-hostGroup-in-cloud",104 "missing-rootContName",105 "not-applicable",106 "zero-mac-in-inventory",107 }, false),108 },109 },110 "n1kv_stats_mode": {111 Type: schema.TypeString,112 Optional: true,113 Computed: true,114 ValidateFunc: validation.StringInSlice([]string{115 "disabled",116 "enabled",117 "unknown",118 }, false),119 },120 "name": {121 Type: schema.TypeString,122 Required: true,123 ForceNew: true,124 },125 "port": {126 Type: schema.TypeString,127 Optional: true,128 Computed: true,129 },130 "root_cont_name": {131 Type: schema.TypeString,132 Required: true,133 ForceNew: true,134 },135 "scope": {136 Type: schema.TypeString,137 Optional: true,138 Computed: true,139 ValidateFunc: validation.StringInSlice([]string{140 "MicrosoftSCVMM",141 "cloudfoundry",142 "iaas",143 "kubernetes",144 "network",145 "nsx",146 "openshift",147 "openstack",148 "rhev",149 "unmanaged",150 "vm",151 }, false),152 },153 "seq_num": {154 Type: schema.TypeString,155 Optional: true,156 Computed: true,157 },158 "stats_mode": {159 Type: schema.TypeString,160 Optional: true,161 Computed: true,162 ValidateFunc: validation.StringInSlice([]string{163 "disabled",164 "enabled",165 "unknown",166 }, false),167 },168 "vxlan_depl_pref": {169 Type: schema.TypeString,170 Optional: true,171 Computed: true,172 ValidateFunc: validation.StringInSlice([]string{173 "nsx",174 "vxlan",175 }, false),176 },177 "relation_vmm_rs_acc": {178 Type: schema.TypeString,179 Optional: true,180 Description: "Create relation to vmm:UsrAccP",181 },182 "relation_vmm_rs_ctrlr_p_mon_pol": {183 Type: schema.TypeString,184 Optional: true,185 Description: "Create relation to mon:InfraPol",186 },187 "relation_vmm_rs_mcast_addr_ns": {188 Type: schema.TypeString,189 Optional: true,190 Description: "Create relation to fvns:McastAddrInstP",191 },192 "relation_vmm_rs_mgmt_e_pg": {193 Type: schema.TypeString,194 Optional: true,195 Description: "Create relation to fv:EPg",196 },197 "relation_vmm_rs_to_ext_dev_mgr": {198 Type: schema.TypeSet,199 Elem: &schema.Schema{Type: schema.TypeString},200 Optional: true,201 Description: "Create relation to extdev:MgrP",202 Set: schema.HashString,203 },204 "relation_vmm_rs_vmm_ctrlr_p": {205 Type: schema.TypeSet,206 Optional: true,207 Description: "Create relation to vmmCtrlrP",208 Elem: &schema.Resource{209 Schema: map[string]*schema.Schema{210 "epg_depl_pref": {211 Optional: true,212 Type: schema.TypeString,213 ValidateFunc: validation.StringInSlice([]string{214 "both",215 "local",216 }, false),217 },218 "target_dn": {219 Required: true,220 Type: schema.TypeString,221 },222 },223 },224 },225 "relation_vmm_rs_vxlan_ns": {226 Type: schema.TypeString,227 Optional: true,228 Description: "Create relation to fvns:VxlanInstP",229 },230 "relation_vmm_rs_vxlan_ns_def": {231 Type: schema.TypeString,232 Computed: true,233 Optional: true,234 Description: "Create relation to fvns:AInstP",235 }}),236 }237}238func getRemoteVMMController(client *client.Client, dn string) (*models.VMMController, error) {239 vmmCtrlrPCont, err := client.Get(dn)240 if err != nil {241 return nil, err242 }243 vmmCtrlrP := models.VMMControllerFromContainer(vmmCtrlrPCont)244 if vmmCtrlrP.DistinguishedName == "" {245 return nil, fmt.Errorf("VMMController %s not found", vmmCtrlrP.DistinguishedName)246 }247 return vmmCtrlrP, nil248}249func setVMMControllerAttributes(vmmCtrlrP *models.VMMController, d *schema.ResourceData) (*schema.ResourceData, error) {250 d.SetId(vmmCtrlrP.DistinguishedName)251 vmmCtrlrPMap, err := vmmCtrlrP.ToMap()252 if err != nil {253 return d, err254 }255 d.Set("annotation", vmmCtrlrPMap["annotation"])256 d.Set("dvs_version", vmmCtrlrPMap["dvsVersion"])257 d.Set("host_or_ip", vmmCtrlrPMap["hostOrIp"])258 // d.Set("inventory_trig_st", vmmCtrlrPMap["inventoryTrigSt"])259 d.Set("mode", vmmCtrlrPMap["mode"])260 d.Set("msft_config_err_msg", vmmCtrlrPMap["msftConfigErrMsg"])261 msftConfigIssuesGet := make([]string, 0, 1)262 for _, val := range strings.Split(vmmCtrlrPMap["msftConfigIssues"], ",") {263 msftConfigIssuesGet = append(msftConfigIssuesGet, strings.Trim(val, " "))264 }265 sort.Strings(msftConfigIssuesGet)266 if msftConfigIssuesIntr, ok := d.GetOk("msft_config_issues"); ok {267 msftConfigIssuesAct := make([]string, 0, 1)268 for _, val := range msftConfigIssuesIntr.([]interface{}) {269 msftConfigIssuesAct = append(msftConfigIssuesAct, val.(string))270 }271 sort.Strings(msftConfigIssuesAct)272 if reflect.DeepEqual(msftConfigIssuesAct, msftConfigIssuesGet) {273 d.Set("msft_config_issues", d.Get("msft_config_issues").([]interface{}))274 } else {275 d.Set("msft_config_issues", msftConfigIssuesGet)276 }277 } else {278 d.Set("msft_config_issues", msftConfigIssuesGet)279 }280 d.Set("vmm_domain_dn", GetParentDn(vmmCtrlrP.DistinguishedName, fmt.Sprintf("/ctrlr-%s", vmmCtrlrPMap["name"])))281 d.Set("n1kv_stats_mode", vmmCtrlrPMap["n1kvStatsMode"])282 d.Set("name", vmmCtrlrPMap["name"])283 d.Set("port", vmmCtrlrPMap["port"])284 d.Set("root_cont_name", vmmCtrlrPMap["rootContName"])285 d.Set("scope", vmmCtrlrPMap["scope"])286 d.Set("seq_num", vmmCtrlrPMap["seqNum"])287 d.Set("stats_mode", vmmCtrlrPMap["statsMode"])288 d.Set("vxlan_depl_pref", vmmCtrlrPMap["vxlanDeplPref"])289 d.Set("name_alias", vmmCtrlrPMap["nameAlias"])290 return d, nil291}292func resourceAciVMMControllerImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {293 log.Printf("[DEBUG] %s: Beginning Import", d.Id())294 aciClient := m.(*client.Client)295 dn := d.Id()296 vmmCtrlrP, err := getRemoteVMMController(aciClient, dn)297 if err != nil {298 return nil, err299 }300 schemaFilled, err := setVMMControllerAttributes(vmmCtrlrP, d)301 if err != nil {302 return nil, err303 }304 log.Printf("[DEBUG] %s: Import finished successfully", d.Id())305 return []*schema.ResourceData{schemaFilled}, nil306}307func resourceAciVMMControllerCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {308 log.Printf("[DEBUG] VMMController: Beginning Creation")309 aciClient := m.(*client.Client)310 name := d.Get("name").(string)311 VMMDomainDn := d.Get("vmm_domain_dn").(string)312 vmmCtrlrPAttr := models.VMMControllerAttributes{}313 nameAlias := ""314 if NameAlias, ok := d.GetOk("name_alias"); ok {315 nameAlias = NameAlias.(string)316 }317 if Annotation, ok := d.GetOk("annotation"); ok {318 vmmCtrlrPAttr.Annotation = Annotation.(string)319 } else {320 vmmCtrlrPAttr.Annotation = "{}"321 }322 if DvsVersion, ok := d.GetOk("dvs_version"); ok {323 vmmCtrlrPAttr.DvsVersion = DvsVersion.(string)324 }325 if HostOrIp, ok := d.GetOk("host_or_ip"); ok {326 vmmCtrlrPAttr.HostOrIp = HostOrIp.(string)327 }328 if InventoryTrigSt, ok := d.GetOk("inventory_trig_st"); ok {329 vmmCtrlrPAttr.InventoryTrigSt = InventoryTrigSt.(string)330 }331 if Mode, ok := d.GetOk("mode"); ok {332 vmmCtrlrPAttr.Mode = Mode.(string)333 }334 if MsftConfigErrMsg, ok := d.GetOk("msft_config_err_msg"); ok {335 vmmCtrlrPAttr.MsftConfigErrMsg = MsftConfigErrMsg.(string)336 }337 if MsftConfigIssues, ok := d.GetOk("msft_config_issues"); ok {338 msftConfigIssuesList := make([]string, 0, 1)339 for _, val := range MsftConfigIssues.([]interface{}) {340 msftConfigIssuesList = append(msftConfigIssuesList, val.(string))341 }342 MsftConfigIssues := strings.Join(msftConfigIssuesList, ",")343 vmmCtrlrPAttr.MsftConfigIssues = MsftConfigIssues344 }345 if N1kvStatsMode, ok := d.GetOk("n1kv_stats_mode"); ok {346 vmmCtrlrPAttr.N1kvStatsMode = N1kvStatsMode.(string)347 }348 if Name, ok := d.GetOk("name"); ok {349 vmmCtrlrPAttr.Name = Name.(string)350 }351 if Port, ok := d.GetOk("port"); ok {352 vmmCtrlrPAttr.Port = Port.(string)353 }354 if RootContName, ok := d.GetOk("root_cont_name"); ok {355 vmmCtrlrPAttr.RootContName = RootContName.(string)356 }357 if Scope, ok := d.GetOk("scope"); ok {358 vmmCtrlrPAttr.Scope = Scope.(string)359 }360 if SeqNum, ok := d.GetOk("seq_num"); ok {361 vmmCtrlrPAttr.SeqNum = SeqNum.(string)362 }363 if StatsMode, ok := d.GetOk("stats_mode"); ok {364 vmmCtrlrPAttr.StatsMode = StatsMode.(string)365 }366 if VxlanDeplPref, ok := d.GetOk("vxlan_depl_pref"); ok {367 vmmCtrlrPAttr.VxlanDeplPref = VxlanDeplPref.(string)368 }369 vmmCtrlrP := models.NewVMMController(fmt.Sprintf("ctrlr-%s", name), VMMDomainDn, nameAlias, vmmCtrlrPAttr)370 err := aciClient.Save(vmmCtrlrP)371 if err != nil {372 return diag.FromErr(err)373 }374 checkDns := make([]string, 0, 1)375 if relationTovmmRsAcc, ok := d.GetOk("relation_vmm_rs_acc"); ok {376 relationParam := relationTovmmRsAcc.(string)377 checkDns = append(checkDns, relationParam)378 }379 if relationTovmmRsCtrlrPMonPol, ok := d.GetOk("relation_vmm_rs_ctrlr_p_mon_pol"); ok {380 relationParam := relationTovmmRsCtrlrPMonPol.(string)381 checkDns = append(checkDns, relationParam)382 }383 if relationTovmmRsMcastAddrNs, ok := d.GetOk("relation_vmm_rs_mcast_addr_ns"); ok {384 relationParam := relationTovmmRsMcastAddrNs.(string)385 checkDns = append(checkDns, relationParam)386 }387 if relationTovmmRsMgmtEPg, ok := d.GetOk("relation_vmm_rs_mgmt_e_pg"); ok {388 relationParam := relationTovmmRsMgmtEPg.(string)389 checkDns = append(checkDns, relationParam)390 }391 if relationTovmmRsToExtDevMgr, ok := d.GetOk("relation_vmm_rs_to_ext_dev_mgr"); ok {392 relationParamList := toStringList(relationTovmmRsToExtDevMgr.(*schema.Set).List())393 for _, relationParam := range relationParamList {394 checkDns = append(checkDns, relationParam)395 }396 }397 if relationTovmmRsVmmCtrlrP, ok := d.GetOk("relation_vmm_rs_vmm_ctrlr_p"); ok {398 relationParamList := toStringList(relationTovmmRsVmmCtrlrP.(*schema.Set).List())399 for _, relationParam := range relationParamList {400 checkDns = append(checkDns, relationParam)401 }402 }403 if relationTovmmRsVxlanNs, ok := d.GetOk("relation_vmm_rs_vxlan_ns"); ok {404 relationParam := relationTovmmRsVxlanNs.(string)405 checkDns = append(checkDns, relationParam)406 }407 if relationTovmmRsVxlanNsDef, ok := d.GetOk("relation_vmm_rs_vxlan_ns_def"); ok {408 relationParam := relationTovmmRsVxlanNsDef.(string)409 checkDns = append(checkDns, relationParam)410 }411 d.Partial(true)412 err = checkTDn(aciClient, checkDns)413 if err != nil {414 return diag.FromErr(err)415 }416 d.Partial(false)417 if relationTovmmRsAcc, ok := d.GetOk("relation_vmm_rs_acc"); ok {418 relationParam := relationTovmmRsAcc.(string)419 err = aciClient.CreateRelationvmmRsAcc(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, relationParam)420 if err != nil {421 return diag.FromErr(err)422 }423 }424 if relationTovmmRsCtrlrPMonPol, ok := d.GetOk("relation_vmm_rs_ctrlr_p_mon_pol"); ok {425 relationParam := relationTovmmRsCtrlrPMonPol.(string)426 err = aciClient.CreateRelationvmmRsCtrlrPMonPol(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, relationParam)427 if err != nil {428 return diag.FromErr(err)429 }430 }431 if relationTovmmRsMcastAddrNs, ok := d.GetOk("relation_vmm_rs_mcast_addr_ns"); ok {432 relationParam := relationTovmmRsMcastAddrNs.(string)433 err = aciClient.CreateRelationvmmRsMcastAddrNs(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, relationParam)434 if err != nil {435 return diag.FromErr(err)436 }437 }438 if relationTovmmRsMgmtEPg, ok := d.GetOk("relation_vmm_rs_mgmt_e_pg"); ok {439 relationParam := relationTovmmRsMgmtEPg.(string)440 err = aciClient.CreateRelationvmmRsMgmtEPg(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, relationParam)441 if err != nil {442 return diag.FromErr(err)443 }444 }445 if relationTovmmRsToExtDevMgr, ok := d.GetOk("relation_vmm_rs_to_ext_dev_mgr"); ok {446 relationParamList := toStringList(relationTovmmRsToExtDevMgr.(*schema.Set).List())447 for _, relationParam := range relationParamList {448 err = aciClient.CreateRelationvmmRsToExtDevMgr(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, relationParam)449 if err != nil {450 return diag.FromErr(err)451 }452 }453 }454 if relationTovmmRsVmmCtrlrP, ok := d.GetOk("relation_vmm_rs_vmm_ctrlr_p"); ok {455 relationParamList := relationTovmmRsVmmCtrlrP.(*schema.Set).List()456 for _, relationParam := range relationParamList {457 paramMap := relationParam.(map[string]interface{})458 err = aciClient.CreateRelationvmmRsVmmCtrlrP(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, paramMap["epg_depl_pref"].(string), paramMap["target_dn"].(string))459 if err != nil {460 return diag.FromErr(err)461 }462 }463 }464 if relationTovmmRsVxlanNs, ok := d.GetOk("relation_vmm_rs_vxlan_ns"); ok {465 relationParam := relationTovmmRsVxlanNs.(string)466 err = aciClient.CreateRelationvmmRsVxlanNs(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, relationParam)467 if err != nil {468 return diag.FromErr(err)469 }470 }471 if relationTovmmRsVxlanNsDef, ok := d.GetOk("relation_vmm_rs_vxlan_ns_def"); ok {472 relationParam := relationTovmmRsVxlanNsDef.(string)473 err = aciClient.CreateRelationvmmRsVxlanNsDef(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, relationParam)474 if err != nil {475 return diag.FromErr(err)476 }477 }478 d.SetId(vmmCtrlrP.DistinguishedName)479 log.Printf("[DEBUG] %s: Creation finished successfully", d.Id())480 return resourceAciVMMControllerRead(ctx, d, m)481}482func resourceAciVMMControllerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {483 log.Printf("[DEBUG] VMMController: Beginning Update")484 aciClient := m.(*client.Client)485 name := d.Get("name").(string)486 VMMDomainDn := d.Get("vmm_domain_dn").(string)487 vmmCtrlrPAttr := models.VMMControllerAttributes{}488 nameAlias := ""489 if NameAlias, ok := d.GetOk("name_alias"); ok {490 nameAlias = NameAlias.(string)491 }492 if Annotation, ok := d.GetOk("annotation"); ok {493 vmmCtrlrPAttr.Annotation = Annotation.(string)494 } else {495 vmmCtrlrPAttr.Annotation = "{}"496 }497 if DvsVersion, ok := d.GetOk("dvs_version"); ok {498 vmmCtrlrPAttr.DvsVersion = DvsVersion.(string)499 }500 if HostOrIp, ok := d.GetOk("host_or_ip"); ok {501 vmmCtrlrPAttr.HostOrIp = HostOrIp.(string)502 }503 if InventoryTrigSt, ok := d.GetOk("inventory_trig_st"); ok {504 vmmCtrlrPAttr.InventoryTrigSt = InventoryTrigSt.(string)505 }506 if Mode, ok := d.GetOk("mode"); ok {507 vmmCtrlrPAttr.Mode = Mode.(string)508 }509 if MsftConfigErrMsg, ok := d.GetOk("msft_config_err_msg"); ok {510 vmmCtrlrPAttr.MsftConfigErrMsg = MsftConfigErrMsg.(string)511 }512 if MsftConfigIssues, ok := d.GetOk("msft_config_issues"); ok {513 msftConfigIssuesList := make([]string, 0, 1)514 for _, val := range MsftConfigIssues.([]interface{}) {515 msftConfigIssuesList = append(msftConfigIssuesList, val.(string))516 }517 MsftConfigIssues := strings.Join(msftConfigIssuesList, ",")518 vmmCtrlrPAttr.MsftConfigIssues = MsftConfigIssues519 }520 if N1kvStatsMode, ok := d.GetOk("n1kv_stats_mode"); ok {521 vmmCtrlrPAttr.N1kvStatsMode = N1kvStatsMode.(string)522 }523 if Name, ok := d.GetOk("name"); ok {524 vmmCtrlrPAttr.Name = Name.(string)525 }526 if Port, ok := d.GetOk("port"); ok {527 vmmCtrlrPAttr.Port = Port.(string)528 }529 if RootContName, ok := d.GetOk("root_cont_name"); ok {530 vmmCtrlrPAttr.RootContName = RootContName.(string)531 }532 if Scope, ok := d.GetOk("scope"); ok {533 vmmCtrlrPAttr.Scope = Scope.(string)534 }535 if SeqNum, ok := d.GetOk("seq_num"); ok {536 vmmCtrlrPAttr.SeqNum = SeqNum.(string)537 }538 if StatsMode, ok := d.GetOk("stats_mode"); ok {539 vmmCtrlrPAttr.StatsMode = StatsMode.(string)540 }541 if VxlanDeplPref, ok := d.GetOk("vxlan_depl_pref"); ok {542 vmmCtrlrPAttr.VxlanDeplPref = VxlanDeplPref.(string)543 }544 vmmCtrlrP := models.NewVMMController(fmt.Sprintf("ctrlr-%s", name), VMMDomainDn, nameAlias, vmmCtrlrPAttr)545 vmmCtrlrP.Status = "modified"546 err := aciClient.Save(vmmCtrlrP)547 if err != nil {548 return diag.FromErr(err)549 }550 checkDns := make([]string, 0, 1)551 if d.HasChange("relation_vmm_rs_acc") || d.HasChange("annotation") {552 _, newRelParam := d.GetChange("relation_vmm_rs_acc")553 checkDns = append(checkDns, newRelParam.(string))554 }555 if d.HasChange("relation_vmm_rs_ctrlr_p_mon_pol") || d.HasChange("annotation") {556 _, newRelParam := d.GetChange("relation_vmm_rs_ctrlr_p_mon_pol")557 checkDns = append(checkDns, newRelParam.(string))558 }559 if d.HasChange("relation_vmm_rs_mcast_addr_ns") || d.HasChange("annotation") {560 _, newRelParam := d.GetChange("relation_vmm_rs_mcast_addr_ns")561 checkDns = append(checkDns, newRelParam.(string))562 }563 if d.HasChange("relation_vmm_rs_mgmt_e_pg") || d.HasChange("annotation") {564 _, newRelParam := d.GetChange("relation_vmm_rs_mgmt_e_pg")565 checkDns = append(checkDns, newRelParam.(string))566 }567 if d.HasChange("relation_vmm_rs_to_ext_dev_mgr") || d.HasChange("annotation") {568 oldRel, newRel := d.GetChange("relation_vmm_rs_to_ext_dev_mgr")569 oldRelSet := oldRel.(*schema.Set)570 newRelSet := newRel.(*schema.Set)571 relToCreate := toStringList(newRelSet.Difference(oldRelSet).List())572 for _, relDn := range relToCreate {573 checkDns = append(checkDns, relDn)574 }575 }576 if d.HasChange("relation_vmm_rs_vmm_ctrlr_p") || d.HasChange("annotation") {577 oldRel, newRel := d.GetChange("relation_vmm_rs_vmm_ctrlr_p")578 oldRelSet := oldRel.(*schema.Set)579 newRelSet := newRel.(*schema.Set)580 relToCreate := toStringList(newRelSet.Difference(oldRelSet).List())581 for _, relDn := range relToCreate {582 checkDns = append(checkDns, relDn)583 }584 }585 if d.HasChange("relation_vmm_rs_vxlan_ns") || d.HasChange("annotation") {586 _, newRelParam := d.GetChange("relation_vmm_rs_vxlan_ns")587 checkDns = append(checkDns, newRelParam.(string))588 }589 if d.HasChange("relation_vmm_rs_vxlan_ns_def") || d.HasChange("annotation") {590 _, newRelParam := d.GetChange("relation_vmm_rs_vxlan_ns_def")591 checkDns = append(checkDns, newRelParam.(string))592 }593 d.Partial(true)594 err = checkTDn(aciClient, checkDns)595 if err != nil {596 return diag.FromErr(err)597 }598 d.Partial(false)599 if d.HasChange("relation_vmm_rs_acc") || d.HasChange("annotation") {600 _, newRelParam := d.GetChange("relation_vmm_rs_acc")601 err = aciClient.DeleteRelationvmmRsAcc(vmmCtrlrP.DistinguishedName)602 if err != nil {603 return diag.FromErr(err)604 }605 err = aciClient.CreateRelationvmmRsAcc(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, newRelParam.(string))606 if err != nil {607 return diag.FromErr(err)608 }609 }610 if d.HasChange("relation_vmm_rs_ctrlr_p_mon_pol") || d.HasChange("annotation") {611 _, newRelParam := d.GetChange("relation_vmm_rs_ctrlr_p_mon_pol")612 err = aciClient.DeleteRelationvmmRsCtrlrPMonPol(vmmCtrlrP.DistinguishedName)613 if err != nil {614 return diag.FromErr(err)615 }616 err = aciClient.CreateRelationvmmRsCtrlrPMonPol(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, newRelParam.(string))617 if err != nil {618 return diag.FromErr(err)619 }620 }621 if d.HasChange("relation_vmm_rs_mcast_addr_ns") || d.HasChange("annotation") {622 _, newRelParam := d.GetChange("relation_vmm_rs_mcast_addr_ns")623 err = aciClient.DeleteRelationvmmRsMcastAddrNs(vmmCtrlrP.DistinguishedName)624 if err != nil {625 return diag.FromErr(err)626 }627 err = aciClient.CreateRelationvmmRsMcastAddrNs(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, newRelParam.(string))628 if err != nil {629 return diag.FromErr(err)630 }631 }632 if d.HasChange("relation_vmm_rs_mgmt_e_pg") || d.HasChange("annotation") {633 _, newRelParam := d.GetChange("relation_vmm_rs_mgmt_e_pg")634 err = aciClient.DeleteRelationvmmRsMgmtEPg(vmmCtrlrP.DistinguishedName)635 if err != nil {636 return diag.FromErr(err)637 }638 err = aciClient.CreateRelationvmmRsMgmtEPg(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, newRelParam.(string))639 if err != nil {640 return diag.FromErr(err)641 }642 }643 if d.HasChange("relation_vmm_rs_to_ext_dev_mgr") || d.HasChange("annotation") {644 oldRel, newRel := d.GetChange("relation_vmm_rs_to_ext_dev_mgr")645 oldRelSet := oldRel.(*schema.Set)646 newRelSet := newRel.(*schema.Set)647 relToDelete := toStringList(oldRelSet.Difference(newRelSet).List())648 relToCreate := toStringList(newRelSet.Difference(oldRelSet).List())649 for _, relDn := range relToDelete {650 err = aciClient.DeleteRelationvmmRsToExtDevMgr(vmmCtrlrP.DistinguishedName, relDn)651 if err != nil {652 return diag.FromErr(err)653 }654 }655 for _, relDn := range relToCreate {656 err = aciClient.CreateRelationvmmRsToExtDevMgr(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, relDn)657 if err != nil {658 return diag.FromErr(err)659 }660 }661 }662 if d.HasChange("relation_vmm_rs_vmm_ctrlr_p") || d.HasChange("annotation") {663 oldRel, newRel := d.GetChange("relation_vmm_rs_vmm_ctrlr_p")664 oldRelList := oldRel.(*schema.Set).List()665 newRelList := newRel.(*schema.Set).List()666 for _, relationParam := range oldRelList {667 paramMap := relationParam.(map[string]interface{})668 err = aciClient.DeleteRelationvmmRsVmmCtrlrP(vmmCtrlrP.DistinguishedName, paramMap["target_dn"].(string))669 if err != nil {670 return diag.FromErr(err)671 }672 }673 for _, relationParam := range newRelList {674 paramMap := relationParam.(map[string]interface{})675 err = aciClient.CreateRelationvmmRsVmmCtrlrP(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, paramMap["epg_depl_pref"].(string), paramMap["target_dn"].(string))676 if err != nil {677 return diag.FromErr(err)678 }679 }680 }681 if d.HasChange("relation_vmm_rs_vxlan_ns") || d.HasChange("annotation") {682 _, newRelParam := d.GetChange("relation_vmm_rs_vxlan_ns")683 err = aciClient.DeleteRelationvmmRsVxlanNs(vmmCtrlrP.DistinguishedName)684 if err != nil {685 return diag.FromErr(err)686 }687 err = aciClient.CreateRelationvmmRsVxlanNs(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, newRelParam.(string))688 if err != nil {689 return diag.FromErr(err)690 }691 }692 if d.HasChange("relation_vmm_rs_vxlan_ns_def") || d.HasChange("annotation") {693 _, newRelParam := d.GetChange("relation_vmm_rs_vxlan_ns_def")694 err = aciClient.DeleteRelationvmmRsVxlanNsDef(vmmCtrlrP.DistinguishedName)695 if err != nil {696 return diag.FromErr(err)697 }698 err = aciClient.CreateRelationvmmRsVxlanNsDef(vmmCtrlrP.DistinguishedName, vmmCtrlrPAttr.Annotation, newRelParam.(string))699 if err != nil {700 return diag.FromErr(err)701 }702 }703 d.SetId(vmmCtrlrP.DistinguishedName)704 log.Printf("[DEBUG] %s: Update finished successfully", d.Id())705 return resourceAciVMMControllerRead(ctx, d, m)706}707func resourceAciVMMControllerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {708 log.Printf("[DEBUG] %s: Beginning Read", d.Id())709 aciClient := m.(*client.Client)710 dn := d.Id()711 vmmCtrlrP, err := getRemoteVMMController(aciClient, dn)712 if err != nil {...
resource_aci_vmmvswitchpolicycont.go
Source:resource_aci_vmmvswitchpolicycont.go
...9 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"10)11func resourceAciVSwitchPolicyGroup() *schema.Resource {12 return &schema.Resource{13 CreateContext: resourceAciVSwitchPolicyGroupCreate,14 UpdateContext: resourceAciVSwitchPolicyGroupUpdate,15 ReadContext: resourceAciVSwitchPolicyGroupRead,16 DeleteContext: resourceAciVSwitchPolicyGroupDelete,17 Importer: &schema.ResourceImporter{18 State: resourceAciVSwitchPolicyGroupImport,19 },20 SchemaVersion: 1,21 Schema: AppendBaseAttrSchema(AppendNameAliasAttrSchema(map[string]*schema.Schema{22 "vmm_domain_dn": {23 Type: schema.TypeString,24 Required: true,25 ForceNew: true,26 },27 "relation_vmm_rs_vswitch_exporter_pol": {28 Type: schema.TypeSet,29 Optional: true,30 Description: "Create relation to netflowVmmExporterPol",31 Elem: &schema.Resource{32 Schema: map[string]*schema.Schema{33 "active_flow_time_out": {34 Optional: true,35 Type: schema.TypeString,36 },37 "idle_flow_time_out": {38 Optional: true,39 Type: schema.TypeString,40 },41 "sampling_rate": {42 Optional: true,43 Type: schema.TypeString,44 },45 "target_dn": {46 Required: true,47 Type: schema.TypeString,48 },49 },50 },51 },52 "relation_vmm_rs_vswitch_override_cdp_if_pol": {53 Type: schema.TypeString,54 Optional: true,55 Description: "Create relation to cdp:IfPol",56 },57 "relation_vmm_rs_vswitch_override_fw_pol": {58 Type: schema.TypeString,59 Optional: true,60 Description: "Create relation to nws:FwPol",61 },62 "relation_vmm_rs_vswitch_override_lacp_pol": {63 Type: schema.TypeString,64 Optional: true,65 Description: "Create relation to lacp:LagPol",66 },67 "relation_vmm_rs_vswitch_override_lldp_if_pol": {68 Type: schema.TypeString,69 Optional: true,70 Description: "Create relation to lldp:IfPol",71 },72 "relation_vmm_rs_vswitch_override_mcp_if_pol": {73 Type: schema.TypeString,74 Optional: true,75 Description: "Create relation to mcp:IfPol",76 },77 "relation_vmm_rs_vswitch_override_mtu_pol": {78 Type: schema.TypeString,79 Optional: true,80 Description: "Create relation to l2:InstPol",81 },82 "relation_vmm_rs_vswitch_override_stp_pol": {83 Type: schema.TypeString,84 Optional: true,85 Description: "Create relation to stp:IfPol",86 }})),87 }88}89func getRemoteVSwitchPolicyGroup(client *client.Client, dn string) (*models.VSwitchPolicyGroup, error) {90 vmmVSwitchPolicyContCont, err := client.Get(dn)91 if err != nil {92 return nil, err93 }94 vmmVSwitchPolicyCont := models.VSwitchPolicyGroupFromContainer(vmmVSwitchPolicyContCont)95 if vmmVSwitchPolicyCont.DistinguishedName == "" {96 return nil, fmt.Errorf("VSwitchPolicyGroup %s not found", vmmVSwitchPolicyCont.DistinguishedName)97 }98 return vmmVSwitchPolicyCont, nil99}100func setVSwitchPolicyGroupAttributes(vmmVSwitchPolicyCont *models.VSwitchPolicyGroup, d *schema.ResourceData) (*schema.ResourceData, error) {101 d.SetId(vmmVSwitchPolicyCont.DistinguishedName)102 d.Set("description", vmmVSwitchPolicyCont.Description)103 vmmVSwitchPolicyContMap, err := vmmVSwitchPolicyCont.ToMap()104 if err != nil {105 return d, err106 }107 d.Set("vmm_domain_dn", GetParentDn(vmmVSwitchPolicyCont.DistinguishedName, fmt.Sprintf("/vswitchpolcont")))108 d.Set("annotation", vmmVSwitchPolicyContMap["annotation"])109 d.Set("name_alias", vmmVSwitchPolicyContMap["nameAlias"])110 return d, nil111}112func resourceAciVSwitchPolicyGroupImport(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) {113 log.Printf("[DEBUG] %s: Beginning Import", d.Id())114 aciClient := m.(*client.Client)115 dn := d.Id()116 vmmVSwitchPolicyCont, err := getRemoteVSwitchPolicyGroup(aciClient, dn)117 if err != nil {118 return nil, err119 }120 schemaFilled, err := setVSwitchPolicyGroupAttributes(vmmVSwitchPolicyCont, d)121 if err != nil {122 return nil, err123 }124 log.Printf("[DEBUG] %s: Import finished successfully", d.Id())125 return []*schema.ResourceData{schemaFilled}, nil126}127func resourceAciVSwitchPolicyGroupCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {128 log.Printf("[DEBUG] VSwitchPolicyGroup: Beginning Creation")129 aciClient := m.(*client.Client)130 desc := d.Get("description").(string)131 VMMDomainDn := d.Get("vmm_domain_dn").(string)132 vmmVSwitchPolicyContAttr := models.VSwitchPolicyGroupAttributes{}133 nameAlias := ""134 if NameAlias, ok := d.GetOk("name_alias"); ok {135 nameAlias = NameAlias.(string)136 }137 if Annotation, ok := d.GetOk("annotation"); ok {138 vmmVSwitchPolicyContAttr.Annotation = Annotation.(string)139 } else {140 vmmVSwitchPolicyContAttr.Annotation = "{}"141 }142 vmmVSwitchPolicyCont := models.NewVSwitchPolicyGroup(fmt.Sprintf("vswitchpolcont"), VMMDomainDn, desc, nameAlias, vmmVSwitchPolicyContAttr)143 err := aciClient.Save(vmmVSwitchPolicyCont)144 if err != nil {145 return diag.FromErr(err)146 }147 checkDns := make([]string, 0, 1)148 if relationTovmmRsVswitchExporterPol, ok := d.GetOk("relation_vmm_rs_vswitch_exporter_pol"); ok {149 relationParamList := toStringList(relationTovmmRsVswitchExporterPol.(*schema.Set).List())150 for _, relationParam := range relationParamList {151 checkDns = append(checkDns, relationParam)152 }153 }154 if relationTovmmRsVswitchOverrideCdpIfPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_cdp_if_pol"); ok {155 relationParam := relationTovmmRsVswitchOverrideCdpIfPol.(string)156 checkDns = append(checkDns, relationParam)157 }158 if relationTovmmRsVswitchOverrideFwPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_fw_pol"); ok {159 relationParam := relationTovmmRsVswitchOverrideFwPol.(string)160 checkDns = append(checkDns, relationParam)161 }162 if relationTovmmRsVswitchOverrideLacpPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_lacp_pol"); ok {163 relationParam := relationTovmmRsVswitchOverrideLacpPol.(string)164 checkDns = append(checkDns, relationParam)165 }166 if relationTovmmRsVswitchOverrideLldpIfPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_lldp_if_pol"); ok {167 relationParam := relationTovmmRsVswitchOverrideLldpIfPol.(string)168 checkDns = append(checkDns, relationParam)169 }170 if relationTovmmRsVswitchOverrideMcpIfPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_mcp_if_pol"); ok {171 relationParam := relationTovmmRsVswitchOverrideMcpIfPol.(string)172 checkDns = append(checkDns, relationParam)173 }174 if relationTovmmRsVswitchOverrideMtuPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_mtu_pol"); ok {175 relationParam := relationTovmmRsVswitchOverrideMtuPol.(string)176 checkDns = append(checkDns, relationParam)177 }178 if relationTovmmRsVswitchOverrideStpPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_stp_pol"); ok {179 relationParam := relationTovmmRsVswitchOverrideStpPol.(string)180 checkDns = append(checkDns, relationParam)181 }182 d.Partial(true)183 err = checkTDn(aciClient, checkDns)184 if err != nil {185 return diag.FromErr(err)186 }187 d.Partial(false)188 if relationTovmmRsVswitchExporterPol, ok := d.GetOk("relation_vmm_rs_vswitch_exporter_pol"); ok {189 relationParamList := relationTovmmRsVswitchExporterPol.(*schema.Set).List()190 for _, relationParam := range relationParamList {191 paramMap := relationParam.(map[string]interface{})192 err = aciClient.CreateRelationvmmRsVswitchExporterPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, paramMap["active_flow_time_out"].(string), paramMap["idle_flow_time_out"].(string), paramMap["sampling_rate"].(string), paramMap["target_dn"].(string))193 if err != nil {194 return diag.FromErr(err)195 }196 }197 }198 if relationTovmmRsVswitchOverrideCdpIfPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_cdp_if_pol"); ok {199 relationParam := relationTovmmRsVswitchOverrideCdpIfPol.(string)200 err = aciClient.CreateRelationvmmRsVswitchOverrideCdpIfPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, relationParam)201 if err != nil {202 return diag.FromErr(err)203 }204 }205 if relationTovmmRsVswitchOverrideFwPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_fw_pol"); ok {206 relationParam := relationTovmmRsVswitchOverrideFwPol.(string)207 err = aciClient.CreateRelationvmmRsVswitchOverrideFwPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, relationParam)208 if err != nil {209 return diag.FromErr(err)210 }211 }212 if relationTovmmRsVswitchOverrideLacpPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_lacp_pol"); ok {213 relationParam := relationTovmmRsVswitchOverrideLacpPol.(string)214 err = aciClient.CreateRelationvmmRsVswitchOverrideLacpPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, relationParam)215 if err != nil {216 return diag.FromErr(err)217 }218 }219 if relationTovmmRsVswitchOverrideLldpIfPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_lldp_if_pol"); ok {220 relationParam := relationTovmmRsVswitchOverrideLldpIfPol.(string)221 err = aciClient.CreateRelationvmmRsVswitchOverrideLldpIfPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, relationParam)222 if err != nil {223 return diag.FromErr(err)224 }225 }226 if relationTovmmRsVswitchOverrideMcpIfPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_mcp_if_pol"); ok {227 relationParam := relationTovmmRsVswitchOverrideMcpIfPol.(string)228 err = aciClient.CreateRelationvmmRsVswitchOverrideMcpIfPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, relationParam)229 if err != nil {230 return diag.FromErr(err)231 }232 }233 if relationTovmmRsVswitchOverrideMtuPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_mtu_pol"); ok {234 relationParam := relationTovmmRsVswitchOverrideMtuPol.(string)235 err = aciClient.CreateRelationvmmRsVswitchOverrideMtuPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, relationParam)236 if err != nil {237 return diag.FromErr(err)238 }239 }240 if relationTovmmRsVswitchOverrideStpPol, ok := d.GetOk("relation_vmm_rs_vswitch_override_stp_pol"); ok {241 relationParam := relationTovmmRsVswitchOverrideStpPol.(string)242 err = aciClient.CreateRelationvmmRsVswitchOverrideStpPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, relationParam)243 if err != nil {244 return diag.FromErr(err)245 }246 }247 d.SetId(vmmVSwitchPolicyCont.DistinguishedName)248 log.Printf("[DEBUG] %s: Creation finished successfully", d.Id())249 return resourceAciVSwitchPolicyGroupRead(ctx, d, m)250}251func resourceAciVSwitchPolicyGroupUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {252 log.Printf("[DEBUG] VSwitchPolicyGroup: Beginning Update")253 aciClient := m.(*client.Client)254 desc := d.Get("description").(string)255 VMMDomainDn := d.Get("vmm_domain_dn").(string)256 vmmVSwitchPolicyContAttr := models.VSwitchPolicyGroupAttributes{}257 nameAlias := ""258 if NameAlias, ok := d.GetOk("name_alias"); ok {259 nameAlias = NameAlias.(string)260 }261 if Annotation, ok := d.GetOk("annotation"); ok {262 vmmVSwitchPolicyContAttr.Annotation = Annotation.(string)263 } else {264 vmmVSwitchPolicyContAttr.Annotation = "{}"265 }266 vmmVSwitchPolicyCont := models.NewVSwitchPolicyGroup(fmt.Sprintf("vswitchpolcont"), VMMDomainDn, desc, nameAlias, vmmVSwitchPolicyContAttr)267 vmmVSwitchPolicyCont.Status = "modified"268 err := aciClient.Save(vmmVSwitchPolicyCont)269 if err != nil {270 return diag.FromErr(err)271 }272 checkDns := make([]string, 0, 1)273 if d.HasChange("relation_vmm_rs_vswitch_exporter_pol") || d.HasChange("annotation") {274 oldRel, newRel := d.GetChange("relation_vmm_rs_vswitch_exporter_pol")275 oldRelSet := oldRel.(*schema.Set)276 newRelSet := newRel.(*schema.Set)277 relToCreate := toStringList(newRelSet.Difference(oldRelSet).List())278 for _, relDn := range relToCreate {279 checkDns = append(checkDns, relDn)280 }281 }282 if d.HasChange("relation_vmm_rs_vswitch_override_cdp_if_pol") || d.HasChange("annotation") {283 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_cdp_if_pol")284 checkDns = append(checkDns, newRelParam.(string))285 }286 if d.HasChange("relation_vmm_rs_vswitch_override_fw_pol") || d.HasChange("annotation") {287 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_fw_pol")288 checkDns = append(checkDns, newRelParam.(string))289 }290 if d.HasChange("relation_vmm_rs_vswitch_override_lacp_pol") || d.HasChange("annotation") {291 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_lacp_pol")292 checkDns = append(checkDns, newRelParam.(string))293 }294 if d.HasChange("relation_vmm_rs_vswitch_override_lldp_if_pol") || d.HasChange("annotation") {295 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_lldp_if_pol")296 checkDns = append(checkDns, newRelParam.(string))297 }298 if d.HasChange("relation_vmm_rs_vswitch_override_mcp_if_pol") || d.HasChange("annotation") {299 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_mcp_if_pol")300 checkDns = append(checkDns, newRelParam.(string))301 }302 if d.HasChange("relation_vmm_rs_vswitch_override_mtu_pol") || d.HasChange("annotation") {303 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_mtu_pol")304 checkDns = append(checkDns, newRelParam.(string))305 }306 if d.HasChange("relation_vmm_rs_vswitch_override_stp_pol") || d.HasChange("annotation") {307 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_stp_pol")308 checkDns = append(checkDns, newRelParam.(string))309 }310 d.Partial(true)311 err = checkTDn(aciClient, checkDns)312 if err != nil {313 return diag.FromErr(err)314 }315 d.Partial(false)316 if d.HasChange("relation_vmm_rs_vswitch_exporter_pol") || d.HasChange("annotation") {317 oldRel, newRel := d.GetChange("relation_vmm_rs_vswitch_exporter_pol")318 oldRelList := oldRel.(*schema.Set).List()319 newRelList := newRel.(*schema.Set).List()320 for _, relationParam := range oldRelList {321 paramMap := relationParam.(map[string]interface{})322 err = aciClient.DeleteRelationvmmRsVswitchExporterPol(vmmVSwitchPolicyCont.DistinguishedName, paramMap["target_dn"].(string))323 if err != nil {324 return diag.FromErr(err)325 }326 }327 for _, relationParam := range newRelList {328 paramMap := relationParam.(map[string]interface{})329 err = aciClient.CreateRelationvmmRsVswitchExporterPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, paramMap["active_flow_time_out"].(string), paramMap["idle_flow_time_out"].(string), paramMap["sampling_rate"].(string), paramMap["target_dn"].(string))330 if err != nil {331 return diag.FromErr(err)332 }333 }334 }335 if d.HasChange("relation_vmm_rs_vswitch_override_cdp_if_pol") || d.HasChange("annotation") {336 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_cdp_if_pol")337 err = aciClient.DeleteRelationvmmRsVswitchOverrideCdpIfPol(vmmVSwitchPolicyCont.DistinguishedName)338 if err != nil {339 return diag.FromErr(err)340 }341 err = aciClient.CreateRelationvmmRsVswitchOverrideCdpIfPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, newRelParam.(string))342 if err != nil {343 return diag.FromErr(err)344 }345 }346 if d.HasChange("relation_vmm_rs_vswitch_override_fw_pol") || d.HasChange("annotation") {347 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_fw_pol")348 err = aciClient.DeleteRelationvmmRsVswitchOverrideFwPol(vmmVSwitchPolicyCont.DistinguishedName)349 if err != nil {350 return diag.FromErr(err)351 }352 err = aciClient.CreateRelationvmmRsVswitchOverrideFwPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, newRelParam.(string))353 if err != nil {354 return diag.FromErr(err)355 }356 }357 if d.HasChange("relation_vmm_rs_vswitch_override_lacp_pol") || d.HasChange("annotation") {358 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_lacp_pol")359 err = aciClient.DeleteRelationvmmRsVswitchOverrideLacpPol(vmmVSwitchPolicyCont.DistinguishedName)360 if err != nil {361 return diag.FromErr(err)362 }363 err = aciClient.CreateRelationvmmRsVswitchOverrideLacpPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, newRelParam.(string))364 if err != nil {365 return diag.FromErr(err)366 }367 }368 if d.HasChange("relation_vmm_rs_vswitch_override_lldp_if_pol") || d.HasChange("annotation") {369 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_lldp_if_pol")370 err = aciClient.DeleteRelationvmmRsVswitchOverrideLldpIfPol(vmmVSwitchPolicyCont.DistinguishedName)371 if err != nil {372 return diag.FromErr(err)373 }374 err = aciClient.CreateRelationvmmRsVswitchOverrideLldpIfPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, newRelParam.(string))375 if err != nil {376 return diag.FromErr(err)377 }378 }379 if d.HasChange("relation_vmm_rs_vswitch_override_mcp_if_pol") || d.HasChange("annotation") {380 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_mcp_if_pol")381 err = aciClient.DeleteRelationvmmRsVswitchOverrideMcpIfPol(vmmVSwitchPolicyCont.DistinguishedName)382 if err != nil {383 return diag.FromErr(err)384 }385 err = aciClient.CreateRelationvmmRsVswitchOverrideMcpIfPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, newRelParam.(string))386 if err != nil {387 return diag.FromErr(err)388 }389 }390 if d.HasChange("relation_vmm_rs_vswitch_override_mtu_pol") || d.HasChange("annotation") {391 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_mtu_pol")392 err = aciClient.DeleteRelationvmmRsVswitchOverrideMtuPol(vmmVSwitchPolicyCont.DistinguishedName)393 if err != nil {394 return diag.FromErr(err)395 }396 err = aciClient.CreateRelationvmmRsVswitchOverrideMtuPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, newRelParam.(string))397 if err != nil {398 return diag.FromErr(err)399 }400 }401 if d.HasChange("relation_vmm_rs_vswitch_override_stp_pol") || d.HasChange("annotation") {402 _, newRelParam := d.GetChange("relation_vmm_rs_vswitch_override_stp_pol")403 err = aciClient.DeleteRelationvmmRsVswitchOverrideStpPol(vmmVSwitchPolicyCont.DistinguishedName)404 if err != nil {405 return diag.FromErr(err)406 }407 err = aciClient.CreateRelationvmmRsVswitchOverrideStpPol(vmmVSwitchPolicyCont.DistinguishedName, vmmVSwitchPolicyContAttr.Annotation, newRelParam.(string))408 if err != nil {409 return diag.FromErr(err)410 }411 }412 d.SetId(vmmVSwitchPolicyCont.DistinguishedName)413 log.Printf("[DEBUG] %s: Update finished successfully", d.Id())414 return resourceAciVSwitchPolicyGroupRead(ctx, d, m)415}416func resourceAciVSwitchPolicyGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {417 log.Printf("[DEBUG] %s: Beginning Read", d.Id())418 aciClient := m.(*client.Client)419 dn := d.Id()420 vmmVSwitchPolicyCont, err := getRemoteVSwitchPolicyGroup(aciClient, dn)421 if err != nil {...
vmm_manager.go
Source:vmm_manager.go
...144 vmmMgr.storageRootPath = filepath.Join(vmmMgr.appRootPath, "storage")145 vmmMgr.instanceConfigRootPath = filepath.Join(vmmMgr.appRootPath, "instances")146 vmmMgr.fcInstanceRootPath = filepath.Join(vmmMgr.appRootPath, "firecracker")147 binPath := filepath.Join(vmmMgr.appRootPath, "bin")148 vutils.Files.CreateDirIfNotExist(binPath)149 fcBinary, err := assets.FireCrackerAssets.Open("firecracker")150 if err == nil {151 of, err := os.Create(filepath.Join(binPath, "firecracker"))152 of.Chmod(0700)153 if err != nil {154 println(err.Error())155 } else {156 io.Copy(of, fcBinary)157 of.Close()158 }159 fcBinary.Close()160 }161 jlrBinary, err := assets.FireCrackerAssets.Open("jailer")162 if err == nil {163 of, err := os.Create(filepath.Join(binPath, "jailer"))164 of.Chmod(0700)165 if err != nil {166 println(err.Error())167 } else {168 io.Copy(of, jlrBinary)169 of.Close()170 }171 jlrBinary.Close()172 }173 if err := vutils.Files.CreateDirIfNotExist(vmmMgr.instanceConfigRootPath); err != nil {174 return err175 } else if err := vutils.Files.CreateDirIfNotExist(vmmMgr.storageRootPath); err != nil {176 return err177 } else if err := vutils.Files.CreateDirIfNotExist(vmmMgr.cacheRootPath); err != nil {178 return err179 } else if err := vutils.Files.CreateDirIfNotExist(filepath.Join(vmmMgr.cacheRootPath, "images")); err != nil {180 return err181 } else if err := vutils.Files.CreateDirIfNotExist(vmmMgr.fcInstanceRootPath); err != nil {182 return err183 } else {184 //now chown everything!185 // err = config.DoChown(vmmMgr.appRootPath, vmmMgr.uid, vmmMgr.gid, true)186 // if err != nil {187 // return err188 // }189 }190 return nil191}192func (vmmMgr *VmmManager) setupNetworking() error {193 log.Printf("Initialising Networking...")194 netMgr, err := networking.NewManager(vmmMgr.config.Networks)195 if err != nil {196 return err197 }198 vmmMgr.networks = netMgr199 return err200}201func (vmmMgr *VmmManager) GetConfig() *config.PromethiumDaemonConfig {202 return vmmMgr.config203}204func (vmmMgr *VmmManager) Wait() error {205 return nil206}207func (vmmMgr *VmmManager) Kill() error {208 //kill all instances IMMEDIATELY209 for _, vmm := range vmmMgr.instances {210 vmm.Kill()211 }212 for _, vmmColl := range vmmMgr.clusterInstances {213 for _, vmm := range vmmColl {214 vmm.Kill()215 }216 }217 return vmmMgr.cleanupForExit()218}219func (vmmMgr *VmmManager) WaitKill() error {220 //kill all instances IMMEDIATELY221 vmmMgr.killGroup = sync.WaitGroup{}222 for _, vmm := range vmmMgr.instances {223 vmmMgr.killGroup.Add(1)224 go func(inVmm *Vmm) {225 fmt.Printf("Killing VMM With Timeout: %s\n", inVmm.ID())226 err := inVmm.WaitKill(30 * time.Second)227 if err != nil {228 fmt.Printf("Error waiting on shutdown: %s\n", err.Error())229 } else {230 fmt.Printf("VMM Killed With Timeout: %s\n", inVmm.ID())231 }232 vmmMgr.killGroup.Done()233 }(vmm)234 }235 for _, vmmColl := range vmmMgr.clusterInstances {236 for _, vmm := range vmmColl {237 vmmMgr.killGroup.Add(1)238 go func(inVmm *Vmm) {239 inVmm.WaitKill(30 * time.Second)240 vmmMgr.killGroup.Done()241 }(vmm)242 }243 }244 vmmMgr.killGroup.Wait()245 log.Println("Waiting on shutdown completed")246 return vmmMgr.cleanupForExit()247}248func (vmmMgr *VmmManager) cleanupForExit() error {249 vmmMgr.storageManager.Dispose()250 log.Println("Cleanup complete")251 return nil252}253func (vmmMgr *VmmManager) Storage() *storage.StorageManager {254 return vmmMgr.storageManager255}256func (vmmMgr *VmmManager) Create(newVmConf *models.NewVM) (*Vmm, error) {257 //need to create a templated VM..258 //get storage back end259 //get linux bridge260 return vmmMgr.NewVmmFromImage(newVmConf.Name, newVmConf.Cpus, newVmConf.Memory, newVmConf.FromImage, uint64(newVmConf.RootDiskSize), newVmConf.StorageName, newVmConf.PrimaryNetworkID, newVmConf.KernelImage)261}262func (vmmMgr *VmmManager) List(showAll bool) []*Vmm {263 instList := []*Vmm{}264 for _, vmm := range vmmMgr.instances {265 if showAll {266 instList = append(instList, vmm)267 } else {268 status := vmm.Status()269 if status == "Running" || status == "Starting" {270 instList = append(instList, vmm)...
Create
Using AI Code Generation
1import (2func main() {3 if err != nil {4 }5 defer conn.Close()6 dom, err := conn.LookupDomainByName("test")7 if err != nil {8 fmt.Println("Failed to lookup domain")9 }10 defer dom.Free()11 vmm, err := dom.VMMSnapshotCreateXML("<domainsnapshot><name>test</name></domainsnapshot>", 0)12 if err != nil {13 fmt.Println("Failed to create snapshot")14 }15 defer vmm.Free()16}17import (18func main() {19 if err != nil {20 }21 defer conn.Close()22 dom, err := conn.LookupDomainByName("test")23 if err != nil {24 fmt.Println("Failed to lookup domain")25 }26 defer dom.Free()27 if err := dom.Create(); err != nil {28 fmt.Println("Failed to start domain")29 }30 vmm, err := dom.VMMSnapshotCreateXML("<domainsnapshot><name>test</name></domainsnapshot>", 0)31 if err != nil {32 fmt.Println("Failed to create snapshot")33 }34 defer vmm.Free()35}36import (37func main()
Create
Using AI Code Generation
1vmm := vmm.NewVmm()2vmm.Create()3vmm := vmm.NewVmm()4vmm.Create()5vmm := vmm.NewVmm()6vmm.Create()7vmm := vmm.NewVmm()8vmm.Create()9vmm := vmm.NewVmm()10vmm.Create()11vmm := vmm.NewVmm()12vmm.Create()13vmm := vmm.NewVmm()14vmm.Create()15vmm := vmm.NewVmm()16vmm.Create()17vmm := vmm.NewVmm()18vmm.Create()19vmm := vmm.NewVmm()20vmm.Create()21vmm := vmm.NewVmm()22vmm.Create()23vmm := vmm.NewVmm()24vmm.Create()25vmm := vmm.NewVmm()26vmm.Create()27vmm := vmm.NewVmm()28vmm.Create()29vmm := vmm.NewVmm()30vmm.Create()31vmm := vmm.NewVmm()32vmm.Create()
Create
Using AI Code Generation
1import (2func main() {3 vmm.Create()4 fmt.Println("VM created")5}6import (7func main() {8 vmm.Create()9 fmt.Println("VM created")10}11import (12func main() {13 vmm.Create()14 fmt.Println("VM created")15}16import (17func main() {18 vmm.Create()19 fmt.Println("VM created")20}21import (22func main() {23 vmm.Create()24 fmt.Println("VM created")25}26import (27func main() {28 vmm.Create()29 fmt.Println("VM created")30}31import (
Create
Using AI Code Generation
1var vmm = new ActiveXObject("WbemScripting.SWbemLocator");2var service = vmm.ConnectServer(null, "root/virtualization");3var vm = service.Get("Msvm_VirtualSystemSettingData.Name='MyVM'");4var vmms = service.Get("Msvm_VirtualSystemManagementService.Name='vmms'");5var job = vmms.CreateVirtualSystemSnapshot(vm, "MySnapshot", "Snapshot of MyVM", null);6job.Get();7var vmm = new ActiveXObject("WbemScripting.SWbemLocator");8var service = vmm.ConnectServer(null, "root/virtualization");9var vm = service.Get("Msvm_VirtualSystemSettingData.Name='MyVM'");10var vmms = service.Get("Msvm_VirtualSystemManagementService.Name='vmms'");11var job = vmms.CreateVirtualSystemSnapshot(vm, "MySnapshot", "Snapshot of MyVM", null);12job.Get();13var vmm = new ActiveXObject("WbemScripting.SWbemLocator");14var service = vmm.ConnectServer(null, "root/virtualization");15var vm = service.Get("Msvm_VirtualSystemSettingData.Name='MyVM'");16var vmms = service.Get("Msvm_VirtualSystemManagementService.Name='vmms'");17var job = vmms.CreateVirtualSystemSnapshot(vm, "MySnapshot", "Snapshot of MyVM", null);18job.Get();19var vmm = new ActiveXObject("WbemScripting.SWbemLocator");20var service = vmm.ConnectServer(null, "root/virtualization");21var vm = service.Get("Msvm_VirtualSystemSettingData.Name='MyVM'");22var vmms = service.Get("Msvm_VirtualSystemManagementService.Name='vmms'");23var job = vmms.CreateVirtualSystemSnapshot(vm, "MySnapshot", "Snapshot of MyVM", null);24job.Get();25var vmm = new ActiveXObject("WbemScripting.SWbemLocator");26var service = vmm.ConnectServer(null, "root/virtualization");
Create
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World")4 vmm.Create()5}6import (7func main() {8 fmt.Println("Hello World")9 vmm.Delete()10}11import (12func main() {13 fmt.Println("Hello World")14 vmm.Stop()15}16import (17func main() {18 fmt.Println("Hello World")19 vmm.Start()20}21import (22func main() {23 fmt.Println("Hello World")24 vmm.Restart()25}26import (27func main() {28 fmt.Println("Hello World")29 vmm.Status()30}31import (32func main() {33 fmt.Println("Hello World")34 vmm.Info()35}36import (37func main() {38 fmt.Println("Hello World")39 vmm.List()40}41import (
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!