func Create(args ...string) (string, error) { // At least 2 arguments: entity <Name> if len(args) < 2 { return "Format:\n CREATE <entity> <Name> [options]", nil } entity := args[0] switch entity { case "enterprise": if len(args) != 2 { return "Format:\n CREATE enterprise <Name>", nil } // CREATE enterprise <Name> org := new(nuage_v3_2.Enterprise) org.Name = args[1] err := org.Create(myconn) if err != nil { return "", err } // JSON pretty-print the org jsonorg, _ := json.MarshalIndent(org, "", "\t") fmt.Printf("\n ===> Org: [%s] <=== \n%#s\n", org.Name, string(jsonorg)) return "", err case "domaintemplate": if len(args) != 3 { return "Format:\n CREATE domaintemplate <Name> <Parent Enterprise ID> ", nil } // CREATE domaintemplate <Name> <Parent Enterprise ID> dt := new(nuage_v3_2.Domaintemplate) dt.Name = args[1] dt.ParentID = args[2] err := dt.Create(myconn) if err != nil { return "", err } // JSON pretty-print the domain template jsondt, _ := json.MarshalIndent(dt, "", "\t") fmt.Printf("\n ===> Domain Template: Name [%s] <=== \n%#s\n", dt.Name, string(jsondt)) return "Domain Template Create -- done", err case "domain": if len(args) != 4 { return "Format:\n CREATE domain <Name> <Parent Enterprise ID> <Domain template ID>", nil } // CREATE domain <Name> <Parent Enterprise ID> <Domain template ID> domain := new(nuage_v3_2.Domain) domain.Name = args[1] domain.ParentID = args[2] domain.TemplateID = args[3] err := domain.Create(myconn) if err != nil { return "", err } jsondomain, _ := json.MarshalIndent(domain, "", "\t") fmt.Printf("\n ===> Domain Name [%s] <=== \n%#s\n", domain.Name, string(jsondomain)) return "Domain Create -- done", err case "zonetemplate": if len(args) != 3 { return "Format:\n CREATE zonetemplate <Name> <Parent domain template ID>", nil } // CREATE zonetemplate <Name> <Parent domain template ID> zt := new(nuage_v3_2.Zonetemplate) zt.Name = args[1] zt.ParentID = args[2] err := zt.Create(myconn) if err != nil { return "", err } jsonzt, _ := json.MarshalIndent(zt, "", "\t") fmt.Printf("\n ===> Zone template: Name [%s] <=== \n%#s\n", zt.Name, string(jsonzt)) return "Zone Template Create -- done", err case "zone": if len(args) < 3 { return "Format:\n CREATE zone <Name> <Parent Domain ID> [ <Zone template ID> ]", nil } // CREATE zone <Name> <Parent Domain ID> [ <Zone template ID> ] zone := new(nuage_v3_2.Zone) zone.Name = args[1] zone.ParentID = args[2] if len(args) >= 4 { zone.TemplateID = args[3] } err := zone.Create(myconn) if err != nil { return "", err } jsonzone, _ := json.MarshalIndent(zone, "", "\t") fmt.Printf("\n ===> Zone Name [%s] <=== \n%#s\n", zone.Name, string(jsonzone)) return "Zone Create -- done", err case "subnet": if len(args) < 4 { return "Format:\n CREATE subnet <Name> <Parent Zone ID> <Subnet template ID> \n or:\n CREATE subnet <Name> <Parent Zone ID> <Subnet address> <Subnet mask>\n", nil } switch len(args) { case 4: // CREATE subnet <Name> <Parent Subnet ID> <Subnet template ID> subnet := new(nuage_v3_2.Subnet) subnet.Name = args[1] subnet.ParentID = args[2] subnet.TemplateID = args[3] err := subnet.Create(myconn) if err != nil { return "", err } jsonsubnet, _ := json.MarshalIndent(subnet, "", "\t") fmt.Printf("\n ===> Subnet Name [%s] <=== \n%#s\n", subnet.Name, string(jsonsubnet)) return "Subnet Create -- done", err case 5: // CREATE subnet <Name> <Parent Subnet ID> <Subnet address> <Subnet mask> subnet := new(nuage_v3_2.Subnet) subnet.Name = args[1] subnet.ParentID = args[2] // TBD -- make sure these are proper dot notation... subnet.Address = args[3] subnet.Netmask = args[4] err := subnet.Create(myconn) if err != nil { return "", err } jsonsubnet, _ := json.MarshalIndent(subnet, "", "\t") fmt.Printf("\n ===> Subnet Name [%s] <=== \n%#s\n", subnet.Name, string(jsonsubnet)) return "Subnet Create -- done", err } case "vport": if len(args) < 3 { return "Format:\n CREATE vport <Name> <Parent Subnet ID> [ options ...]", nil } // CREATE vport <Name> <Parent Subnet ID> [ options ...] subnet := new(nuage_v3_2.Subnet) subnet.ID = args[2] var vport nuage_v3_2.VPort vport.Name = args[1] // ??? vport.ID = vport.Name vport.Type = "VM" vport.AddressSpoofing = "INHERITED" vport.Active = true // ???? Not needed but still.... vport.ParentID = subnet.ID vport.ParentType = "subnet" jsonvport, err := json.MarshalIndent(vport, "", "\t") fmt.Printf("\n ===> Created VPort: Name [%s] <=== \n%#s\n", vport.Name, string(jsonvport)) vp, err := subnet.AddVPort(myconn, vport) if err != nil { return "", err } jsonvp, err := json.MarshalIndent(vp, "", "\t") fmt.Printf("\n ===> Created VPort: Name [%s] <=== \n%#s\n", vp.Name, string(jsonvp)) return "VPort Create -- done", err case "vm": if len(args) != 5 { return "Format:\n CREATE vm <Name> <UUID> <Interface0-MAC> <Interface0-VPortID>", nil } // CREATE vm <Name> <UUID> <Interface0-MAC> <Interface0-VPortID> var vm nuage_v3_2.VirtualMachine vm.Name = args[1] vm.UUID = args[2] var vmi nuage_v3_2.VMInterface vmi.MAC = args[3] vmi.VPortID = args[4] vm.Interfaces = append(vm.Interfaces, vmi) err := (&vm).Create(myconn) if err != nil { return "", err } jsonvm, _ := json.MarshalIndent(vm, "", "\t") fmt.Printf("\n ===> Virtual Machine: Name [%s] <=== \n%#s\n", vm.Name, string(jsonvm)) return "Virtual Machine Create -- done", err default: return "Don't know how to create Nuage API entity: [" + entity + "]" + " with Name [" + args[1] + "]" + " and options: " + strings.Join(args[2:], " "), nil } return "", nil }