

def configure_instance_security(self, parameters):
    "\n    Setup EC2 security keys and groups. Required input values are read from\n    the parameters dictionary. More specifically, this method expects to\n    find a 'keyname' parameter and a 'group' parameter in the parameters\n    dictionary. Using these provided values, this method will create a new\n    EC2 key-pair and a security group. Security group will be granted permission\n    to access any port on the instantiated VMs. (Also see documentation for the\n    BaseAgent class)\n\n    Args:\n      parameters: A dictionary of parameters.\n    "
    keyname = parameters[self.PARAM_KEYNAME]
    group = parameters[self.PARAM_GROUP]
    AppScaleLogger.log(('Verifying that keyname {0}'.format(keyname) + ' is not already registered.'))
    conn = self.open_connection(parameters)
    if conn.get_key_pair(keyname):
        self.handle_failure("SSH keyname {0} is already registered. Please change the 'keyname' specified in your AppScalefile to a different value, or erase it to have one automatically generated for you.".format(keyname))
    security_groups = conn.get_all_security_groups()
    for security_group in security_groups:
        if (security_group.name == group):
            self.handle_failure("Security group {0} is already registered. Please change the 'group' specified in your AppScalefile to a different value, or erase it to have one automatically generated for you.".format(group))
    AppScaleLogger.log('Creating key pair: {0}'.format(keyname))
    key_pair = conn.create_key_pair(keyname)
    ssh_key = '{0}{1}.key'.format(LocalState.LOCAL_APPSCALE_PATH, keyname)
    LocalState.write_key_file(ssh_key, key_pair.material)
    self.create_security_group(parameters, group)
    self.authorize_security_group(parameters, group, from_port=1, to_port=65535, ip_protocol='udp', cidr_ip='0.0.0.0/0')
    self.authorize_security_group(parameters, group, from_port=1, to_port=65535, ip_protocol='tcp', cidr_ip='0.0.0.0/0')
    self.authorize_security_group(parameters, group, from_port=(- 1), to_port=(- 1), ip_protocol='icmp', cidr_ip='0.0.0.0/0')
    return True

dataset/ETHPy150Open AppScale/appscale-tools/lib/agents/ec2_agent.py EC2Agent.configure_instance_security/original