예제 #1
0
파일: modelmanager.go 프로젝트: makyo/juju
func (mm *ModelManagerAPI) configSkeleton(source ConfigSource, requestedProviderType string) (map[string]interface{}, error) {
	baseConfig, err := source.Config()
	if err != nil {
		return nil, errors.Trace(err)
	}
	if requestedProviderType != "" && baseConfig.Type() != requestedProviderType {
		return nil, errors.Errorf(
			"cannot create new model with credentials for provider type %q on controller with provider type %q",
			requestedProviderType, baseConfig.Type())
	}
	baseMap := baseConfig.AllAttrs()

	fields, err := modelmanager.RestrictedProviderFields(baseConfig.Type())
	if err != nil {
		return nil, errors.Trace(err)
	}

	var result = make(map[string]interface{})
	for _, field := range fields {
		if value, found := baseMap[field]; found {
			result[field] = value
		}
	}
	return result, nil
}
예제 #2
0
func (*RestrictedProviderFieldsSuite) TestRestrictedProviderFields(c *gc.C) {
	for i, test := range []struct {
		provider string
		expected []string
	}{{
		provider: "azure",
		expected: []string{
			"type", "ca-cert", "state-port", "api-port", "controller-uuid",
			"location", "endpoint", "storage-endpoint",
		},
	}, {
		provider: "dummy",
		expected: []string{
			"type", "ca-cert", "state-port", "api-port", "controller-uuid",
		},
	}, {
		provider: "joyent",
		expected: []string{
			"type", "ca-cert", "state-port", "api-port", "controller-uuid", "sdc-url",
		},
	}, {
		provider: "maas",
		expected: []string{
			"type", "ca-cert", "state-port", "api-port", "controller-uuid",
			"maas-server",
		},
	}, {
		provider: "openstack",
		expected: []string{
			"type", "ca-cert", "state-port", "api-port", "controller-uuid",
			"region", "auth-url", "auth-mode",
		},
	}, {
		provider: "ec2",
		expected: []string{
			"type", "ca-cert", "state-port", "api-port", "controller-uuid",
			"region",
		},
	}} {
		c.Logf("%d: %s provider", i, test.provider)
		fields, err := modelmanager.RestrictedProviderFields(test.provider)
		c.Check(err, jc.ErrorIsNil)
		c.Check(fields, jc.SameContents, test.expected)
	}
}