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

#    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. 

 

"""API for interfacing with Magnum Backend.""" 

from oslo_config import cfg 

 

from magnum.common import rpc_service 

from magnum import objects 

 

 

# The Backend API class serves as a AMQP client for communicating 

# on a topic exchange specific to the conductors.  This allows the ReST 

# API to trigger operations on the conductors 

 

class API(rpc_service.API): 

    def __init__(self, transport=None, context=None, topic=None): 

        if topic is None: 

            cfg.CONF.import_opt('topic', 'magnum.conductor.config', 

                                group='conductor') 

        super(API, self).__init__(transport, context, 

                                  topic=cfg.CONF.conductor.topic) 

 

    # Bay Model Operations 

 

    def baymodel_create(self, context, baymodel): 

        return baymodel.create(context) 

 

    def baymodel_list(self, context, limit, marker, sort_key, sort_dir): 

        return objects.BayModel.list(context, limit, marker, 

                                     sort_key, sort_dir) 

 

    def baymodel_delete(self, context, uuid): 

        baymodel = objects.BayModel.get_by_uuid(uuid) 

        return baymodel.destroy() 

 

    def baymodel_show(self, context, uuid): 

        return objects.BayModel.get_by_uuid(uuid) 

 

    # Bay Operations 

 

    def bay_create(self, bay, bay_create_timeout): 

        return self._call('bay_create', bay=bay, 

                          bay_create_timeout=bay_create_timeout) 

 

    def bay_list(self, context, limit, marker, sort_key, sort_dir): 

        return objects.Bay.list(context, limit, marker, sort_key, sort_dir) 

 

    def bay_delete(self, uuid): 

        return self._call('bay_delete', uuid=uuid) 

 

    def bay_show(self, context, uuid): 

        return objects.Bay.get_by_uuid(context, uuid) 

 

    def bay_update(self, bay): 

        return self._call('bay_update', bay=bay) 

 

    # Service Operations 

 

    def service_create(self, service): 

        return self._call('service_create', service=service) 

 

    def service_update(self, service): 

        return self._call('service_update', service=service) 

 

    def service_list(self, context, limit, marker, sort_key, sort_dir): 

        return objects.Service.list(context, limit, marker, sort_key, sort_dir) 

 

    def service_delete(self, uuid): 

        return self._call('service_delete', uuid=uuid) 

 

    def service_show(self, context, uuid): 

        return objects.Service.get_by_uuid(context, uuid) 

 

    # Pod Operations 

 

    def pod_create(self, pod): 

        return self._call('pod_create', pod=pod) 

 

    def pod_list(self, context, limit, marker, sort_key, sort_dir): 

        return objects.Pod.list(context, limit, marker, sort_key, sort_dir) 

 

    def pod_update(self, pod): 

        return self._call('pod_update', pod=pod) 

 

    def pod_delete(self, uuid): 

        return self._call('pod_delete', uuid=uuid) 

 

    def pod_show(self, context, uuid): 

        return objects.Pod.get_by_uuid(context, uuid) 

 

    # ReplicationController Operations 

 

    def rc_create(self, rc): 

        return self._call('rc_create', rc=rc) 

 

    def rc_update(self, rc): 

        return self._call('rc_update', rc=rc) 

 

    def rc_list(self, context, limit, marker, sort_key, sort_dir): 

        return objects.ReplicationController.list(context, limit, marker, 

                                                  sort_key, sort_dir) 

 

    def rc_delete(self, uuid): 

        return self._call('rc_delete', uuid=uuid) 

 

    def rc_show(self, context, uuid): 

        return objects.ReplicationController.get_by_uuid(context, uuid) 

 

    # Container operations 

 

    def container_create(self, name, container_uuid, container): 

        return self._call('container_create', name=name, 

                          container_uuid=container_uuid, 

                          container=container) 

 

    def container_list(self, context, limit, marker, sort_key, sort_dir): 

        return objects.Container.list(context, limit, marker, sort_key, 

                                      sort_dir) 

 

    def container_delete(self, container_uuid): 

        return self._call('container_delete', container_uuid=container_uuid) 

 

    def container_show(self, container_uuid): 

        return self._call('container_show', container_uuid=container_uuid) 

 

    def container_reboot(self, container_uuid): 

        return self._call('container_reboot', container_uuid=container_uuid) 

 

    def container_stop(self, container_uuid): 

        return self._call('container_stop', container_uuid=container_uuid) 

 

    def container_start(self, container_uuid): 

        return self._call('container_start', container_uuid=container_uuid) 

 

    def container_pause(self, container_uuid): 

        return self._call('container_pause', container_uuid=container_uuid) 

 

    def container_unpause(self, container_uuid): 

        return self._call('container_unpause', container_uuid=container_uuid) 

 

    def container_logs(self, container_uuid): 

        return self._call('container_logs', container_uuid=container_uuid) 

 

    def container_execute(self, container_uuid, command): 

        return self._call('container_execute', container_uuid=container_uuid, 

                          command=command) 

 

 

class ListenerAPI(rpc_service.API): 

    def __init__(self, context=None, topic=None, server=None, timeout=None): 

        super(ListenerAPI, self).__init__(context=context, topic=topic, 

                                          server=server, timeout=timeout) 

 

    def ping_conductor(self): 

        return self._call('ping_conductor')