コード例 #1
0
var _ = Describe("Manifest", func() {
	Describe("NewManifest", func() {
		It("generates a valid Turbulence AWS manifest", func() {
			manifest, err := turbulence.NewManifest(turbulence.Config{
				Name:         "turbulence",
				DirectorUUID: "some-director-uuid",
				IPRange:      "10.0.16.0/24",
				BOSH: turbulence.ConfigBOSH{
					Target:             "some-bosh-target",
					Username:           "******",
					Password:           "******",
					DirectorCACert:     "some-ca-cert",
					PersistentDiskType: "some-persistent-disk-type",
					VMType:             "some-vm-type",
				},
			}, iaas.AWSConfig{
				AccessKeyID:           "some-access-key-id",
				SecretAccessKey:       "some-secret-access-key",
				DefaultKeyName:        "some-default-key-name",
				DefaultSecurityGroups: []string{"some-default-security-group1"},
				Region:                "some-region",
				Subnets: []iaas.AWSConfigSubnet{
					{ID: "subnet-1234", Range: "10.0.16.0/24", AZ: "some-az-1a"},
				},
				RegistryHost:     "some-registry-host",
				RegistryPassword: "******",
				RegistryPort:     25777,
				RegistryUsername: "******",
			})
			Expect(err).NotTo(HaveOccurred())

			Expect(manifest.DirectorUUID).To(Equal("some-director-uuid"))
コード例 #2
0
func DeployTurbulence(client bosh.Client, config Config) (turbulence.Manifest, error) {
	info, err := client.Info()
	if err != nil {
		return turbulence.Manifest{}, err
	}

	guid, err := NewGUID()
	if err != nil {
		return turbulence.Manifest{}, err
	}

	manifestConfig := turbulence.Config{
		DirectorUUID: info.UUID,
		Name:         "turbulence-consul-" + guid,
		BOSH: turbulence.ConfigBOSH{
			Target:         config.BOSH.Target,
			Username:       config.BOSH.Username,
			Password:       config.BOSH.Password,
			DirectorCACert: config.BOSH.DirectorCACert,
		},
	}

	var iaasConfig iaas.Config
	switch info.CPI {
	case "aws_cpi":
		awsConfig := iaas.AWSConfig{
			AccessKeyID:           config.AWS.AccessKeyID,
			SecretAccessKey:       config.AWS.SecretAccessKey,
			DefaultKeyName:        config.AWS.DefaultKeyName,
			DefaultSecurityGroups: config.AWS.DefaultSecurityGroups,
			Region:                config.AWS.Region,
			RegistryHost:          config.Registry.Host,
			RegistryPassword:      config.Registry.Password,
			RegistryPort:          config.Registry.Port,
			RegistryUsername:      config.Registry.Username,
		}

		manifestConfig.BOSH.PersistentDiskType = config.BOSH.Errand.DefaultPersistentDiskType
		manifestConfig.BOSH.VMType = config.BOSH.Errand.DefaultVMType

		if len(config.AWS.Subnets) > 0 {
			subnet := config.AWS.Subnets[0]

			var cidrBlock string
			cidrPool := NewCIDRPool(subnet.Range, 24, 27)
			cidrBlock, err = cidrPool.Last()
			if err != nil {
				return turbulence.Manifest{}, err
			}

			awsConfig.Subnets = append(awsConfig.Subnets, iaas.AWSConfigSubnet{ID: subnet.ID, Range: cidrBlock, AZ: subnet.AZ, SecurityGroup: subnet.SecurityGroup})
			manifestConfig.IPRange = cidrBlock
		} else {
			return turbulence.Manifest{}, errors.New("aws.subnet is required for AWS IAAS deployment")
		}

		iaasConfig = awsConfig
	case "warden_cpi":
		var cidrBlock string
		cidrPool := NewCIDRPool("10.244.4.0", 24, 27)
		cidrBlock, err = cidrPool.Last()
		if err != nil {
			return turbulence.Manifest{}, err
		}

		manifestConfig.IPRange = cidrBlock
		iaasConfig = iaas.NewWardenConfig()
	default:
		return turbulence.Manifest{}, errors.New("unknown infrastructure type")
	}

	turbulenceManifest, err := turbulence.NewManifest(manifestConfig, iaasConfig)
	if err != nil {
		return turbulence.Manifest{}, err
	}

	yaml, err := turbulenceManifest.ToYAML()
	if err != nil {
		return turbulence.Manifest{}, err
	}

	yaml, err = client.ResolveManifestVersions(yaml)
	if err != nil {
		return turbulence.Manifest{}, err
	}

	turbulenceManifest, err = turbulence.FromYAML(yaml)
	if err != nil {
		return turbulence.Manifest{}, err
	}

	_, err = client.Deploy(yaml)
	if err != nil {
		return turbulence.Manifest{}, err
	}

	return turbulenceManifest, nil
}