def _authenticate_security_group_response(response, rule_type): if "errortext" in response: if "Failed to authorize security group" in response["errortext"]: cidrlist = str(helpers.get("CidrIp")) protocol = str(helpers.get("IpProtocol")) from_port = str(helpers.get("FromPort")) to_port = str(helpers.get("toPort")) raise Ec2stackError( "400", "InvalidPermission.Duplicate", 'the specified rule "peer: ' + cidrlist + ", " + protocol + ", from port: " + from_port + ", to port: " + to_port + ', ALLOW" already exists', ) elif "Unable to find security group" in response["errortext"]: errors.invalid_security_group() errors.invalid_paramater_value(response["errortext"]) else: if rule_type == "ingress": rule_type = "AuthorizeSecurityGroupIngressResponse" elif rule_type == "egress": rule_type = "AuthorizeSecurityGroupEgressResponse" return {"template_name_or_list": "status.xml", "response_type": rule_type, "return": "true"}
def _authenticate_security_group_response(response, rule_type): if 'errortext' in response: if 'Failed to authorize security group' in response['errortext']: cidrlist = str(helpers.get('CidrIp')) protocol = str(helpers.get('IpProtocol')) from_port = str(helpers.get('FromPort')) to_port = str(helpers.get('toPort')) raise Ec2stackError( '400', 'InvalidPermission.Duplicate', 'the specified rule "peer: ' + cidrlist + ', ' + protocol + ', from port: ' + from_port + ', to port: ' + to_port + ', ALLOW" already exists') elif 'Unable to find security group' in response['errortext']: errors.invalid_security_group() errors.invalid_paramater_value(response['errortext']) else: if rule_type == 'ingress': rule_type = 'AuthorizeSecurityGroupIngressResponse' elif rule_type == 'egress': rule_type = 'AuthorizeSecurityGroupEgressResponse' return { 'template_name_or_list': 'status.xml', 'response_type': rule_type, 'return': 'true' }
def describe_image_attribute(): image_id = helpers.get('ImageId') attribute = helpers.get('Attribute') supported_attribute_map = { 'description': 'displaytext' } if attribute not in supported_attribute_map.iterkeys(): errors.invalid_paramater_value( 'The specified attribute is not valid, please specify a valid ' + 'image attribute.' ) response = describe_image_by_id(image_id) return _describe_image_attribute_response( response, attribute, supported_attribute_map)
def describe_instance_attribute(): instance_id = helpers.get('InstanceId') attribute = helpers.get('Attribute') supported_attribute_map = { 'instanceType': 'serviceofferingname', 'groupSet': 'securitygroup' } if attribute not in supported_attribute_map.iterkeys(): errors.invalid_paramater_value( 'The specified attribute is not valid, please specify a valid ' + 'instance attribute.' ) response = describe_instance_by_id(instance_id) return _describe_instance_attribute_response( response, attribute, supported_attribute_map)
def _run_instance_response(response): if 'errortext' in response: if 'Invalid parameter templateid' in response['errortext']: errors.invalid_image_id() elif 'Unable to find group' in response['errortext']: errors.invalid_security_group() elif 'Invalid parameter securitygroupids' in response['errortext']: errors.invalid_security_group() elif 'A key pair with name' in response['errortext']: errors.invalid_keypair_name() else: errors.invalid_paramater_value(response['errortext']) else: response = response['virtualmachine'] response = { 'template_name_or_list': 'run_instance.xml', 'response_type': 'RunInstancesResponse', 'response': response } return response