Skip to content

Commit

Permalink
Switch config file format to YAML
Browse files Browse the repository at this point in the history
Update README accordingly.

Signed-off-by: Andy Grover <agrover@redhat.com>
  • Loading branch information
Andy Grover committed Jun 18, 2012
1 parent f4104b6 commit c310e5a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,26 @@ targetd has these Python library dependencies:
* [python-rtslib](https://github.com/agrover/rtslib-fb) 2.1.fb14+ (must be fb*)
* [python-lvm](https://github.com/agrover/python-lvm) 1.2.2+
* [python-setproctitle](https://github.com/dvarrazzo/py-setproctitle)
* [PyYAML](http://pyyaml.org/)

All of these are available in Fedora Rawhide.

Installing the targetcli package is also highly recommended.

### Configuring targetd

A configuration file may be placed at `/etc/target/targetd.yaml`, and
is in [YAML](http://www.yaml.org/spec/1.2/spec.html) format. Here's
an example:

pool_name: test
user: "foo" # strings quoted, or not
password: bar
ssl: false
target_name: iqn.2003-01.org.example.mach1:1234

targetd defaults to using the "test" volume group, and username 'foo'
password 'bar' for the HTTP jsonrpc interface. Overrides to these
defaults may be placed in `/etc/target/targetd.json`:

{
# this is a comment. comments must be on their own line.
"pool_name" : "test",
"user" : "foo",
"password" : "bar",
"ssl" : false,
"target_name" : "iqn.2003-01.org.example.mach1:1234"
}
password 'bar' for the HTTP jsonrpc interface.

Then, run `sudo ./targetd.py`.

Expand Down
9 changes: 3 additions & 6 deletions targetd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from SocketServer import ThreadingMixIn
import socket
import yaml

setproctitle.setproctitle("targetd")

config_path = "/etc/target/targetd.json"
config_path = "/etc/target/targetd.yaml"

default_config = dict(
pool_name = "test",
Expand All @@ -43,11 +44,7 @@

config = {}
if os.path.isfile(config_path):
jsontxt=""
for f in open(config_path):
if not f.lstrip().startswith("#"):
jsontxt += f
config = json.loads(jsontxt)
config = yaml.load(open(config_path).read())

for key, value in default_config.iteritems():
if key not in config:
Expand Down

0 comments on commit c310e5a

Please sign in to comment.