func DeployMultiAZConsulMigration(client bosh.Client, config Config, deploymentName string) (consul.ManifestV2, error) {
	info, err := client.Info()
	if err != nil {
		return consul.ManifestV2{}, err
	}

	manifestConfig := consul.ConfigV2{
		DirectorUUID:   info.UUID,
		Name:           deploymentName,
		WindowsClients: config.WindowsClients,
	}

	var iaasConfig iaas.Config
	switch info.CPI {
	case "aws_cpi":
		manifestConfig.PersistentDiskType = config.BOSH.Errand.DefaultPersistentDiskType
		manifestConfig.VMType = config.BOSH.Errand.DefaultVMType

		awsConfig := buildAWSConfig(config)
		if len(config.AWS.CloudConfigSubnets) >= 2 {
			subnet := config.AWS.CloudConfigSubnets[0]

			awsConfig.Subnets = append(awsConfig.Subnets, iaas.AWSConfigSubnet{ID: subnet.ID, Range: subnet.Range, AZ: subnet.AZ, SecurityGroup: subnet.SecurityGroup})
			manifestConfig.AZs = append(manifestConfig.AZs, consul.ConfigAZ{Name: "z1", IPRange: subnet.Range, Nodes: 2})

			subnet = config.AWS.CloudConfigSubnets[1]

			awsConfig.Subnets = append(awsConfig.Subnets, iaas.AWSConfigSubnet{ID: subnet.ID, Range: subnet.Range, AZ: subnet.AZ, SecurityGroup: subnet.SecurityGroup})
			manifestConfig.AZs = append(manifestConfig.AZs, consul.ConfigAZ{Name: "z2", IPRange: subnet.Range, Nodes: 1})
		} else {
			return consul.ManifestV2{}, errors.New("AWSSubnet is required for AWS IAAS deployment")
		}

		iaasConfig = awsConfig
	case "warden_cpi":
		iaasConfig = iaas.NewWardenConfig()

		var cidrBlock string
		cidrPool := NewCIDRPool("10.244.4.0", 24, 27)
		cidrBlock, err = cidrPool.Get(0)
		if err != nil {
			return consul.ManifestV2{}, err
		}

		var cidrBlock2 string
		cidrPool2 := NewCIDRPool("10.244.5.0", 24, 27)
		cidrBlock2, err = cidrPool2.Get(0)
		if err != nil {
			return consul.ManifestV2{}, err
		}

		manifestConfig.AZs = []consul.ConfigAZ{
			{
				Name:    "z1",
				IPRange: cidrBlock,
				Nodes:   2,
			},
			{
				Name:    "z2",
				IPRange: cidrBlock2,
				Nodes:   1,
			},
		}
	default:
		return consul.ManifestV2{}, errors.New("unknown infrastructure type")
	}

	manifest, err := consul.NewManifestV2(manifestConfig, iaasConfig)
	if err != nil {
		return consul.ManifestV2{}, err
	}

	consulInstanceGroup, err := manifest.GetInstanceGroup("consul")
	if err != nil {
		return consul.ManifestV2{}, err
	}
	consulInstanceGroup.MigratedFrom = []core.InstanceGroupMigratedFrom{
		{
			Name: "consul_z1",
			AZ:   "z1",
		},
		{
			Name: "consul_z2",
			AZ:   "z2",
		},
	}

	consulTestConsumerInstanceGroup, err := manifest.GetInstanceGroup("test_consumer")
	if err != nil {
		return consul.ManifestV2{}, err
	}

	consulTestConsumerInstanceGroup.MigratedFrom = []core.InstanceGroupMigratedFrom{
		{
			Name: "consul_test_consumer",
			AZ:   "z1",
		},
	}

	for i := range manifest.Releases {
		if manifest.Releases[i].Name == "consul" {
			manifest.Releases[i].Version = ConsulReleaseVersion()
		}
	}

	manifestYAML, err := manifest.ToYAML()
	if err != nil {
		return consul.ManifestV2{}, err
	}

	_, err = client.Deploy(manifestYAML)
	if err != nil {
		return consul.ManifestV2{}, err
	}

	if err := VerifyDeploymentRelease(client, manifestConfig.Name, ConsulReleaseVersion()); err != nil {
		return consul.ManifestV2{}, err
	}

	return manifest, nil
}
Ejemplo n.º 2
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Job", func() {
	Context("Manifest V2", func() {
		var (
			manifest consul.ManifestV2
		)
		BeforeEach(func() {
			var err error
			manifest, err = consul.NewManifestV2(consul.ConfigV2{
				AZs: []consul.ConfigAZ{
					{
						IPRange: "10.244.4.0/24",
						Nodes:   1,
						Name:    "z1",
					},
				},
			}, iaas.NewWardenConfig())
			Expect(err).NotTo(HaveOccurred())
		})
		Describe("SetInstanceCount", func() {
			It("updates the instance count", func() {
				newManifest, err := manifest.SetInstanceCount("consul", 3)
				Expect(err).NotTo(HaveOccurred())

				consulInstanceGroup, err := newManifest.GetInstanceGroup("consul")
				Expect(err).NotTo(HaveOccurred())

				Expect(consulInstanceGroup.Instances).To(Equal(3))
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("ManifestV2", func() {
	Describe("NewManifestV2", func() {
		It("returns a BOSH 2.0 manifest for bosh-lite", func() {
			manifest, err := consul.NewManifestV2(consul.ConfigV2{
				DirectorUUID: "some-director-uuid",
				Name:         "consul-some-random-guid",
				AZs: []consul.ConfigAZ{
					{
						Name:    "z1",
						IPRange: "10.244.4.0/24",
						Nodes:   2,
					},
					{
						Name:    "z2",
						IPRange: "10.244.5.0/24",
						Nodes:   1,
					},
				},
			}, iaas.NewWardenConfig())

			Expect(err).NotTo(HaveOccurred())
			Expect(manifest.DirectorUUID).To(Equal("some-director-uuid"))
			Expect(manifest.Name).To(Equal("consul-some-random-guid"))

			Expect(manifest.Releases).To(Equal([]core.Release{
				{
					Name:    "consul",