def _create_volume_request(): """ Request to create a volume. @return: Response. """ args = {} if helpers.contains_parameter('SnapshotId'): args['snapshotid'] = helpers.get('SnapshotId') else: helpers.require_parameters(['Size']) args['size'] = helpers.get('Size') args['diskofferingid'] = disk_offerings.get_disk_offering( current_app.config['CLOUDSTACK_CUSTOM_DISK_OFFERING'] )['id'] zone_name = helpers.get('AvailabilityZone') zone_id = zones.get_zone(zone_name)['id'] args['zoneid'] = zone_id args['command'] = 'createVolume' args['name'] = uuid.uuid1() response = requester.make_request_async(args) return response
def _delete_tag_request(): """ Request to delete a tag. @return: Response. """ key = helpers.get('Tag.1.Key') resource_id = helpers.get('ResourceId.1') if resource_id in current_app.config['RESOURCE_TYPE_MAP']: resource_type = current_app.config['RESOURCE_TYPE_MAP'][resource_id] else: errors.invalid_request( str(resource_id) + " not found in configuration") args = { 'command': 'deleteTags', 'resourceids': resource_id, 'resourcetype': resource_type, 'tags[0].key': key } response = requester.make_request_async(args) return response
def _create_vpc_request(): """ Request to create a vpc. @return: Response. """ args = {'command': 'createVPC'} name = uuid.uuid1() args['name'] = name args['displaytext'] = name args['zoneid'] = zones.get_zone( current_app.config['CLOUDSTACK_DEFAULT_ZONE'])['id'] if 'VPC_OFFERING_ID' in current_app.config: args['vpcofferingid'] = current_app.config['VPC_OFFERING_ID'] else: errors.invalid_request( str('VPC_OFFERING_ID') + " not found in configuration, " + "please run ec2stack-configure -a True") args['cidr'] = helpers.get('CidrBlock') response = requester.make_request_async(args) return response
def _create_volume_request(): """ Request to create a volume. @return: Response. """ args = {} if helpers.contains_parameter('SnapshotId'): args['snapshotid'] = helpers.get('SnapshotId') else: helpers.require_parameters(['Size']) args['size'] = helpers.get('Size') args['diskofferingid'] = disk_offerings.get_disk_offering( current_app.config['CLOUDSTACK_CUSTOM_DISK_OFFERING'] )['id'] zone_name = helpers.get('AvailabilityZone') zone_id = zones.get_zone(zone_name)['id'] args['zoneid'] = zone_id args['command'] = 'createVolume' args['name'] = uuid.uuid4() response = requester.make_request_async(args) return response
def _terminate_instance_request(instance_id): args = {'command': 'destroyVirtualMachine', 'id': instance_id} response = requester.make_request_async(args) response = response['virtualmachine'] return response
def _run_instance_request(): args = {} if helpers.get('InstanceType') is None: instance_type = 'm1.small' else: instance_type = helpers.get('InstanceType') if instance_type in current_app.config['INSTANCE_TYPE_MAP']: instance_type = current_app.config[ 'INSTANCE_TYPE_MAP'][instance_type] else: instance_type = instance_type args['serviceofferingid'] = \ service_offerings.get_service_offering(instance_type)['id'] args['templateid'] = helpers.get('ImageId') if helpers.contains_parameter('Placement.AvailabilityZone'): args['zoneid'] = zones.get_zone( helpers.get('Placement.AvailabilityZone') ) else: args['zoneid'] = zones.get_zone( current_app.config['CLOUDSTACK_DEFAULT_ZONE'] )['id'] if helpers.contains_parameter('KeyName'): args['keypair'] = helpers.get('KeyName') if helpers.contains_parameter('UserData'): args['userdata'] = helpers.get('UserData') if helpers.contains_parameter_with_keyword('SecurityGroupId.'): keys = helpers.get_request_parameter_keys('SecurityGroupId.') securitygroupids = [] for key in keys: securitygroupids.append(helpers.get(key)) args['securitygroupids'] = ",".join(securitygroupids) if helpers.contains_parameter_with_keyword('SecurityGroup.'): keys = helpers.get_request_parameter_keys('SecurityGroup.') securitygroupnames = [] for key in keys: securitygroupnames.append(helpers.get(key)) args['securitygroupnames'] = ",".join(securitygroupnames) args['command'] = 'deployVirtualMachine' response = requester.make_request_async(args) return response
def _create_snapshot_request(): """ Request to create a snapshot. @return: Response. """ args = {'command': 'createSnapshot', 'volumeid': helpers.get('VolumeId')} response = requester.make_request_async(args) return response
def _delete_snapshot_request(): """ Request to delete a snapshot. @return: Response. """ args = {'command': 'deleteSnapshot', 'id': helpers.get('SnapshotId')} response = requester.make_request_async(args) return response
def _authenticate_security_group_request(rule_type): args = _parse_security_group_request() if rule_type == "egress": args["command"] = "authorizeSecurityGroupEgress" elif rule_type == "ingress": args["command"] = "authorizeSecurityGroupIngress" response = requester.make_request_async(args) return response
def _stop_instance_request(instance_id): """ Request to stop an instance. @param instance_id: Id of instance to stop. @return: Response. """ args = {'command': 'stopVirtualMachine', 'id': instance_id} response = requester.make_request_async(args) response = response['virtualmachine'] return response
def _authenticate_security_group_request(rule_type): args = _parse_security_group_request() if rule_type == 'egress': args['command'] = 'authorizeSecurityGroupEgress' elif rule_type == 'ingress': args['command'] = 'authorizeSecurityGroupIngress' response = requester.make_request_async(args) return response
def _delete_vpc_request(): """ Request to delete a vpc. @return: Response. """ args = {'command': 'deleteVPC', 'id': helpers.get('VpcId')} response = requester.make_request_async(args) return response
def _reboot_instance_request(instance_id): """ Request to reboot an instance. @param instance_id: Id of instance to be rebooted. @return: Response. """ args = {'command': 'rebootVirtualMachine', 'id': instance_id} response = requester.make_request_async(args) response = response['virtualmachine'] return response
def _terminate_instance_request(instance_id): """ Request to terminate an instance. @param instance_id: Id of instance to terminate. @return: Response. """ args = {'command': 'destroyVirtualMachine', 'id': instance_id} response = requester.make_request_async(args) response = response['virtualmachine'] return response
def _attach_volume_request(): args = {} volume_id = helpers.get("VolumeId") instance_id = helpers.get("InstanceId") device = helpers.get("Device") args["id"] = volume_id args["command"] = "attachVolume" args["virtualmachineid"] = instance_id args["device"] = device response = requester.make_request_async(args) return response
def _revoke_security_group_request(rule_type): args = {} rules = _parse_security_group_request() if rule_type == "ingress": args["command"] = "revokeSecurityGroupIngress" args["id"] = _find_rule(rules, "ingressrule") elif rule_type == "egress": args["command"] = "revokeSecurityGroupEgress" args["id"] = _find_rule(rules, "egressrule") response = requester.make_request_async(args) return response
def _revoke_security_group_request(rule_type): args = {} rules = _parse_security_group_request() if rule_type == 'ingress': args['command'] = 'revokeSecurityGroupIngress' args['id'] = _find_rule(rules, 'ingressrule') elif rule_type == 'egress': args['command'] = 'revokeSecurityGroupEgress' args['id'] = _find_rule(rules, 'egressrule') response = requester.make_request_async(args) return response
def _attach_volume_request(): args = {} volume_id = helpers.get('VolumeId') instance_id = helpers.get('InstanceId') device = helpers.get('Device') args['id'] = volume_id args['command'] = 'attachVolume' args['virtualmachineid'] = instance_id args['device'] = device response = requester.make_request_async(args) return response
def _detach_volume_request(): args = {} volume_id = helpers.get("VolumeId") if helpers.contains_parameter("InstanceId"): args["virtualmachineid"] = helpers.get("InstanceId") if helpers.contains_parameter("Device"): args["deviceid"] = helpers.get("Device") args["id"] = volume_id args["command"] = "detachVolume" response = requester.make_request_async(args) return response
def _detach_volume_request(): args = {} volume_id = helpers.get('VolumeId') if helpers.contains_parameter('InstanceId'): args['virtualmachineid'] = helpers.get('InstanceId') if helpers.contains_parameter('Device'): args['deviceid'] = helpers.get('Device') args['id'] = volume_id args['command'] = 'detachVolume' response = requester.make_request_async(args) return response
def _authenticate_security_group_request(rule_type): """ Request to add an egress rule to a security group. @param rule_type: The type of rule to add. @return: Response. """ args = _parse_security_group_request() if rule_type == 'egress': args['command'] = 'authorizeSecurityGroupEgress' elif rule_type == 'ingress': args['command'] = 'authorizeSecurityGroupIngress' response = requester.make_request_async(args) return response
def _attach_volume_request(): """ Request to attach a volume. @return: Response. """ args = {} volume_id = helpers.get('VolumeId') instance_id = helpers.get('InstanceId') device = helpers.get('Device') args['id'] = volume_id args['command'] = 'attachVolume' args['virtualmachineid'] = instance_id args['device'] = device response = requester.make_request_async(args) return response
def _detach_volume_request(): """ Request to detach a volume. @return: Response. """ args = {} volume_id = helpers.get('VolumeId') if helpers.contains_parameter('InstanceId'): args['virtualmachineid'] = helpers.get('InstanceId') if helpers.contains_parameter('Device'): args['deviceid'] = helpers.get('Device') args['id'] = volume_id args['command'] = 'detachVolume' response = requester.make_request_async(args) return response
def _revoke_security_group_request(rule_type): """ Request to remove rule from security group @param rule_type: The type of rule to remove. @return: Response. """ args = {} rules = _parse_security_group_request() if rule_type == 'ingress': args['command'] = 'revokeSecurityGroupIngress' args['id'] = _find_rule(rules, 'ingressrule') elif rule_type == 'egress': args['command'] = 'revokeSecurityGroupEgress' args['id'] = _find_rule(rules, 'egressrule') response = requester.make_request_async(args) return response
def _create_volume_request(): args = {} if helpers.contains_parameter("SnapshotId"): args["snapshotid"] = helpers.get("SnapshotId") else: args["size"] = helpers.get("Size") args["diskofferingid"] = disk_offerings.get_disk_offering( current_app.config["CLOUDSTACK_CUSTOM_DISK_OFFERING"] )["id"] zone_name = helpers.get("AvailabilityZone") zone_id = zones.get_zone(zone_name)["id"] args["zoneid"] = zone_id args["command"] = "createVolume" args["name"] = uuid.uuid4() response = requester.make_request_async(args) return response
def _run_instance_request(): """ Request to bring up an instance. @return: Response. """ args = {} if helpers.contains_parameter('Placement.AvailabilityZone'): args['zoneid'] = zones.get_zone( helpers.get('Placement.AvailabilityZone') ) else: args['zoneid'] = zones.get_zone( current_app.config['CLOUDSTACK_DEFAULT_ZONE'] )['id'] if helpers.get('BlockDeviceMapping.1.Ebs.VolumeType') is not None: disk_type = helpers.get('BlockDeviceMapping.1.Ebs.VolumeType') if disk_type == 'gp2': args['diskofferingid'] = disk_offerings.get_disk_offering( current_app.config['CLOUDSTACK_CUSTOM_DISK_OFFERING'] )['id'] if helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize') is None: errors.invalid_request("VolumeSize not found in BlockDeviceMapping") else: args['size'] = helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize') if helpers.get('InstanceType') is None: instance_type = 'm1.small' else: instance_type = helpers.get('InstanceType') if instance_type in current_app.config['INSTANCE_TYPE_MAP']: instance_type = current_app.config[ 'INSTANCE_TYPE_MAP'][instance_type] else: instance_type = instance_type args['serviceofferingid'] = \ service_offerings.get_service_offering(instance_type)['id'] args['templateid'] = helpers.get('ImageId') if helpers.contains_parameter('KeyName'): args['keypair'] = helpers.get('KeyName') if helpers.contains_parameter('UserData'): args['userdata'] = helpers.get('UserData') if helpers.contains_parameter_with_keyword('SecurityGroupId.'): keys = helpers.get_request_parameter_keys('SecurityGroupId.') securitygroupids = [] for key in keys: securitygroupids.append(helpers.get(key)) args['securitygroupids'] = ",".join(securitygroupids) if helpers.contains_parameter_with_keyword('SecurityGroup.'): keys = helpers.get_request_parameter_keys('SecurityGroup.') securitygroupnames = [] for key in keys: securitygroupnames.append(helpers.get(key)) args['securitygroupnames'] = ",".join(securitygroupnames) args['command'] = 'deployVirtualMachine' response = requester.make_request_async(args) return response
def _reboot_instance_request(instance_id): args = {'command': 'rebootVirtualMachine', 'id': instance_id} response = requester.make_request_async(args) response = response['virtualmachine'] return response
def _run_instance_request(): """ Request to bring up an instance. @return: Response. """ args = {} if helpers.contains_parameter('Placement.AvailabilityZone'): args['zoneid'] = zones.get_zone( helpers.get('Placement.AvailabilityZone')) else: args['zoneid'] = zones.get_zone( current_app.config['CLOUDSTACK_DEFAULT_ZONE'])['id'] if helpers.get('BlockDeviceMapping.1.Ebs.VolumeType') is not None: disk_type = helpers.get('BlockDeviceMapping.1.Ebs.VolumeType') if disk_type == 'gp2': args['diskofferingid'] = disk_offerings.get_disk_offering( current_app.config['CLOUDSTACK_CUSTOM_DISK_OFFERING'])['id'] if helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize') is None: errors.invalid_request( "VolumeSize not found in BlockDeviceMapping") else: args['size'] = helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize') if helpers.get('InstanceType') is None: instance_type = 'm1.small' else: instance_type = helpers.get('InstanceType') if instance_type in current_app.config['INSTANCE_TYPE_MAP']: instance_type = current_app.config['INSTANCE_TYPE_MAP'][instance_type] else: instance_type = instance_type args['serviceofferingid'] = \ service_offerings.get_service_offering(instance_type)['id'] args['templateid'] = helpers.get('ImageId') if helpers.contains_parameter('KeyName'): args['keypair'] = helpers.get('KeyName') if helpers.contains_parameter('UserData'): args['userdata'] = helpers.get('UserData') if helpers.contains_parameter_with_keyword('SecurityGroupId.'): keys = helpers.get_request_parameter_keys('SecurityGroupId.') securitygroupids = [] for key in keys: securitygroupids.append(helpers.get(key)) args['securitygroupids'] = ",".join(securitygroupids) if helpers.contains_parameter_with_keyword('SecurityGroup.'): keys = helpers.get_request_parameter_keys('SecurityGroup.') securitygroupnames = [] for key in keys: securitygroupnames.append(helpers.get(key)) args['securitygroupnames'] = ",".join(securitygroupnames) if helpers.get('SubnetId') is not None: args['networkids'] = helpers.get('SubnetId') args['command'] = 'deployVirtualMachine' response = requester.make_request_async(args) return response