3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 from __future__ import print_function
16 from urlparse import urlparse
18 from cmframework.apis import cmerror
19 from cmframework.apis import cmstate
20 from dss.client import dss_client
21 from dss.api import dss_error
24 class CMDSSHandler(cmstate.CMState):
25 def __init__(self, **kw):
26 uridata = urlparse(kw['uri'])
28 self.client = dss_client.Client(socket)
30 def _domain_exists(self, domain):
31 return domain in self.get_domains()
33 def _name_exists_in_domain(self, domain, name):
34 return name in self.get_domain(domain)
36 def get(self, domain, name):
37 logging.debug('get called for %s %s', domain, name)
39 if self._domain_exists(domain):
41 domain_data = self.client.get_domain(domain)
42 return domain_data.get(name, None)
43 except dss_error.Error as ex:
44 raise cmerror.CMError(str(ex))
48 def get_domain(self, domain):
49 logging.debug('get_domain called for %s', domain)
51 if self._domain_exists(domain):
53 return self.client.get_domain(domain)
54 except dss_error.Error as ex:
55 raise cmerror.CMError(str(ex))
59 def set(self, domain, name, value):
60 logging.debug('set called for setting %s %s=%s', domain, name, value)
62 return self.client.set(domain, name, value)
63 except dss_error.Error as ex:
64 raise cmerror.CMError(str(ex))
66 def get_domains(self):
67 logging.debug('get_domains called')
69 return self.client.get_domains()
70 except dss_error.Error as ex:
71 raise cmerror.CMError(str(ex))
73 def delete(self, domain, name):
74 logging.debug('delete called for %s %s', domain, name)
76 if self._domain_exists(domain):
77 if self._name_exists_in_domain(domain, name):
79 self.client.delete(domain, name)
80 except dss_error.Error as ex:
81 raise cmerror.CMError(str(ex))
83 def delete_domain(self, domain):
84 logging.debug('delete_domain called for %s', domain)
86 if self._domain_exists(domain):
88 self.client.delete_domain(domain)
89 except dss_error.Error as ex:
90 raise cmerror.CMError(str(ex))