github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/identity/v3/projects/doc.go (about) 1 /* 2 Package projects manages and retrieves Projects in the OpenStack Identity 3 Service. 4 5 Example to List Projects 6 7 listOpts := projects.ListOpts{ 8 Enabled: gophercloud.Enabled, 9 } 10 11 allPages, err := projects.List(identityClient, listOpts).AllPages(context.TODO()) 12 if err != nil { 13 panic(err) 14 } 15 16 allProjects, err := projects.ExtractProjects(allPages) 17 if err != nil { 18 panic(err) 19 } 20 21 for _, project := range allProjects { 22 fmt.Printf("%+v\n", project) 23 } 24 25 Example to Create a Project 26 27 createOpts := projects.CreateOpts{ 28 Name: "project_name", 29 Description: "Project Description", 30 Tags: []string{"FirstTag", "SecondTag"}, 31 } 32 33 project, err := projects.Create(context.TODO(), identityClient, createOpts).Extract() 34 if err != nil { 35 panic(err) 36 } 37 38 Example to Update a Project 39 40 projectID := "966b3c7d36a24facaf20b7e458bf2192" 41 42 updateOpts := projects.UpdateOpts{ 43 Enabled: gophercloud.Disabled, 44 } 45 46 project, err := projects.Update(context.TODO(), identityClient, projectID, updateOpts).Extract() 47 if err != nil { 48 panic(err) 49 } 50 51 updateOpts = projects.UpdateOpts{ 52 Tags: &[]string{"FirstTag"}, 53 } 54 55 project, err = projects.Update(context.TODO(), identityClient, projectID, updateOpts).Extract() 56 if err != nil { 57 panic(err) 58 } 59 60 Example to Delete a Project 61 62 projectID := "966b3c7d36a24facaf20b7e458bf2192" 63 err := projects.Delete(context.TODO(), identityClient, projectID).ExtractErr() 64 if err != nil { 65 panic(err) 66 } 67 68 Example to List all tags of a Project 69 70 projectID := "966b3c7d36a24facaf20b7e458bf2192" 71 err := projects.ListTags(context.TODO(), identityClient, projectID).Extract() 72 if err != nil { 73 panic(err) 74 } 75 76 Example to modify all tags of a Project 77 78 projectID := "966b3c7d36a24facaf20b7e458bf2192" 79 tags := ["foo", "bar"] 80 projects, err := projects.ModifyTags(context.TODO(), identityClient, projectID, tags).Extract() 81 if err != nil { 82 panic(err) 83 } 84 85 Example to Delete all tags of a Project 86 87 projectID := "966b3c7d36a24facaf20b7e458bf2192" 88 err := projects.DeleteTags(context.TODO(), identityClient, projectID).ExtractErr() 89 if err != nil { 90 panic(err) 91 } 92 */ 93 package projects