def run(self, **kwargs): """ """ assert not env.hosts if not env.get("joyent_account"): print "To use the joyent api you must add a joyent_account value to your env" sys.exit(1) setup_name = "setup.%s" % kwargs.get("type") task = functions.get_task_instance(setup_name) default_dataset = DEFAULT_DATASET default_package = DEFAULT_PACKAGE if task: if hasattr(task, "dataset"): default_dataset = task.dataset if hasattr(task, "server_size"): default_package = task.server_size else: print "I don't know how to add a %s server" % kwargs.get("type") sys.exit(1) location = kwargs.get("data_center") if not location and env.get("joyent_default_data_center"): location = env.joyent_default_data_center elif not location: print "You must supply an data_center argument or add a joyent_default_data_center attribute to your env" sys.exit(1) key_name = raw_input("Enter your ssh key name: ") key_id = "/%s/keys/%s" % (env.joyent_account, key_name) allow_agent = env.get("allow_agent", False) sdc = DataCenter(location=location, key_id=key_id, allow_agent=allow_agent) name = functions.get_remote_name(None, task.config_section, name=kwargs.get("name")) new_args = { "name": name, "dataset": kwargs.get("data_set", default_dataset), "metadata": kwargs.get("metadata", {}), "tags": kwargs.get("tags", {}), "package": kwargs.get("package", default_package), } machine = sdc.create_machine(**new_args) public_ip = machine.public_ips[0] print "added machine %s" % public_ip host_string = "admin@%s" % public_ip print "waiting for machine to be ready" while machine.status() != "running": print "." time.sleep(5) print "done" execute(setup_name, name=name, hosts=[host_string])
def run(self, **kwargs): """ """ assert not env.hosts if not env.get('joyent_account'): print "To use the joyent api you must add a joyent_account value to your env" sys.exit(1) setup_name = 'setup.%s' % kwargs.get('type') task = functions.get_task_instance(setup_name) default_dataset = DEFAULT_DATASET default_package = DEFAULT_PACKAGE if task: if hasattr(task, 'dataset'): default_dataset = task.dataset if hasattr(task, 'server_size'): default_package = task.server_size else: print "I don't know how to add a %s server" % kwargs.get('type') sys.exit(1) location = kwargs.get('data_center') if not location and env.get('joyent_default_data_center'): location = env.joyent_default_data_center elif not location: print "You must supply an data_center argument or add a joyent_default_data_center attribute to your env" sys.exit(1) key_name = raw_input('Enter your ssh key name: ') key_id = '/%s/keys/%s' % ( env.joyent_account, key_name) sdc = DataCenter(location=location, key_id=key_id) name = functions.get_remote_name(None, task.config_section, name=kwargs.get('name')) new_args = { 'name' : name, 'dataset' : kwargs.get('data_set', default_dataset), 'metadata' : kwargs.get('metadata', {}), 'tags' : kwargs.get('tags', {}), 'package' : kwargs.get('package', default_package) } machine = sdc.create_machine(**new_args) public_ip = machine.public_ips[0] print "added machine %s" % public_ip host_string = 'admin@%s' % public_ip print "waiting for machine to be ready" while machine.status() != 'running': print '.' time.sleep(5) print 'done' execute(setup_name, name=name, hosts=[host_string])
def _update_firewalls(self, config_section): # Generate the correct file execute('firewall.update_files', section=config_section) task = functions.get_task_instance('firewall.update_files') filename = task.get_section_path(config_section) execute('firewall.sync_single', filename=filename) # Update any section where this section appears for section in env.config_object.sections(): if config_section in env.config_object.get_list(section, env.config_object.ALLOWED_SECTIONS): execute('firewall.update_files', section=section)
def _update_firewalls(self, config_section): if self.setup_firewall: # Generate the correct file execute('firewall.update_files', section=config_section) task = functions.get_task_instance('firewall.update_files') filename = task.get_section_path(config_section) execute('firewall.sync_single', filename=filename) # Update any section where this section appears for section in env.config_object.server_sections(): if config_section in env.config_object.get_list( section, env.config_object.ALLOWED_SECTIONS): execute('firewall.update_files', section=section)
def run(self, section=None): execute("firewall.update_files", section=section) if section: sections = [section] else: sections = env.config_object.sections() task = functions.get_task_instance("firewall.update_files") for s in sections: filename = task.get_section_path(s) execute( "firewall.sync_single", filename=filename, hosts=env.config_object.get_list(section, env.config_object.CONNECTIONS), )
def run(self, section=None): update = '%s.update_files' % self.task_group single = '%s.sync_single' % self.task_group execute(update, section=section, hosts=[]) if section: sections = [section] else: sections = env.config_object.server_sections() task = functions.get_task_instance(update) for s in sections: hosts = env.config_object.get_list(s, env.config_object.CONNECTIONS) if hosts: filename = task.get_section_path(s) execute(single, filename=filename, hosts=hosts)
def run(self, name=None): """ """ self._update_config(self.config_section) master = self._get_master() self._secure_ssh() self._set_profile() self._add_snmp(self.config_section) self._update_firewalls(self.config_section) execute('postgres.slave_setup', master=master, section=self.config_section) self._save_config() # update firewall for db-server task = functions.get_task_instance('firewall.update_files') filename = task.get_section_path('db-server') execute('firewall.sync_single', filename=filename, hosts=[master])
def run(self, name=None): """ """ self._secure_ssh() self._set_profile() self._update_config(self.config_section) master = self._get_master() self._add_snmp(self.config_section) self._update_firewalls(self.config_section) execute('postgres.slave_setup', master=master, section=self.config_section) self._save_config() # update firewall for db-server task = functions.get_task_instance('firewall.update_files') if task: filename = task.get_section_path('db-server') execute('firewall.sync_single', filename=filename, hosts=[master])
def _modify_others(self): task = functions.get_task_instance('setup.lb_server') execute('nginx.update_app_servers', nginx_conf=task.nginx_conf, section=self.config_section)
def get_name(self): task = functions.get_task_instance('gunicorn.setup') return task.gunicorn_name
def _add_snmp(self, config_section): if self.setup_snmp: execute('snmp.update_files', section=config_section) task = functions.get_task_instance('snmp.update_files') filename = task.get_section_path(config_section) execute('snmp.sync_single', filename=filename)
def run(self, **kwargs): assert not env.hosts conn = get_ec2_connection(server_type='ec2', **kwargs) type = kwargs.get('type') setup_name = 'setup.%s' % type instance_type = DEFAULT_INSTANCE_TYPE ami_id = kwargs.get('ami_id') if not ami_id: ami_id = DEFAULT_AMI task = functions.get_task_instance(setup_name) if task: if hasattr(task, 'instance_type'): instance_type = task.instance_type if hasattr(task, 'ami'): ami_id = task.ami else: print "I don't know how to add a %s server" % type sys.exit(1) amzn = env.get('AWS_CREDENTIAL', os.path.join(env.deploy_path, 'amazon.ini')) parser = ConfigParser() parser.read(amzn) key_name = parser.get('amazon-aws', 'ec2-key-name') key_file = parser.get('amazon-aws', 'ec2-key-file') if not key_name: print "Sorry. You need to create key pair with create_key first." sys.exit(1) elif not os.path.exists(key_file): print( "I find key %s in server.ini file, but the key file is not" " on its location %s. There is something wrong. Please fix " "it, or recreate key pair" % (key_name, key_file)) sys.exit(1) image = conn.get_image(ami_id) security_group = get_security_group(conn, task.config_section) name = functions.get_remote_name(None, task.config_section, name=kwargs.get('name')) SERVER = { 'image_id': image.id, 'instance_type': instance_type, 'security_groups': [security_group], 'key_name': key_name, } reservation = conn.run_instances(**SERVER) print reservation instance = reservation.instances[0] while instance.state != 'running': time.sleep(5) instance.update() print "...instance state: %s" % (instance.state) conn.create_tags([instance.id], {"Name": name}) if not kwargs.get('static_ip', False): ip = instance.ip_address else: elastic_ip = conn.allocate_address() print "...Elastic IP %s allocated" % elastic_ip elastic_ip.associate(instance.id) ip = elastic_ip.public_ip print "...EC2 instance is successfully created." print "...wait 5 seconds for the server to be ready" print "...while waiting, you may want to note down the following info" time.sleep(5) print "..." print "...Instance using image: %s" % image.name print "...Added into security group: %s" % security_group.name print "...Instance ID: %s" % instance.id print "...Public IP: %s" % ip host_string = 'ubuntu@%s' % instance.public_dns_name execute(setup_name, name=name, hosts=[host_string])
def run(self, **kwargs): """ """ assert not env.hosts if not env.get('joyent_account'): print "To use the joyent api you must add a joyent_account value to your env" sys.exit(1) setup_name = 'setup.%s' % kwargs.get('type') task = functions.get_task_instance(setup_name) default_dataset = DEFAULT_DATASET default_package = DEFAULT_PACKAGE if task: if hasattr(task, 'dataset'): default_dataset = task.dataset if hasattr(task, 'server_size'): default_package = task.server_size else: print "I don't know how to add a %s server" % kwargs.get('type') sys.exit(1) location = kwargs.get('data_center') if not location and env.get('joyent_default_data_center'): location = env.joyent_default_data_center elif not location: print "You must supply an data_center argument or add a joyent_default_data_center attribute to your env" sys.exit(1) key_name = raw_input('Enter your ssh key name: ') key_id = '/%s/keys/%s' % (env.joyent_account, key_name) allow_agent = env.get('allow_agent', False) sdc = DataCenter(location=location, key_id=key_id, allow_agent=allow_agent) name = functions.get_remote_name(None, task.config_section, name=kwargs.get('name')) new_args = { 'name': name, 'dataset': kwargs.get('data_set', default_dataset), 'metadata': kwargs.get('metadata', {}), 'tags': kwargs.get('tags', {}), 'package': kwargs.get('package', default_package) } machine = sdc.create_machine(**new_args) public_ip = machine.public_ips[0] print "added machine %s" % public_ip host_string = 'admin@%s' % public_ip print "waiting for machine to be ready" while machine.status() != 'running': print '.' time.sleep(5) print 'done' execute(setup_name, name=name, hosts=[host_string])
def run(self, **kwargs): assert not env.hosts conn = get_ec2_connection(server_type='ec2', **kwargs) type = kwargs.get('type') setup_name = 'setup.%s' % type instance_type = DEFAULT_INSTANCE_TYPE ami_id = kwargs.get('ami_id') if not ami_id: ami_id = DEFAULT_AMI task = functions.get_task_instance(setup_name) if task: if hasattr(task, 'instance_type'): instance_type = task.instance_type if hasattr(task, 'ami'): ami_id = task.ami else: print "I don't know how to add a %s server" % type sys.exit(1) amzn = env.get('AWS_CREDENTIAL', os.path.join(env.deploy_path, 'amazon.ini')) parser = ConfigParser() parser.read(amzn) key_name = parser.get('amazon-aws', 'ec2-key-name') key_file = parser.get('amazon-aws', 'ec2-key-file') if not key_name: print "Sorry. You need to create key pair with create_key first." sys.exit(1) elif not os.path.exists(key_file): print ("I find key %s in server.ini file, but the key file is not" " on its location %s. There is something wrong. Please fix " "it, or recreate key pair" % (key_name, key_file)) sys.exit(1) image = conn.get_image(ami_id) security_group = get_security_group(conn, task.config_section) name = functions.get_remote_name(None, task.config_section, name=kwargs.get('name')) SERVER = { 'image_id': image.id, 'instance_type': instance_type, 'security_groups': [security_group], 'key_name': key_name,} reservation = conn.run_instances(**SERVER) print reservation instance = reservation.instances[0] while instance.state != 'running': time.sleep(5) instance.update() print "...instance state: %s" % (instance.state) conn.create_tags([instance.id], {"Name": name}) if not kwargs.get('static_ip', False): ip = instance.ip_address else: elastic_ip = conn.allocate_address() print "...Elastic IP %s allocated" % elastic_ip elastic_ip.associate(instance.id) ip = elastic_ip.public_ip print "...EC2 instance is successfully created." print "...wait 5 seconds for the server to be ready" print "...while waiting, you may want to note down the following info" time.sleep(5) print "..." print "...Instance using image: %s" % image.name print "...Added into security group: %s" %security_group.name print "...Instance ID: %s" % instance.id print "...Public IP: %s" % ip host_string = 'ubuntu@%s' % instance.public_dns_name execute(setup_name, name=name, hosts=[host_string])