def _run_instance_response(response): """ Generates a response for a run instance request. @param response: Response from Cloudstack. @return: Response. """ if 'errortext' in response: if 'Object vm_template' in response['errortext']: errors.invalid_image_id() elif 'Object security_group' in response['errortext']: errors.invalid_security_group() elif 'A key pair with name' in response['errortext']: errors.invalid_keypair_name() else: errors.invalid_request(response['errortext']) else: response = response['virtualmachine'] response = { 'template_name_or_list': 'run_instance.xml', 'response_type': 'RunInstancesResponse', 'response': response } return response
def _authenticate_security_group_response(response, rule_type): """ Generate a response for authenticate security group request. @param response: Cloudstack response. @param rule_type: The type of rule to add. @raise Ec2stackError: If authorize security group fails. @return: Response """ 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() else: errors.invalid_request(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 _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
def _authenticate_security_group_response(response, rule_type): """ Generate a response for authenticate security group request. @param response: Cloudstack response. @param rule_type: The type of rule to add. @raise Ec2stackError: If authorize security group fails. @return: Response """ 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() else: errors.invalid_request(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' }