Permalink
Switch branches/tags
TrueNAS-9.10.2-U5 TrueNAS-9.10.2-U2 TrueNAS-9.10-RELEASE TrueNAS-9.3-STABLE-201511030016 TN-11.1-U6.1 TN-11.1-U6 TN-11.1-U5.1 TN-11.0-u2.1 TN-11.0-U6 TN-11.0-U5 TN-11.0-U4 TN-11.0-U2.2 TN-11.0-U2 TN-9.10.2-U4 TN-9.10.2-U3 TN-9.10.1-U2 TN-9.3-STABLE-201602032047 TN-9.3-STABLE-201512161903 TN-9.3-STABLE-201511180607 TN-9.3-STABLE-201510080155 TN-9.3-STABLE-201506300138 TN-9.3-STABLE-201505130613 TN-9.3-STABLE-201504162155 TN-9.3-STABLE-201503270306 TN-9.3-RELEASE TN-9.3-BETA TN-9.2.1.11-RELEASE-p2 TN-9.2.1.10 TN-9.2.1.9-RELEASE TN-9.2.1.8-RELEASE TN-9.2.1.6-RELEASE LAST-WORKING-COPY FreeNAS-9.10.2-U5 FreeNAS-9.10-STABLE-201603252134 FN-11.2-RC1 FN-11.2-BETA3 FN-11.2-BETA2 FN-11.2-BETA1 FN-11.1-U6 FN-10.2-ALPHA FN-9.10.2 FN-9.10-STABLE-201604261518 FN-9.10-STABLE-201604181743 FN-9.10-RELEASE 11.1-U5 11.1-U4 11.1-U3 11.1-U2 11.1-U1 11.1-RELEASE 11.1-RC2 11.1-RC1 11.1-BETA1 11.0-U4 11.0-U3 11.0-U2 11.0-U1 11.0-RELEASE 11.0-RC4 11.0-RC3 11.0-RC2 11.0-RC 9.10.2-U3 9.10.1 9.10.1-U4 9.10.1-U3 9.10.1-U2.1 9.10-STABLE-201606072003 9.10-STABLE-201605240427 9.10-STABLE-201603252134 9.3.1-STABLE-201604120241 9.3.1-STABLE-201511280648 9.3.1-STABLE-201511040813 9.3.1-STABLE-201511020249 9.3.1-STABLE-201509282017 9.3.1-STABLE-201509160044 9.3.1-STABLE-201508250051 9.3-STABLE-201605170422 9.3-STABLE-201604202233 9.3-STABLE-201604112122 9.3-STABLE-201604041648 9.3-STABLE-201602031011 9.3-STABLE-201602030118 9.3-STABLE-201602020212 9.3-STABLE-201601181840 9.3-STABLE-201512121950 9.3-STABLE-201508250051 9.3-STABLE-201506292332 9.3-STABLE-201506232120 9.3-STABLE-201506222346 9.3-STABLE-201506162331 9.3-STABLE-201506042008 9.3-STABLE-201506040752 9.3-STABLE-201505130355 9.3-STABLE-201505100553 9.3-STABLE-201505040117 9.3-STABLE-201505010007 9.3-STABLE-201504292314 9.3-STABLE-201504152200 9.3-STABLE-201504100216
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
85 lines (66 sloc) 2.19 KB
import argparse
import json
import sys
import requests
class Startup(object):
def __init__(self, hostname, user, secret):
self._hostname = hostname
self._user = user
self._secret = secret
self._ep = 'http://%s/api/v1.0' % hostname
def request(self, resource, method='GET', data=None):
if data is None:
data = ''
r = requests.request(
method,
'%s/%s/' % (self._ep, resource),
data=json.dumps(data),
headers={'Content-Type': "application/json"},
auth=(self._user, self._secret),
)
if r.ok:
try:
return r.json()
except:
return r.text
raise ValueError(r)
def _get_disks(self):
disks = self.request('storage/disk')
return [disk['disk_name'] for disk in disks]
def create_pool(self):
disks = self._get_disks()
self.request('storage/volume', method='POST', data={
'volume_name': 'tank',
'layout': [
{'vdevtype': 'stripe', 'disks': disks},
],
})
def create_dataset(self):
self.request('storage/volume/tank/datasets', method='POST', data={
'name': 'MyShare',
})
def create_cifs_share(self):
self.request('sharing/cifs', method='POST', data={
'cifs_name': 'My Test Share',
'cifs_path': '/mnt/tank/MyShare',
'cifs_guestonly': True
})
def service_start(self, name):
self.request('services/services/%s' % name, method='PUT', data={
'srv_enable': True,
})
def run(self):
self.create_pool()
self.create_dataset()
self.create_cifs_share()
self.service_start('cifs')
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-H', '--hostname', required=True, type=str)
parser.add_argument('-u', '--user', required=True, type=str)
parser.add_argument('-p', '--passwd', required=True, type=str)
args = parser.parse_args(sys.argv[1:])
startup = Startup(args.hostname, args.user, args.passwd)
startup.run()
if __name__ == '__main__':
main()