github.com/Cloud-Foundations/Dominator@v0.3.4/imageunpacker/client/misc.go (about)

     1  package client
     2  
     3  import (
     4  	"io"
     5  	"path"
     6  
     7  	"github.com/Cloud-Foundations/Dominator/lib/srpc"
     8  	proto "github.com/Cloud-Foundations/Dominator/proto/imageunpacker"
     9  )
    10  
    11  func associateStreamWithDevice(srpcClient *srpc.Client, streamName string,
    12  	deviceId string) error {
    13  	request := proto.AssociateStreamWithDeviceRequest{
    14  		StreamName: streamName,
    15  		DeviceId:   deviceId,
    16  	}
    17  	var reply proto.AssociateStreamWithDeviceResponse
    18  	return srpcClient.RequestReply("ImageUnpacker.AssociateStreamWithDevice",
    19  		request, &reply)
    20  }
    21  
    22  func claimDevice(srpcClient *srpc.Client, deviceId, deviceName string) error {
    23  	request := proto.ClaimDeviceRequest{
    24  		DeviceId:   deviceId,
    25  		DeviceName: deviceName,
    26  	}
    27  	var reply proto.ClaimDeviceResponse
    28  	return srpcClient.RequestReply("ImageUnpacker.ClaimDevice", request, &reply)
    29  }
    30  
    31  func exportImage(srpcClient *srpc.Client, streamName,
    32  	exportType, exportDestination string) error {
    33  	request := proto.ExportImageRequest{
    34  		StreamName:  path.Clean(streamName),
    35  		Type:        exportType,
    36  		Destination: exportDestination,
    37  	}
    38  	var reply proto.ExportImageResponse
    39  	return srpcClient.RequestReply("ImageUnpacker.ExportImage", request, &reply)
    40  }
    41  
    42  func forgetStream(srpcClient *srpc.Client, streamName string) error {
    43  	request := proto.ForgetStreamRequest{StreamName: streamName}
    44  	var reply proto.ForgetStreamResponse
    45  	return srpcClient.RequestReply("ImageUnpacker.ForgetStream",
    46  		request, &reply)
    47  }
    48  
    49  func getRaw(srpcClient *srpc.Client, streamName string) (
    50  	io.ReadCloser, uint64, error) {
    51  	conn, err := srpcClient.Call("ImageUnpacker.GetRaw")
    52  	if err != nil {
    53  		return nil, 0, err
    54  	}
    55  	doClose := true
    56  	defer func() {
    57  		if doClose {
    58  			conn.Close()
    59  		}
    60  	}()
    61  	request := proto.GetRawRequest{StreamName: path.Clean(streamName)}
    62  	if err := conn.Encode(request); err != nil {
    63  		return nil, 0, err
    64  	}
    65  	if err := conn.Flush(); err != nil {
    66  		return nil, 0, err
    67  	}
    68  	var reply proto.GetRawResponse
    69  	if err := conn.Decode(&reply); err != nil {
    70  		return nil, 0, err
    71  	}
    72  	doClose = false
    73  	return conn, reply.Size, nil
    74  }
    75  
    76  func getStatus(srpcClient *srpc.Client) (proto.GetStatusResponse, error) {
    77  	var request proto.GetStatusRequest
    78  	var reply proto.GetStatusResponse
    79  	err := srpcClient.RequestReply("ImageUnpacker.GetStatus", request, &reply)
    80  	return reply, err
    81  }
    82  
    83  func prepareForCapture(srpcClient *srpc.Client, streamName string) error {
    84  	request := proto.PrepareForCaptureRequest{StreamName: streamName}
    85  	var reply proto.PrepareForCaptureResponse
    86  	return srpcClient.RequestReply("ImageUnpacker.PrepareForCapture", request,
    87  		&reply)
    88  }
    89  
    90  func prepareForCopy(srpcClient *srpc.Client, streamName string) error {
    91  	request := proto.PrepareForCopyRequest{StreamName: streamName}
    92  	var reply proto.PrepareForCopyResponse
    93  	return srpcClient.RequestReply("ImageUnpacker.PrepareForCopy", request,
    94  		&reply)
    95  }
    96  
    97  func prepareForUnpack(srpcClient *srpc.Client, streamName string,
    98  	skipIfPrepared bool, doNotWaitForResult bool) error {
    99  	request := proto.PrepareForUnpackRequest{
   100  		DoNotWaitForResult: doNotWaitForResult,
   101  		SkipIfPrepared:     skipIfPrepared,
   102  		StreamName:         streamName,
   103  	}
   104  	var reply proto.PrepareForUnpackResponse
   105  	return srpcClient.RequestReply("ImageUnpacker.PrepareForUnpack", request,
   106  		&reply)
   107  }
   108  
   109  func removeDevice(srpcClient *srpc.Client, deviceId string) error {
   110  	request := proto.RemoveDeviceRequest{DeviceId: deviceId}
   111  	var reply proto.RemoveDeviceResponse
   112  	return srpcClient.RequestReply("ImageUnpacker.RemoveDevice", request,
   113  		&reply)
   114  }
   115  
   116  func unpackImage(srpcClient *srpc.Client, streamName,
   117  	imageLeafName string) error {
   118  	request := proto.UnpackImageRequest{
   119  		StreamName:    path.Clean(streamName),
   120  		ImageLeafName: path.Clean(imageLeafName),
   121  	}
   122  	var reply proto.UnpackImageResponse
   123  	return srpcClient.RequestReply("ImageUnpacker.UnpackImage", request, &reply)
   124  }