Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

# vim: tabstop=4 shiftwidth=4 softtabstop=4 

 

# Copyright 2012 OpenStack LLC 

# Copyright 2012 Canonical Ltd. 

# 

# Licensed under the Apache License, Version 2.0 (the "License"); you may 

# not use this file except in compliance with the License. You may obtain 

# a copy of the License at 

# 

#      http://www.apache.org/licenses/LICENSE-2.0 

# 

# Unless required by applicable law or agreed to in writing, software 

# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

# License for the specific language governing permissions and limitations 

# under the License. 

 

"""Main entry point into the Catalog service.""" 

 

from keystone.common import dependency 

from keystone.common import logging 

from keystone.common import manager 

from keystone import config 

from keystone import exception 

 

 

CONF = config.CONF 

LOG = logging.getLogger(__name__) 

 

 

def format_url(url, data): 

    """Safely string formats a user-defined URL with the given data.""" 

    try: 

        result = url.replace('$(', '%(') % data 

    except AttributeError: 

        return None 

    except KeyError as e: 

        LOG.error(_("Malformed endpoint %(url)s - unknown key %(keyerror)s") % 

                  {"url": url, 

                   "keyerror": str(e)}) 

        raise exception.MalformedEndpoint(endpoint=url) 

    except TypeError as e: 

        LOG.error(_("Malformed endpoint %(url)s - unknown key %(keyerror)s" 

                    "(are you missing brackets ?)") % 

                  {"url": url, 

                   "keyerror": str(e)}) 

        raise exception.MalformedEndpoint(endpoint=url) 

    except ValueError as e: 

        LOG.error(_("Malformed endpoint %s - incomplete format \ 

                  (are you missing a type notifier ?)") % url) 

        raise exception.MalformedEndpoint(endpoint=url) 

    return result 

 

 

@dependency.provider('catalog_api') 

class Manager(manager.Manager): 

    """Default pivot point for the Catalog backend. 

 

    See :mod:`keystone.common.manager.Manager` for more details on how this 

    dynamically calls the backend. 

 

    """ 

 

    def __init__(self): 

        super(Manager, self).__init__(CONF.catalog.driver) 

 

    def get_service(self, context, service_id): 

        try: 

            return self.driver.get_service(service_id) 

        except exception.NotFound: 

            raise exception.ServiceNotFound(service_id=service_id) 

 

    def delete_service(self, context, service_id): 

        try: 

            return self.driver.delete_service(service_id) 

        except exception.NotFound: 

            raise exception.ServiceNotFound(service_id=service_id) 

 

    def create_endpoint(self, context, endpoint_id, endpoint_ref): 

        try: 

            return self.driver.create_endpoint(endpoint_id, endpoint_ref) 

        except exception.NotFound: 

            service_id = endpoint_ref.get('service_id') 

            raise exception.ServiceNotFound(service_id=service_id) 

 

    def delete_endpoint(self, context, endpoint_id): 

        try: 

            return self.driver.delete_endpoint(endpoint_id) 

        except exception.NotFound: 

            raise exception.EndpointNotFound(endpoint_id=endpoint_id) 

 

    def get_endpoint(self, context, endpoint_id): 

        try: 

            return self.driver.get_endpoint(endpoint_id) 

        except exception.NotFound: 

            raise exception.EndpointNotFound(endpoint_id=endpoint_id) 

 

    def get_catalog(self, context, user_id, tenant_id, metadata=None): 

        try: 

            return self.driver.get_catalog(user_id, tenant_id, metadata) 

        except exception.NotFound: 

            raise exception.NotFound('Catalog not found for user and tenant') 

 

 

class Driver(object): 

    """Interface description for an Catalog driver.""" 

    def create_service(self, service_id, service_ref): 

        """Creates a new service. 

 

        :raises: keystone.exception.Conflict 

 

        """ 

        raise exception.NotImplemented() 

 

    def list_services(self): 

        """List all services. 

 

        :returns: list of service_refs or an empty list. 

 

        """ 

        raise exception.NotImplemented() 

 

    def get_service(self, service_id): 

        """Get service by id. 

 

        :returns: service_ref dict 

        :raises: keystone.exception.ServiceNotFound 

 

        """ 

        raise exception.NotImplemented() 

 

    def update_service(self, service_id): 

        """Update service by id. 

 

        :returns: service_ref dict 

        :raises: keystone.exception.ServiceNotFound 

 

        """ 

        raise exception.NotImplemented() 

 

    def delete_service(self, service_id): 

        """Deletes an existing service. 

 

        :raises: keystone.exception.ServiceNotFound 

 

        """ 

        raise exception.NotImplemented() 

 

    def create_endpoint(self, endpoint_id, endpoint_ref): 

        """Creates a new endpoint for a service. 

 

        :raises: keystone.exception.Conflict, 

                 keystone.exception.ServiceNotFound 

 

        """ 

        raise exception.NotImplemented() 

 

    def get_endpoint(self, endpoint_id): 

        """Get endpoint by id. 

 

        :returns: endpoint_ref dict 

        :raises: keystone.exception.EndpointNotFound 

 

        """ 

        raise exception.NotImplemented() 

 

    def list_endpoints(self): 

        """List all endpoints. 

 

        :returns: list of endpoint_refs or an empty list. 

 

        """ 

        raise exception.NotImplemented() 

 

    def update_endpoint(self, endpoint_id, endpoint_ref): 

        """Get endpoint by id. 

 

        :returns: endpoint_ref dict 

        :raises: keystone.exception.EndpointNotFound 

                 keystone.exception.ServiceNotFound 

 

        """ 

        raise exception.NotImplemented() 

 

    def delete_endpoint(self, endpoint_id): 

        """Deletes an endpoint for a service. 

 

        :raises: keystone.exception.EndpointNotFound 

 

        """ 

        raise exception.NotImplemented() 

 

    def get_catalog(self, user_id, tenant_id, metadata=None): 

        """Retrieve and format the current service catalog. 

 

        Example:: 

 

            { 'RegionOne': 

                {'compute': { 

                    'adminURL': u'http://host:8774/v1.1/tenantid', 

                    'internalURL': u'http://host:8774/v1.1/tenant_id', 

                    'name': 'Compute Service', 

                    'publicURL': u'http://host:8774/v1.1/tenantid'}, 

                 'ec2': { 

                    'adminURL': 'http://host:8773/services/Admin', 

                    'internalURL': 'http://host:8773/services/Cloud', 

                    'name': 'EC2 Service', 

                    'publicURL': 'http://host:8773/services/Cloud'}} 

 

        :returns: A nested dict representing the service catalog or an 

                  empty dict. 

        :raises: keystone.exception.NotFound 

 

        """ 

        raise exception.NotImplemented() 

 

    def get_v3_catalog(self, user_id, tenant_id, metadata=None): 

        """Retrieve and format the current V3 service catalog. 

 

        Example:: 

 

            [ 

                { 

                    "endpoints": [ 

                    { 

                        "interface": "public", 

                        "id": "--endpoint-id--", 

                        "region": "RegionOne", 

                        "url": "http://external:8776/v1/--project-id--" 

                    }, 

                    { 

                        "interface": "internal", 

                        "id": "--endpoint-id--", 

                        "region": "RegionOne", 

                        "url": "http://internal:8776/v1/--project-id--" 

                    }], 

                "id": "--service-id--", 

                "type": "volume" 

            }] 

 

        :returns: A list representing the service catalog or an empty list 

        :raises: keystone.exception.NotFound 

 

        """ 

        raise exception.NotImplemented()