예제 #1
0
파일: handlers.go 프로젝트: reoring/tsuru
func (p *dockerProvisioner) addNodeForParams(params map[string]string, isRegister bool) (map[string]string, error) {
	response := make(map[string]string)
	var machineID string
	var address string
	if isRegister {
		address, _ = params["address"]
		delete(params, "address")
	} else {
		desc, _ := iaas.Describe(params["iaas"])
		response["description"] = desc
		m, err := iaas.CreateMachine(params)
		if err != nil {
			return response, err
		}
		address = m.FormatNodeAddress()
		machineID = m.Id
	}
	err := validateNodeAddress(address)
	if err != nil {
		return response, err
	}
	node := cluster.Node{Address: address, Metadata: params, CreationStatus: cluster.NodeCreationStatusPending}
	err = p.Cluster().Register(node)
	if err != nil {
		return response, err
	}
	q, err := queue.Queue()
	if err != nil {
		return response, err
	}
	jobParams := monsterqueue.JobParams{"endpoint": address, "machine": machineID, "metadata": params}
	_, err = q.Enqueue(bs.QueueTaskName, jobParams)
	return response, err
}
예제 #2
0
func (s *S) TestCreateMachineValidations(c *gocheck.C) {
	iaas := &EC2IaaS{}
	_, err := iaas.CreateMachine(map[string]string{
		"region": "invalid-region",
	})
	c.Assert(err, gocheck.ErrorMatches, `region "invalid-region" not found`)
	_, err = iaas.CreateMachine(map[string]string{
		"region": "myregion",
	})
	c.Assert(err, gocheck.ErrorMatches, "image param required")
	_, err = iaas.CreateMachine(map[string]string{
		"region": "myregion",
		"image":  "ami-xxxxx",
	})
	c.Assert(err, gocheck.ErrorMatches, "type param required")
}
예제 #3
0
파일: node.go 프로젝트: tsuru/tsuru
func addNodeForParams(p provision.NodeProvisioner, params provision.AddNodeOptions) (string, map[string]string, error) {
	response := make(map[string]string)
	var address string
	if params.Register {
		address, _ = params.Metadata["address"]
		delete(params.Metadata, "address")
	} else {
		desc, _ := iaas.Describe(params.Metadata["iaas"])
		response["description"] = desc
		m, err := iaas.CreateMachine(params.Metadata)
		if err != nil {
			return address, response, err
		}
		address = m.FormatNodeAddress()
		params.CaCert = m.CaCert
		params.ClientCert = m.ClientCert
		params.ClientKey = m.ClientKey
	}
	prov, _, err := provision.FindNode(address)
	if err != provision.ErrNodeNotFound {
		if err == nil {
			return "", nil, errors.Errorf("node with address %q already exists in provisioner %q", address, prov.GetName())
		}
		return "", nil, err
	}
	err = validateNodeAddress(address)
	if err != nil {
		return address, response, err
	}
	params.Address = address
	err = p.AddNode(params)
	return address, response, err
}
예제 #4
0
func (s *S) TestCreateMachine(c *gocheck.C) {
	params := map[string]string{
		"region": "myregion",
		"image":  "ami-xxxxxx",
		"type":   "m1.micro",
	}
	iaas := &EC2IaaS{}
	m, err := iaas.CreateMachine(params)
	m.CreationParams = map[string]string{"region": "myregion"}
	defer iaas.DeleteMachine(m)
	c.Assert(err, gocheck.IsNil)
	c.Assert(m.Id, gocheck.Matches, `i-\d`)
	c.Assert(m.Address, gocheck.Matches, `i-\d.testing.invalid`)
	c.Assert(m.Status, gocheck.Equals, "pending")
}
예제 #5
0
func addNodeForParams(params map[string]string, isRegister bool) (map[string]string, error) {
	response := make(map[string]string)
	var address string
	if isRegister {
		address, _ = params["address"]
		delete(params, "address")
	} else {
		iaasName, _ := params["iaas"]
		desc, err := iaas.Describe(iaasName)
		if err != nil {
			return response, err
		}
		response["description"] = desc
		var m *iaas.Machine
		if iaasName != "" {
			m, err = iaas.CreateMachineForIaaS(iaasName, params)
		} else {
			m, err = iaas.CreateMachine(params)
		}
		if err != nil {
			return response, err
		}
		nodeAddress, err := m.FormatNodeAddress()
		if err != nil {
			return response, err
		}
		params["iaas"] = m.Iaas
		address = nodeAddress
	}
	err := validateNodeAddress(address)
	if err != nil {
		return response, err
	}
	err = dockerCluster().Register(address, params)
	if err != nil {
		return response, err
	}
	return response, err
}