Skip to content

Commit

Permalink
* remove trailing spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Savin committed Feb 14, 2012
1 parent a2654da commit 158d12e
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion nova_dns/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

__version__ = "0.0.4"

try:
try:
from nova import flags
FLAGS = flags.FLAGS

Expand Down
46 changes: 23 additions & 23 deletions nova_dns/dns.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Nova DNS
# Nova DNS
# Copyright (C) GridDynamics Openstack Core Team, GridDynamics
#
# This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -31,10 +31,10 @@
import routes
import routes.middleware

from nova import wsgi
from nova import wsgi
from nova import service
#from nova_dns import keystone_utils
from nova_dns import __version__
from nova_dns import __version__
from nova_dns.dnsmanager import DNSRecord, DNSSOARecord

LOG = logging.getLogger("nova_dns.dns")
Expand All @@ -45,14 +45,14 @@
"File name for the paste.deploy config for nova-dns api")
flags.DEFINE_string("dns_listen", "0.0.0.0",
"IP address for DNS API to listen")
flags.DEFINE_integer("dns_listen_port", 15353,
flags.DEFINE_integer("dns_listen_port", 15353,
"DNS API port")

class Service(service.WSGIService):
"""
"""
def __init__(self):
service.WSGIService.__init__(self, name="dns",
service.WSGIService.__init__(self, name="dns",
loader=wsgi.Loader(config_path=FLAGS.dns_api_paste_config))


Expand All @@ -69,7 +69,7 @@ def __call__(self, req):
version = json.dumps({
"version": __version__,
"application": "nova-dns",
"links": [{ "href": "http://%s:%s/zones" %
"links": [{ "href": "http://%s:%s/zones" %
(req.environ["SERVER_NAME"], req.environ["SERVER_PORT"]),
"rel": "self"}]
})
Expand Down Expand Up @@ -118,25 +118,25 @@ def __call__(self, req):
elif action=="record_add":
rec=DNSRecord(
name="" if args['name']=='@' else args['name'],
content=args['content'], type=args['type'],
content=args['content'], type=args['type'],
ttl=req.GET.get('ttl', None),
priority=req.GET.get('priority', None))
result=self.manager.get(args['zonename']).add(rec)
result=self.manager.get(args['zonename']).add(rec)
elif action=="record_del":
name="" if args['name']=='@' else args['name']
result=self.manager.get(args['zonename']).delete(name, args['type'])
elif action=="record_edit":
name="" if args['name']=='@' else args['name']
result=self.manager.get(args['zonename']).set(
name=name,
name=name,
type=args['type'],
content=req.GET.get('content', None),
ttl=req.GET.get('ttl', None),
priority=req.GET.get('priority', None)
)
else:
raise Exception("Incorrect action: "+action)
return webob.Response(json.dumps({"result":result, "error":None}),
return webob.Response(json.dumps({"result":result, "error":None}),
content_type='application/json')
except Exception as e:
return webob.Response(json.dumps({"result":None, "error":str(e)}),
Expand All @@ -149,51 +149,51 @@ class App(wsgi.Router):

def __init__(self):
"""
GET /
GET /
return version info and links
GET /zone
return list of all zones
return list of all zones
GET /zone/name
return SSON for SOA if zone exists
PUT /zone/name[?soa_params]
create new zone. if no params for SOA provided, backend
_has_to_ use reasonable defaults. Return 'ok' on success
DELETE /zone/name[?force]
drop zone and all records in zone.
drop zone and all records in zone.
if "force" param provided, will delete all sub-zones
if not - will refuse to delete if there are any sub-zone for
this zone
this zone
return "ok" on success
GET /record/zonename[?name=&type=]
return JSON (array of objects). Will return 'err' if zone or
or (name, type) not exists
PUT /record/zonename/name/type/content[?ttl&priority]
add record. return 'ok' on success. set name to '@' if empty
POST /record/zonename/name/type?[params]
POST /record/zonename/name/type?[params]
return 'ok' on success, 'err' if zonename or (name, type) not exists
DELETE /record/zonename/name/type
"""
#FIXME rewrite dict(controller=Controller(), action="...") to
#FIXME rewrite dict(controller=Controller(), action="...") to
#controller=Controller
#....controller=conntroller.index
map = routes.Mapper()
map.connect(None, "/zone/",
map.connect(None, "/zone/",
controller=Controller(), action="index")
map.connect(None, "/zone/{zonename}", conditions=dict(method=["GET"]),
map.connect(None, "/zone/{zonename}", conditions=dict(method=["GET"]),
controller=Controller(), action="zone_get")
map.connect(None, "/zone/{zonename}", conditions=dict(method=["PUT"]),
map.connect(None, "/zone/{zonename}", conditions=dict(method=["PUT"]),
controller=Controller(), action="zone_add")
map.connect(None, "/zone/{zonename}", conditions=dict(method=["DELETE"]),
map.connect(None, "/zone/{zonename}", conditions=dict(method=["DELETE"]),
controller=Controller(), action="zone_del")
map.connect(None, "/record/{zonename}", conditions=dict(method=["GET"]),
map.connect(None, "/record/{zonename}", conditions=dict(method=["GET"]),
controller=Controller(), action="list")
map.connect(None, "/record/{zonename}/{name}/{type}/{content}",
conditions=dict(method=["PUT"]), controller=Controller(),
action="record_add")
map.connect(None, "/record/{zonename}/{name}/{type}",
map.connect(None, "/record/{zonename}/{name}/{type}",
conditions=dict(method=["POST"]), controller=Controller(),
action="record_edit")
map.connect(None, "/record/{zonename}/{name}/{type}",
map.connect(None, "/record/{zonename}/{name}/{type}",
conditions=dict(method=["DELETE"]), controller=Controller(),
action="record_del")
super(App, self).__init__(map)
Expand Down
10 changes: 5 additions & 5 deletions nova_dns/dnsmanager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python

import re
import re

from nova import flags
from nova import log as logging
Expand All @@ -23,8 +23,8 @@
"time between retries if the slave fails to contact the master")
flags.DEFINE_integer("dns_soa_expire", 604800,
"Indicates when the zone data is no longer authoritative")
record_types=set(('A', 'AAAA', 'MX', 'SOA', 'CNAME', 'PTR', 'SPF', 'SRV', 'TXT', 'NS',
'AFSDB', 'CERT', 'DNSKEY', 'DS', 'HINFO', 'KEY', 'LOC', 'NAPTR', 'RP', 'RRSIG',
record_types=set(('A', 'AAAA', 'MX', 'SOA', 'CNAME', 'PTR', 'SPF', 'SRV', 'TXT', 'NS',
'AFSDB', 'CERT', 'DNSKEY', 'DS', 'HINFO', 'KEY', 'LOC', 'NAPTR', 'RP', 'RRSIG',
'SSHFP'))


Expand All @@ -48,8 +48,8 @@ def drop(self, zone_name, force=False):

@abstractmethod
def get(self, zone_name):
""" return DNSZone object for zone_name.
If zone not exist, raise exception
""" return DNSZone object for zone_name.
If zone not exist, raise exception
"""
pass

Expand Down
14 changes: 7 additions & 7 deletions nova_dns/dnsmanager/powerdns/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python

import time

Expand All @@ -15,7 +15,7 @@
class Manager(DNSManager):
def __init__(self):
self.session=get_session()
def list(self):
def list(self):
return [name[0] for name in self.session.query(Domains.name).all()]
def add(self, zone_name, soa):
if zone_name in self.list():
Expand All @@ -27,7 +27,7 @@ def add(self, zone_name, soa):
soa=DNSSOARecord(**soa)
# PowerDNS-specific. TODO make this more pytonish - with objects
# and bells
soa.content=" ".join((str(f) for f in (soa.primary, soa.hostmaster, soa.serial,
soa.content=" ".join((str(f) for f in (soa.primary, soa.hostmaster, soa.serial,
soa.refresh, soa.retry, soa.expire, soa.ttl)))
PowerDNSZone(zone_name).add(soa)
return "ok"
Expand Down Expand Up @@ -77,7 +77,7 @@ def add(self, v):
#FIXME check uniq in model - duplicating (name, type)
self.session.add(rec)
self.session.flush()
LOG.info("Record (%s, %s, %s) in zone %s was added" %
LOG.info("Record (%s, %s, %s) in zone %s was added" %
(rec.name, rec.type, rec.content, self.zone_name))
self._update_serial(rec.change_date)
return "ok"
Expand Down Expand Up @@ -106,22 +106,22 @@ def set(self, name, type, content="", priority="", ttl=""):
self.session.merge(rec)
self.session.flush()
self._update_serial(rec.change_date)
LOG.info("Record (%s, %s) in zone %s was changed" %
LOG.info("Record (%s, %s) in zone %s was changed" %
(rec.name, rec.type, self.zone_name))
return "ok"
def delete(self, name, type=None):
if self._q(name, type).delete():
return "ok"
else:
raise Exception("No records was deleted")
raise Exception("No records was deleted")
def _update_serial(self, change_date):
#TODO change to get_soa
soa=self._q('', 'SOA').first()
v=soa.content.split()
#TODO change this to ordinar set()
v[2]=change_date
content=" ".join((str(f) for f in v))
#FIXME should change_date for SOA be changed here ?
#FIXME should change_date for SOA be changed here ?
soa.update({"content":content, "change_date":change_date})
self.session.flush()
def _q(self, name, type):
Expand Down
2 changes: 1 addition & 1 deletion nova_dns/dnsmanager/powerdns/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

FLAGS = flags.FLAGS
flags.DEFINE_string('dns_sql_connection',
"mysql://pdns:pdns@localhost/pdns",
"mysql://pdns:pdns@localhost/pdns",
# 'sqlite:////var/lib/nova/nova_dns.sqlite',
'connection string for powerdns sql database')

Expand Down
12 changes: 6 additions & 6 deletions nova_dns/listener/dumb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python

"""Dumb listener - only log events """

Expand All @@ -7,7 +7,7 @@

LOG = logging.getLogger("nova_dns.listener.dumb")

methods=set(("run_instance", "terminate_instance", "stop_instance",
methods=set(("run_instance", "terminate_instance", "stop_instance",
"start_instance", "pause_instance", "unpause_instance",
"resume_instance", "suspend_instance"))

Expand All @@ -19,9 +19,9 @@ def event(self, e):
return
contextproject_id = e["_context_project_id"]
id = e["args"]["instance_id"]
try:
try:
name = e["args"]["request_spec"]["instance_properties"]["display_name"]
except:
name = "<unknown>"
LOG.warning("Method %s instance_id '%s' project_id '%s' instance name '%s'" %
except:
name = "<unknown>"
LOG.warning("Method %s instance_id '%s' project_id '%s' instance name '%s'" %
(method, str(id), str(contextproject_id), name))
10 changes: 5 additions & 5 deletions nova_dns/listener/simple/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python

"""Simple listener:
- doesn't sync state with dns after restart
Expand Down Expand Up @@ -34,7 +34,7 @@ def __init__(self):
self.conn=sqlalchemy.engine.create_engine(FLAGS.sql_connection).connect()
dnsmanager_class=utils.import_class(FLAGS.dns_manager);
self.dnsmanager=dnsmanager_class()

def event(self, e):
method = e.get("method", "<unknown>")
id = e["args"].get("instance_id", None)
Expand Down Expand Up @@ -63,11 +63,11 @@ def event(self, e):
def _pollip(self):
while True:
time.sleep(SLEEP)
if not len(self.pending):
if not len(self.pending):
LOG.debug('empty pending queue - continue')
continue
for r in self.conn.execute("""
select i.hostname, i.id, i.project_id, f.address
select i.hostname, i.id, i.project_id, f.address
from instances i, fixed_ips f
where i.id=f.instance_id"""):
LOG.info("Instance %s hostname %s adding ip %s" %
Expand Down Expand Up @@ -96,7 +96,7 @@ def _pollip(self):
LOG.warn(str(e))
except:
pass
try:
try:
self.dnsmanager.get(zonename).add(
DNSRecord(name=r.hostname, type='A', content=r.address))
except ValueError as e:
Expand Down

0 comments on commit 158d12e

Please sign in to comment.