1717
1818import logging
1919
20+ from openstack import exceptions as sdk_exceptions
2021from osc_lib .command import command
2122from osc_lib import exceptions
2223from osc_lib import utils
@@ -55,16 +56,26 @@ def get_parser(self, prog_name):
5556 return parser
5657
5758 def take_action (self , parsed_args ):
58- compute_client = self .app .client_manager .compute
59- args = (
60- parsed_args .os ,
61- parsed_args .architecture ,
62- parsed_args .version ,
63- parsed_args .url ,
64- parsed_args .md5hash ,
65- parsed_args .hypervisor ,
59+ compute_client = self .app .client_manager .sdk_connection .compute
60+
61+ # doing this since openstacksdk has decided not to support this
62+ # deprecated command
63+ data = {
64+ 'agent' : {
65+ 'hypervisor' : parsed_args .hypervisor ,
66+ 'os' : parsed_args .os ,
67+ 'architecture' : parsed_args .architecture ,
68+ 'version' : parsed_args .version ,
69+ 'url' : parsed_args .url ,
70+ 'md5hash' : parsed_args .md5hash ,
71+ },
72+ }
73+ response = compute_client .post (
74+ '/os-agents' , json = data , microversion = '2.1'
6675 )
67- agent = compute_client .agents .create (* args )._info .copy ()
76+ sdk_exceptions .raise_from_response (response )
77+ agent = response .json ().get ('agent' )
78+
6879 return zip (* sorted (agent .items ()))
6980
7081
@@ -84,11 +95,16 @@ def get_parser(self, prog_name):
8495 return parser
8596
8697 def take_action (self , parsed_args ):
87- compute_client = self .app .client_manager .compute
98+ compute_client = self .app .client_manager .sdk_connection . compute
8899 result = 0
89100 for id in parsed_args .id :
90101 try :
91- compute_client .agents .delete (id )
102+ # doing this since openstacksdk has decided not to support this
103+ # deprecated command
104+ response = compute_client .delete (
105+ f'/os-agents/{ id } ' , microversion = '2.1'
106+ )
107+ sdk_exceptions .raise_from_response (response )
92108 except Exception as e :
93109 result += 1
94110 LOG .error (
@@ -123,7 +139,7 @@ def get_parser(self, prog_name):
123139 return parser
124140
125141 def take_action (self , parsed_args ):
126- compute_client = self .app .client_manager .compute
142+ compute_client = self .app .client_manager .sdk_connection . compute
127143 columns = (
128144 "Agent ID" ,
129145 "Hypervisor" ,
@@ -133,30 +149,36 @@ def take_action(self, parsed_args):
133149 "Md5Hash" ,
134150 "URL" ,
135151 )
136- data = compute_client .agents .list (parsed_args .hypervisor )
137- return (
138- columns ,
139- (
140- utils .get_item_properties (
141- s ,
142- columns ,
143- )
144- for s in data
145- ),
146- )
152+
153+ # doing this since openstacksdk has decided not to support this
154+ # deprecated command
155+ path = '/os-agents'
156+ if parsed_args .hypervisor :
157+ path += f'?hypervisor={ parsed_args .hypervisor } '
158+
159+ response = compute_client .get (path , microversion = '2.1' )
160+ sdk_exceptions .raise_from_response (response )
161+ agents = response .json ().get ('agents' )
162+
163+ return columns , (utils .get_dict_properties (s , columns ) for s in agents )
147164
148165
149166class SetAgent (command .Command ):
150167 """Set compute agent properties.
151168
152- The compute agent functionality is hypervisor specific and is only
169+ The compute agent functionality is hypervisor- specific and is only
153170 supported by the XenAPI hypervisor driver. It was removed from nova in the
154171 23.0.0 (Wallaby) release.
155172 """
156173
157174 def get_parser (self , prog_name ):
158175 parser = super ().get_parser (prog_name )
159- parser .add_argument ("id" , metavar = "<id>" , help = _ ("ID of the agent" ))
176+ parser .add_argument (
177+ "id" ,
178+ metavar = "<id>" ,
179+ type = int ,
180+ help = _ ("ID of the agent" ),
181+ )
160182 parser .add_argument (
161183 "--agent-version" ,
162184 dest = "version" ,
@@ -172,30 +194,34 @@ def get_parser(self, prog_name):
172194 return parser
173195
174196 def take_action (self , parsed_args ):
175- compute_client = self .app .client_manager .compute
176- data = compute_client .agents .list (hypervisor = None )
177- agent = {}
178-
179- for s in data :
180- if s .agent_id == int (parsed_args .id ):
181- agent ['version' ] = s .version
182- agent ['url' ] = s .url
183- agent ['md5hash' ] = s .md5hash
184- if agent == {}:
197+ compute_client = self .app .client_manager .sdk_connection .compute
198+
199+ response = compute_client .get ('/os-agents' , microversion = '2.1' )
200+ sdk_exceptions .raise_from_response (response )
201+ agents = response .json ().get ('agents' )
202+ data = {}
203+ for agent in agents :
204+ if agent ['agent_id' ] == parsed_args .id :
205+ data ['version' ] = agent ['version' ]
206+ data ['url' ] = agent ['url' ]
207+ data ['md5hash' ] = agent ['md5hash' ]
208+ break
209+ else :
185210 msg = _ ("No agent with a ID of '%(id)s' exists." )
186- raise exceptions .CommandError (msg % parsed_args .id )
211+ raise exceptions .CommandError (msg % { 'id' : parsed_args .id } )
187212
188213 if parsed_args .version :
189- agent ['version' ] = parsed_args .version
214+ data ['version' ] = parsed_args .version
190215 if parsed_args .url :
191- agent ['url' ] = parsed_args .url
216+ data ['url' ] = parsed_args .url
192217 if parsed_args .md5hash :
193- agent ['md5hash' ] = parsed_args .md5hash
218+ data ['md5hash' ] = parsed_args .md5hash
219+
220+ data = {'para' : data }
194221
195- args = (
196- parsed_args .id ,
197- agent ['version' ],
198- agent ['url' ],
199- agent ['md5hash' ],
222+ # doing this since openstacksdk has decided not to support this
223+ # deprecated command
224+ response = compute_client .put (
225+ f'/os-agents/{ parsed_args .id } ' , json = data , microversion = '2.1'
200226 )
201- compute_client . agents . update ( * args )
227+ sdk_exceptions . raise_from_response ( response )
0 commit comments