Esempio n. 1
0
func Setup(qpointer *queue.Queue, tlspointer *tls.Config) queue.ResourceManager {
	return &directResourceManager{
		resources: protectedmap.New(),
		q:         qpointer,
		tls:       tlspointer,
	}
}
Esempio n. 2
0
func NewQueue(statefile string, updatetime int, timeout int) Queue {
	//Setup the options
	StateFileLocation = statefile
	KeeperDuration = time.Duration(updatetime) * time.Second
	NetworkTimeout = time.Duration(timeout) * time.Second

	// Build the queue
	q := Queue{
		status:   STATUS_EMPTY,
		pool:     NewResourcePool(),
		stack:    []common.Job{},
		managers: protectedmap.New(),
		stats:    NewStats(),
	}

	if _, err := os.Stat(StateFileLocation); err == nil {
		q.parseState()
	}

	log.WithFields(log.Fields{
		"statefile":  StateFileLocation,
		"keepertime": KeeperDuration,
		"nettimeout": NetworkTimeout,
	}).Debug("Setup a new queue")

	return q
}
Esempio n. 3
0
func Setup(confpath string, qpointer *queue.Queue, tlspointer *tls.Config, caCertPath, caKeyPath string) (queue.ResourceManager, error) {
	log.Debug("Setting up AWS resource manager")

	// Load the configuration file from the path provided during the setup function
	confFile, err := ini.LoadFile(confpath)
	if err != nil {
		log.WithFields(log.Fields{
			"error": err.Error(),
			"file":  confpath,
		}).Error("Unable to load configuration file for AWS resource manager.")
		return &awsResourceManager{}, err
	}

	// Get the bin path
	confGen := confFile.Section("General")
	if len(confGen) == 0 {
		// Nothing retrieved, so return error
		return &awsResourceManager{}, errors.New("No \"General\" configuration section.")
	}

	// Declare a boolean to hold if there are any issues.  Then go through each of the confiugration
	// lines and make sure we have everything in the "General" area that we are looking for.
	var ok bool
	conf.AccessKey, ok = confGen["AccessKeyID"]
	if !ok {
		return &awsResourceManager{}, errors.New("AccessKeyID was not found in the general configuration section of the AWS resource manager config")
	}
	conf.AccessSecret, ok = confGen["SecretAccessKey"]
	if !ok {
		return &awsResourceManager{}, errors.New("SecretAccessKey was not found in the general configuration section of the AWS resource manager config")
	}
	conf.Region, ok = confGen["Region"]
	if !ok {
		return &awsResourceManager{}, errors.New("The Region was not defined in the general configuration section of the AWS resource manager config")
	}
	conf.AMIID, ok = confGen["AMIID"]
	if !ok {
		return &awsResourceManager{}, errors.New("The AMIID of the image to deploy was not defined in the general configuration section of the AWS resource manager config")
	}
	conf.SecurityGroup, ok = confGen["SecurityGroupName"]
	if !ok {
		return &awsResourceManager{}, errors.New("The ID of the security group to use was not defined in the general configuration section of the AWS resource manager config")
	}

	// If we don't have a VPCID defined, we'll assume the default one.
	conf.VPCID, ok = confGen["VPCID"]
	if !ok {
		conf.VPCID = ""
	}

	// Let's see if we have a connection attempts, if so, do it.  Otherwise set to 10.
	tmpAttempts, ok := confGen["ConnectAttempts"]
	if !ok {
		conf.ConnectionAttempts = 10
	} else {
		conf.ConnectionAttempts, err = strconv.Atoi(tmpAttempts)
		if err != nil {
			return &awsResourceManager{}, errors.New("Unable to parse ConnectionAttempts field in AWS resource manager configuration file.")
		}
	}

	// Get the InstanceTypes section
	confTypes := confFile.Section("InstanceTypes")
	if len(confTypes) == 0 {
		// Nothing retrieved, so return error
		return &awsResourceManager{}, errors.New("No 'InstanceTypes' configuration section in aws config.")
	}
	conf.InstanceTypes = make(map[string]string)
	for key, value := range confTypes {
		log.WithFields(log.Fields{
			"id":   key,
			"name": value,
		}).Debug("Added instance type to AWS resource manager configuration")
		conf.InstanceTypes[value] = key
	}
	conf.InstanceTypesOrder = getSortedKeys(conf.InstanceTypes)

	conf.CACert, conf.CAKey, err = common.GetCertandKey(caCertPath, caKeyPath)
	if err != nil {
		return &awsResourceManager{}, err
	}

	aws := awsResourceManager{
		resources: protectedmap.New(),
		q:         qpointer,
		tls:       tlspointer,
		ec2client: getEC2Client(conf.AccessKey, conf.AccessSecret, conf.Region),
	}

	aws.gatherAPIData()

	return &aws, nil
}