forked from sylabs/singularity
/
client.go
108 lines (97 loc) · 2.85 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2018, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package client
import (
"net/rpc"
"os"
args "github.com/sylabs/singularity/internal/pkg/runtime/engines/singularity/rpc"
"github.com/sylabs/singularity/pkg/util/loop"
)
// RPC holds the state necessary for remote procedure calls.
type RPC struct {
Client *rpc.Client
Name string
}
// Mount calls tme mount RPC using the supplied arguments.
func (t *RPC) Mount(source string, target string, filesystem string, flags uintptr, data string) (int, error) {
arguments := &args.MountArgs{
Source: source,
Target: target,
Filesystem: filesystem,
Mountflags: flags,
Data: data,
}
var reply int
err := t.Client.Call(t.Name+".Mount", arguments, &reply)
return reply, err
}
// Mkdir calls the mkdir RPC using the supplied arguments.
func (t *RPC) Mkdir(path string, perm os.FileMode) (int, error) {
arguments := &args.MkdirArgs{
Path: path,
Perm: perm,
}
var reply int
err := t.Client.Call(t.Name+".Mkdir", arguments, &reply)
return reply, err
}
// Chroot calls the chroot RPC using the supplied arguments.
func (t *RPC) Chroot(root string, method string) (int, error) {
arguments := &args.ChrootArgs{
Root: root,
Method: method,
}
var reply int
err := t.Client.Call(t.Name+".Chroot", arguments, &reply)
return reply, err
}
// LoopDevice calls the loop device RPC using the supplied arguments.
func (t *RPC) LoopDevice(image string, mode int, info loop.Info64, maxDevices int, shared bool) (int, error) {
arguments := &args.LoopArgs{
Image: image,
Mode: mode,
Info: info,
MaxDevices: maxDevices,
Shared: shared,
}
var reply int
err := t.Client.Call(t.Name+".LoopDevice", arguments, &reply)
return reply, err
}
// SetHostname calls the sethostname RPC using the supplied arguments.
func (t *RPC) SetHostname(hostname string) (int, error) {
arguments := &args.HostnameArgs{
Hostname: hostname,
}
var reply int
err := t.Client.Call(t.Name+".SetHostname", arguments, &reply)
return reply, err
}
// HasNamespace calls the HasNamespace RPC using the supplied arguments.
func (t *RPC) HasNamespace(pid int, nstype string) (bool, error) {
arguments := &args.HasNamespaceArgs{
Pid: pid,
NsType: nstype,
}
var reply int
err := t.Client.Call(t.Name+".HasNamespace", arguments, &reply)
if err != nil {
return false, err
}
if reply == 1 {
return true, err
}
return false, err
}
// SetFsID calls the setfsid RPC using the supplied arguments.
func (t *RPC) SetFsID(uid int, gid int) (int, error) {
arguments := &args.SetFsIDArgs{
UID: uid,
GID: gid,
}
var reply int
err := t.Client.Call(t.Name+".SetFsID", arguments, &reply)
return reply, err
}