예제 #1
0
파일: tenant.go 프로젝트: romana/core
func (tsvc *TenantSvc) Initialize(client *common.RestClient) error {
	err := tsvc.store.Connect()
	if err != nil {
		return err
	}

	tsvc.client = client
	topologyURL, err := client.GetServiceUrl("topology")
	if err != nil {
		return err
	}

	index := common.IndexResponse{}
	err = client.Get(topologyURL, &index)
	if err != nil {
		return err
	}

	dcURL := index.Links.FindByRel("datacenter")
	dc := common.Datacenter{}
	err = client.Get(dcURL, &dc)
	if err != nil {
		return err
	}
	// TODO should this always be queried?
	tsvc.dc = dc
	return nil
}
예제 #2
0
파일: resources.go 프로젝트: romana/core
// getAllPoliciesFunc wraps request to Policy for the purpose of unit testing.
func getAllPolicies(restClient *common.RestClient) ([]common.Policy, error) {
	policyUrl, err := restClient.GetServiceUrl("policy")
	if err != nil {
		return nil, err
	}

	policies := []common.Policy{}
	err = restClient.Get(policyUrl+"/policies", &policies)
	if err != nil {
		return nil, err
	}
	return policies, nil
}
예제 #3
0
파일: romana.go 프로젝트: romana/core
// GetTenantID return romana Tenant ID
// corresponding to romana name.
func GetTenantID(client *common.RestClient, name string) (uint64, error) {
	tenantURL, err := client.GetServiceUrl("tenant")
	if err != nil {
		return 0, err
	}

	tenants := []tenant.Tenant{}
	err = client.Get(tenantURL+"/tenants", &tenants)
	if err != nil {
		return 0, err
	}

	for t := range reverse(tenants) {
		if t.Name == name {
			return t.ID, nil
		}
	}

	return 0, errors.New("Romana Tenant ID not found.")
}