Пример #1
0
func (u Up) Execute(subcommandFlags []string, state storage.State) (storage.State, error) {
	err := u.awsCredentialValidator.Validate()
	if err != nil {
		return state, err
	}

	err = u.checkForFastFails(state)
	if err != nil {
		return state, err
	}

	keyPair, err := u.keyPairSynchronizer.Sync(ec2.KeyPair{
		Name:       state.KeyPair.Name,
		PublicKey:  state.KeyPair.PublicKey,
		PrivateKey: state.KeyPair.PrivateKey,
	})
	if err != nil {
		return state, err
	}

	state.KeyPair.Name = keyPair.Name
	state.KeyPair.PublicKey = keyPair.PublicKey
	state.KeyPair.PrivateKey = keyPair.PrivateKey

	availabilityZones, err := u.availabilityZoneRetriever.Retrieve(state.AWS.Region)
	if err != nil {
		return state, err
	}

	if state.Stack.Name == "" {
		state.Stack.Name, err = u.stringGenerator.Generate("bbl-aws-", 5)
		if err != nil {
			return state, err
		}
	}

	var certificateARN string
	if lbExists(state.Stack.LBType) {
		certificate, err := u.certificateDescriber.Describe(state.Stack.CertificateName)
		if err != nil {
			return state, err
		}
		certificateARN = certificate.ARN
	}

	stack, err := u.infrastructureManager.Create(state.KeyPair.Name, len(availabilityZones), state.Stack.Name, state.Stack.LBType, certificateARN)
	if err != nil {
		return state, err
	}

	infrastructureConfiguration := boshinit.InfrastructureConfiguration{
		AWSRegion:        state.AWS.Region,
		SubnetID:         stack.Outputs["BOSHSubnet"],
		AvailabilityZone: stack.Outputs["BOSHSubnetAZ"],
		ElasticIP:        stack.Outputs["BOSHEIP"],
		AccessKeyID:      stack.Outputs["BOSHUserAccessKey"],
		SecretAccessKey:  stack.Outputs["BOSHUserSecretAccessKey"],
		SecurityGroup:    stack.Outputs["BOSHSecurityGroup"],
	}

	deployInput, err := boshinit.NewDeployInput(state, infrastructureConfiguration, u.stringGenerator)
	if err != nil {
		return state, err
	}

	deployOutput, err := u.boshDeployer.Deploy(deployInput)
	if err != nil {
		return state, err
	}

	if state.BOSH.IsEmpty() {
		state.BOSH = storage.BOSH{
			DirectorAddress:        stack.Outputs["BOSHURL"],
			DirectorUsername:       deployInput.DirectorUsername,
			DirectorPassword:       deployInput.DirectorPassword,
			DirectorSSLCertificate: string(deployOutput.DirectorSSLKeyPair.Certificate),
			DirectorSSLPrivateKey:  string(deployOutput.DirectorSSLKeyPair.PrivateKey),
			Credentials:            deployOutput.Credentials,
		}
	}

	state.BOSH.State = deployOutput.BOSHInitState
	state.BOSH.Manifest = deployOutput.BOSHInitManifest

	boshClient := u.boshClientProvider.Client(state.BOSH.DirectorAddress, state.BOSH.DirectorUsername,
		state.BOSH.DirectorPassword)

	cloudConfigInput := u.boshCloudConfigurator.Configure(stack, availabilityZones)

	err = u.cloudConfigManager.Update(cloudConfigInput, boshClient)
	if err != nil {
		return state, err
	}

	return state, nil
}
					DirectorUsername: "******",
					DirectorPassword: "******",
				},
			}

			infrastructureConfiguration := boshinit.InfrastructureConfiguration{
				AWSRegion:        "some-aws-region",
				SubnetID:         "some-subnet-id",
				AvailabilityZone: "some-az",
				ElasticIP:        "some-eip",
				AccessKeyID:      "some-access-key-id",
				SecretAccessKey:  "some-secret-access-key",
				SecurityGroup:    "some-security-group",
			}

			deployInput, err := boshinit.NewDeployInput(state, infrastructureConfiguration, fakeStringGenerator)

			Expect(err).NotTo(HaveOccurred())
			Expect(deployInput).To(Equal(boshinit.DeployInput{
				DirectorUsername: "******",
				DirectorPassword: "******",
				State: map[string]interface{}{
					"some-state-key": "some-state-value",
				},
				InfrastructureConfiguration: boshinit.InfrastructureConfiguration{
					AWSRegion:        "some-aws-region",
					SubnetID:         "some-subnet-id",
					AvailabilityZone: "some-az",
					ElasticIP:        "some-eip",
					AccessKeyID:      "some-access-key-id",
					SecretAccessKey:  "some-secret-access-key",