def create(self, server_data, cloud_id=1): self.logger.debug("~~~~ %s ~~~~" % inspect.stack()[0][3]) server_name = (server_data['nickname'] if 'nickname' in server_data else 'unknown') st = ServerTemplate(self.account_id, self.username, self.password) ssh = SshKey(self.account_id, self.username, self.password) template_data = server_data.pop('server_template', None) key_data = server_data.pop('ssh_key', None) security_groups = server_data.pop('security_groups', None) server_data['server_template_href'] = st.get_href(template_data) server_data['ec2_ssh_key_href'] = ssh.get_href(key_data) _ebs_optimized = ('Yes' if 'ebs_optimized' in server_data and (server_data['ebs_optimized'] == 1 or server_data['ebs_optimized'] == 'true') else 'No') self.logger.info("~" * 50) self.logger.info(" Creating Server: %s" % server_name) self.logger.info(" Server Template: %s" % ', '.join(["%s: %s" % (key, val) for (key, val) in template_data.items()])) self.logger.info(" Security Groups: %s" % ', '.join(security_groups)) self.logger.info(" Instance Type: %s" % server_data['instance_type']) #self.logger.info(" Pricing: %s" % server_data['pricing']) self.logger.info(" EBS Optimized: %s" % _ebs_optimized) self.logger.info(" SSH Key: %s" % key_data['aws_key_name']) self.logger.info(" Cloud Id: %d" % cloud_id) self.logger.info("~" * 50) server_data = dict(map(lambda (key, value): ("server[" + str(key) + "]", value), server_data.items())) if cloud_id != 1: self.logger.warn("Deviating from default cloud id of 1!") server_data['cloud_id'] = cloud_id self.logger.debug("Server post data: %s" % server_data) http_code = ResumatorRightScale.make_request(self, self.url, "POST", server_data) if http_code == 201: self.logger.info("Created server '%s'" % server_name) return self.add_security_groups(server_name, security_groups) self.logger.error("HTTP CODE: %d: Unable to create '%s'" % (http_code, server_name)) return False
def get_server_template(self): self._server_template = ServerTemplate(self.server_template_href, self.rsapi)
def create(self, server_data, parameters={}, cloud_id=1): self.logger.debug("~~~~ %s ~~~~" % inspect.stack()[0][3]) array_name = server_data["nickname"] if "nickname" in server_data else "unknown" st = ServerTemplate(self.account_id, self.username, self.password) ssh = SshKey(self.account_id, self.username, self.password) elasticity_data = server_data.pop("elasticity", None) security_groups = server_data.pop("security_groups", None) ssh_key_data = server_data.pop("ssh_key", None) template_data = server_data.pop("server_template", None) array_enabled = ( "Yes" if "active" in server_data and (server_data["active"] == "true" or server_data["active"] == "true") else "No" ) self.logger.info("~" * 50) self.logger.info("Creating Server Array: %s" % array_name) self.logger.info(" Enabled: %s" % array_enabled) self.logger.info( " Server Template: %s" % ", ".join(["%s: %s" % (key, val) for (key, val) in template_data.items()]) ) self.logger.info(" Array Type: %s" % server_data["array_type"]) self.logger.info(" Security Groups: %s" % ", ".join(security_groups)) self.logger.info(" Instance Type: %s" % server_data["instance_type"]) # self.logger.info(" Pricing: %s" % server_data['pricing']) self.logger.info(" SSH Key: %s" % ssh_key_data["aws_key_name"]) self.logger.info(" Cloud Id: %d" % cloud_id) self.logger.info( " Elasticity: %s" % ", ".join(["%s: %s" % (key, val) for (key, val) in elasticity_data.items()]) ) if parameters: self.logger.info(" ~~~~ PARAMETERS ~~~~") for k, v in parameters.items(): self.logger.info("%s: %s" % (k, v)) self.logger.info("~" * 50) server_data["server_template_href"] = st.get_href(template_data) server_data["ec2_ssh_key_href"] = ssh.get_href(ssh_key_data) server_data = dict(map(lambda (key, value): ("server_array[" + str(key) + "]", value), server_data.items())) elasticity_data = dict( map(lambda (key, value): ("server_array[elasticity][" + str(key) + "]", value), elasticity_data.items()) ) server_data = dict(server_data.items() + elasticity_data.items()) if parameters: param_data = dict( map(lambda (key, value): ("server_array[parameters][" + str(key) + "]", value), parameters.items()) ) server_data = dict(server_data.items() + param_data.items()) if cloud_id != 1: self.logger.warn("Deviating from default cloud id of 1!") server_data["cloud_id"] = cloud_id self.logger.debug("Server array post data: %s" % server_data) http_code = ResumatorRightScale.make_request(self, self.url, "POST", server_data) if http_code == 201: self.logger.info("Created server array '%s'" % array_name) return self.add_security_groups(array_name, security_groups) self.logger.error("HTTP CODE: %d: Unable to create '%s'" % (http_code, array_name)) return False