summaryrefslogtreecommitdiff
path: root/novaclient/v2/floating_ip_dns.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/floating_ip_dns.py')
-rw-r--r--novaclient/v2/floating_ip_dns.py121
1 files changed, 121 insertions, 0 deletions
diff --git a/novaclient/v2/floating_ip_dns.py b/novaclient/v2/floating_ip_dns.py
new file mode 100644
index 0000000..41df0f6
--- /dev/null
+++ b/novaclient/v2/floating_ip_dns.py
@@ -0,0 +1,121 @@
1# Copyright 2011 Andrew Bogott for The Wikimedia Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from six.moves.urllib import parse
17
18from novaclient import base
19
20
21def _quote_domain(domain):
22 """Special quoting rule for placing domain names on a url line.
23
24 Domain names tend to have .'s in them. Urllib doesn't quote dots,
25 but Routes tends to choke on them, so we need an extra level of
26 by-hand quoting here.
27 """
28 return parse.quote(domain.replace('.', '%2E'))
29
30
31class FloatingIPDNSDomain(base.Resource):
32 def delete(self):
33 self.manager.delete(self.domain)
34
35 def create(self):
36 if self.scope == 'public':
37 self.manager.create_public(self.domain, self.project)
38 else:
39 self.manager.create_private(self.domain, self.availability_zone)
40
41 def get(self):
42 entries = self.manager.domains()
43 for entry in entries:
44 if entry.get('domain') == self.domain:
45 return entry
46
47 return None
48
49
50class FloatingIPDNSDomainManager(base.Manager):
51 resource_class = FloatingIPDNSDomain
52
53 def domains(self):
54 """Return the list of available dns domains."""
55 return self._list("/os-floating-ip-dns", "domain_entries")
56
57 def create_private(self, fqdomain, availability_zone):
58 """Add or modify a private DNS domain."""
59 body = {'domain_entry': {'scope': 'private',
60 'availability_zone': availability_zone}}
61 return self._update('/os-floating-ip-dns/%s' % _quote_domain(fqdomain),
62 body,
63 'domain_entry')
64
65 def create_public(self, fqdomain, project):
66 """Add or modify a public DNS domain."""
67 body = {'domain_entry': {'scope': 'public', 'project': project}}
68
69 return self._update('/os-floating-ip-dns/%s' % _quote_domain(fqdomain),
70 body, 'domain_entry')
71
72 def delete(self, fqdomain):
73 """Delete the specified domain."""
74 self._delete("/os-floating-ip-dns/%s" % _quote_domain(fqdomain))
75
76
77class FloatingIPDNSEntry(base.Resource):
78 def delete(self):
79 self.manager.delete(self.name, self.domain)
80
81 def create(self):
82 self.manager.create(self.domain, self.name, self.ip, self.dns_type)
83
84 def get(self):
85 return self.manager.get(self.domain, self.name)
86
87
88class FloatingIPDNSEntryManager(base.Manager):
89 resource_class = FloatingIPDNSEntry
90
91 def get(self, domain, name):
92 """Return a list of entries for the given domain and IP or name."""
93 return self._get("/os-floating-ip-dns/%s/entries/%s" %
94 (_quote_domain(domain), name), "dns_entry")
95
96 def get_for_ip(self, domain, ip):
97 """Return a list of entries for the given domain and IP or name."""
98 qparams = {'ip': ip}
99 params = "?%s" % parse.urlencode(qparams)
100
101 return self._list("/os-floating-ip-dns/%s/entries%s" %
102 (_quote_domain(domain), params), "dns_entries")
103
104 def create(self, domain, name, ip, dns_type):
105 """Add a new DNS entry."""
106 body = {'dns_entry': {'ip': ip, 'dns_type': dns_type}}
107
108 return self._update("/os-floating-ip-dns/%s/entries/%s" %
109 (_quote_domain(domain), name), body, "dns_entry")
110
111 def modify_ip(self, domain, name, ip):
112 """Add a new DNS entry."""
113 body = {'dns_entry': {'ip': ip, 'dns_type': 'A'}}
114
115 return self._update("/os-floating-ip-dns/%s/entries/%s" %
116 (_quote_domain(domain), name), body, "dns_entry")
117
118 def delete(self, domain, name):
119 """Delete entry specified by name and domain."""
120 self._delete("/os-floating-ip-dns/%s/entries/%s" %
121 (_quote_domain(domain), name))