def _parse_security_group_request(args=None): if args is None: args = {} helpers.require_atleast_one_parameter(['GroupName', 'GroupId']) if helpers.contains_parameter('GroupName'): args['securityGroupName'] = helpers.get('GroupName') args['name'] = helpers.get('GroupName') elif helpers.contains_parameter('GroupId'): args['securityGroupId'] = helpers.get('GroupId') args['id'] = helpers.get('GroupId') helpers.require_parameters(['IpProtocol']) args['protocol'] = helpers.get('IpProtocol') helpers.require_parameters(['FromPort', 'ToPort']) if args['protocol'] in ['icmp']: args['icmptype'] = helpers.get('FromPort') args['icmpcode'] = helpers.get('ToPort') else: args['startport'] = helpers.get('FromPort') args['endport'] = helpers.get('ToPort') if helpers.get('CidrIp') is None: args['cidrlist'] = '0.0.0.0/0' else: args['cidrlist'] = helpers.get('CidrIp') return args
def _parse_security_group_request(args=None): if args is None: args = {} helpers.require_atleast_one_parameter(["GroupName", "GroupId"]) if helpers.contains_parameter("GroupName"): args["securityGroupName"] = helpers.get("GroupName") args["name"] = helpers.get("GroupName") elif helpers.contains_parameter("GroupId"): args["securityGroupId"] = helpers.get("GroupId") args["id"] = helpers.get("GroupId") helpers.require_parameters(["IpProtocol"]) args["protocol"] = helpers.get("IpProtocol") helpers.require_parameters(["FromPort", "ToPort"]) if args["protocol"] in ["icmp"]: args["icmptype"] = helpers.get("FromPort") args["icmpcode"] = helpers.get("ToPort") else: args["startport"] = helpers.get("FromPort") args["endport"] = helpers.get("ToPort") if helpers.get("CidrIp") is None: args["cidrlist"] = "0.0.0.0/0" else: args["cidrlist"] = helpers.get("CidrIp") return args
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 _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 _delete_security_group_request(): args = {} helpers.require_atleast_one_parameter(["GroupName", "GroupId"]) if helpers.contains_parameter("GroupName"): args["name"] = helpers.get("GroupName") elif helpers.contains_parameter("GroupId"): args["id"] = helpers.get("GroupId") args["command"] = "deleteSecurityGroup" response = requester.make_request(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 _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 _delete_security_group_request(): args = {} helpers.require_atleast_one_parameter(['GroupName', 'GroupId']) if helpers.contains_parameter('GroupName'): args['name'] = helpers.get('GroupName') elif helpers.contains_parameter('GroupId'): args['id'] = helpers.get('GroupId') args['command'] = 'deleteSecurityGroup' response = requester.make_request(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.uuid1() response = requester.make_request_async(args) return response
def _delete_security_group_request(): """ Request to delete a security group. @return: Response. """ args = {} helpers.require_atleast_one_parameter(['GroupName', 'GroupId']) if helpers.contains_parameter('GroupName'): args['name'] = helpers.get('GroupName') elif helpers.contains_parameter('GroupId'): args['id'] = helpers.get('GroupId') args['command'] = 'deleteSecurityGroup' response = requester.make_request(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 _parse_security_group_request(args=None): """ Parse the request parameters into a Cloudstack request payload. @param args: Arguments to include in the request. @return: Request payload. """ if args is None: args = {} helpers.require_atleast_one_parameter(['GroupName', 'GroupId']) if helpers.contains_parameter('GroupName'): args['securityGroupName'] = helpers.get('GroupName') args['name'] = helpers.get('GroupName') elif helpers.contains_parameter('GroupId'): args['securityGroupId'] = helpers.get('GroupId') args['id'] = helpers.get('GroupId') helpers.require_parameters(['IpProtocol']) args['protocol'] = helpers.get('IpProtocol') helpers.require_parameters(['FromPort', 'ToPort']) if args['protocol'] in ['icmp']: args['icmptype'] = helpers.get('FromPort') args['icmpcode'] = helpers.get('ToPort') else: args['startport'] = helpers.get('FromPort') args['endport'] = helpers.get('ToPort') if helpers.get('CidrIp') is None: args['cidrlist'] = '0.0.0.0/0' else: args['cidrlist'] = helpers.get('CidrIp') return args
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) if helpers.get('SubnetId') is not None: args['networkids'] = helpers.get('SubnetId') args['command'] = 'deployVirtualMachine' 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