|
@@ -3,19 +3,11 @@ package main
|
|
|
import (
|
|
|
"fmt"
|
|
|
|
|
|
- "github.com/alyu/configparser"
|
|
|
"github.com/gophercloud/gophercloud/openstack/identity/v3/projects"
|
|
|
)
|
|
|
|
|
|
func main() {
|
|
|
- domainID := "614b64b5d4ce4e989ad0590ec56b021f" // mephi domain
|
|
|
-
|
|
|
- var osclient OpenstackIdentityClient
|
|
|
- osclient.client = initIdentityClient()
|
|
|
-
|
|
|
- config, err := configparser.Read("./project_and_roles.conf")
|
|
|
- checkErr(err)
|
|
|
- osclient.config = config
|
|
|
+ osclient := initIdentityClient()
|
|
|
|
|
|
// allProjects := osclient.getProjectsMap(domainID)
|
|
|
// for _, project := range allProjects {
|
|
@@ -27,26 +19,26 @@ func main() {
|
|
|
// }
|
|
|
|
|
|
fmt.Println("Syncing projects...")
|
|
|
- osclient.syncProjects(domainID)
|
|
|
+ osclient.syncProjects()
|
|
|
// fmt.Println("Deleting projects...")
|
|
|
- // osclient.deleteAllProjects(domainID)
|
|
|
+ // osclient.deleteAllProjects()
|
|
|
//fmt.Println("Syncing roles...")
|
|
|
- //syncRoles(domainID)
|
|
|
+ //syncRoles()
|
|
|
}
|
|
|
|
|
|
-func (osclient OpenstackIdentityClient) syncProjects(domainID string) {
|
|
|
+func (osclient OpenstackIdentityClient) syncProjects() {
|
|
|
allUnits := getCleanUnitsMap(osclient.config)
|
|
|
- allProjects := osclient.getProjectsMap(domainID)
|
|
|
+ allProjects := osclient.getProjectsMap()
|
|
|
|
|
|
for persNumber, unit := range allUnits {
|
|
|
if _, ok := allProjects[persNumber]; ok {
|
|
|
- updateOpts := makeUpdateOpts(unit, domainID)
|
|
|
+ updateOpts := makeUpdateOpts(unit, osclient.domainID)
|
|
|
projectID := allProjects[persNumber].ID
|
|
|
updateResult := projects.Update(osclient.client, projectID, updateOpts)
|
|
|
checkErr(updateResult.Err)
|
|
|
fmt.Printf("Project \"%s\" updated\n", *unit.BriefName)
|
|
|
} else {
|
|
|
- createOpts := makeCreateOpts(unit, domainID)
|
|
|
+ createOpts := makeCreateOpts(unit, osclient.domainID)
|
|
|
createResult := projects.Create(osclient.client, createOpts)
|
|
|
checkErr(createResult.Err)
|
|
|
fmt.Printf("Project \"%s\" created\n", *unit.BriefName)
|
|
@@ -54,8 +46,8 @@ func (osclient OpenstackIdentityClient) syncProjects(domainID string) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (osclient OpenstackIdentityClient) createOrUpdateParentIDs(domainID string) {
|
|
|
- allProjects := osclient.getProjectsMap(domainID)
|
|
|
+func (osclient OpenstackIdentityClient) createOrUpdateParentIDs() {
|
|
|
+ allProjects := osclient.getProjectsMap()
|
|
|
|
|
|
for _, project := range allProjects {
|
|
|
if project.Extra["ParentPersNumber"] == nil {
|
|
@@ -77,8 +69,8 @@ func (osclient OpenstackIdentityClient) createOrUpdateParentIDs(domainID string)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func (osclient OpenstackIdentityClient) deleteAllProjects(domainID string) {
|
|
|
- allProjects := osclient.getProjectsMap(domainID)
|
|
|
+func (osclient OpenstackIdentityClient) deleteAllProjects() {
|
|
|
+ allProjects := osclient.getProjectsMap()
|
|
|
|
|
|
index := 1
|
|
|
amount := len(allProjects)
|