Coverage for osmclient/cli_commands/wim.py: 45%

101 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2024-06-30 09:54 +0000

1# Copyright ETSI Contributors and Others. 

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 

16import click 

17from osmclient.cli_commands import utils 

18from prettytable import PrettyTable 

19import json 

20import logging 

21 

22logger = logging.getLogger("osmclient") 

23 

24 

25@click.command(name="wim-create", short_help="creates a new WIM account") 

26@click.option("--name", prompt=True, help="Name for the WIM account") 

27@click.option("--user", help="WIM username") 

28@click.option("--password", help="WIM password") 

29@click.option("--url", prompt=True, help="WIM url") 

30@click.option("--config", default=None, help="WIM specific config parameters") 

31@click.option("--wim_type", help="WIM type") 

32@click.option("--description", default=None, help="human readable description") 

33@click.option( 

34 "--wim_port_mapping", 

35 default=None, 

36 help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge " 

37 "(WAN service endpoint id and info)", 

38) 

39@click.option( 

40 "--wait", 

41 required=False, 

42 default=False, 

43 is_flag=True, 

44 help="do not return the control immediately, but keep it " 

45 "until the operation is completed, or timeout", 

46) 

47@click.pass_context 

48def wim_create( 

49 ctx, 

50 name, 

51 user, 

52 password, 

53 url, 

54 config, 

55 wim_type, 

56 description, 

57 wim_port_mapping, 

58 wait, 

59): 

60 """creates a new WIM account""" 

61 logger.debug("") 

62 utils.check_client_version(ctx.obj, ctx.command.name) 

63 wim = {} 

64 if user: 

65 wim["user"] = user 

66 if password: 

67 wim["password"] = password 

68 if url: 

69 wim["wim_url"] = url 

70 wim["wim_type"] = wim_type 

71 if description: 

72 wim["description"] = description 

73 if config: 

74 wim["config"] = config 

75 ctx.obj.wim.create(name, wim, wim_port_mapping, wait=wait) 

76 

77 

78@click.command(name="wim-update", short_help="updates a WIM account") 

79@click.argument("name") 

80@click.option("--newname", help="New name for the WIM account") 

81@click.option("--user", help="WIM username") 

82@click.option("--password", help="WIM password") 

83@click.option("--url", help="WIM url") 

84@click.option("--config", help="WIM specific config parameters") 

85@click.option("--wim_type", help="WIM type") 

86@click.option("--description", help="human readable description") 

87@click.option( 

88 "--wim_port_mapping", 

89 default=None, 

90 help="File describing the port mapping between DC edge (datacenters, switches, ports) and WAN edge " 

91 "(WAN service endpoint id and info)", 

92) 

93@click.option( 

94 "--wait", 

95 required=False, 

96 default=False, 

97 is_flag=True, 

98 help="do not return the control immediately, but keep it until the operation is completed, or timeout", 

99) 

100@click.pass_context 

101def wim_update( 

102 ctx, 

103 name, 

104 newname, 

105 user, 

106 password, 

107 url, 

108 config, 

109 wim_type, 

110 description, 

111 wim_port_mapping, 

112 wait, 

113): 

114 """updates a WIM account 

115 

116 NAME: name or ID of the WIM account 

117 """ 

118 logger.debug("") 

119 utils.check_client_version(ctx.obj, ctx.command.name) 

120 wim = {} 

121 if newname: 

122 wim["name"] = newname 

123 if user: 

124 wim["user"] = user 

125 if password: 

126 wim["password"] = password 

127 if url: 

128 wim["url"] = url 

129 if wim_type: 

130 wim["wim_type"] = wim_type 

131 if description: 

132 wim["description"] = description 

133 if config: 

134 wim["config"] = config 

135 ctx.obj.wim.update(name, wim, wim_port_mapping, wait=wait) 

136 

137 

138@click.command(name="wim-delete", short_help="deletes a WIM account") 

139@click.argument("name") 

140@click.option( 

141 "--force", is_flag=True, help="forces the deletion bypassing pre-conditions" 

142) 

143@click.option( 

144 "--wait", 

145 required=False, 

146 default=False, 

147 is_flag=True, 

148 help="do not return the control immediately, but keep it until the operation is completed, or timeout", 

149) 

150@click.pass_context 

151def wim_delete(ctx, name, force, wait): 

152 """deletes a WIM account 

153 

154 NAME: name or ID of the WIM account to be deleted 

155 """ 

156 logger.debug("") 

157 utils.check_client_version(ctx.obj, ctx.command.name) 

158 ctx.obj.wim.delete(name, force, wait=wait) 

159 

160 

161@click.command(name="wim-list", short_help="list all WIM accounts") 

162@click.option( 

163 "--filter", 

164 default=None, 

165 multiple=True, 

166 help="restricts the list to the WIM accounts matching the filter", 

167) 

168@click.pass_context 

169def wim_list(ctx, filter): 

170 """list all WIM accounts""" 

171 logger.debug("") 

172 utils.check_client_version(ctx.obj, ctx.command.name) 

173 if filter: 

174 filter = "&".join(filter) 

175 resp = ctx.obj.wim.list(filter) 

176 table = PrettyTable(["wim name", "uuid"]) 

177 for wim in resp: 

178 table.add_row([wim["name"], wim["uuid"]]) 

179 table.align = "l" 

180 print(table) 

181 

182 

183@click.command(name="wim-show", short_help="shows the details of a WIM account") 

184@click.argument("name") 

185@click.pass_context 

186def wim_show(ctx, name): 

187 """shows the details of a WIM account 

188 

189 NAME: name or ID of the WIM account 

190 """ 

191 logger.debug("") 

192 utils.check_client_version(ctx.obj, ctx.command.name) 

193 resp = ctx.obj.wim.get(name) 

194 if "password" in resp: 

195 resp["password"] = "********" 

196 

197 table = PrettyTable(["key", "attribute"]) 

198 for k, v in list(resp.items()): 

199 table.add_row([k, json.dumps(v, indent=2)]) 

200 table.align = "l" 

201 print(table)