@@ -1768,6 +1768,167 @@ def _show_progress(progress):
17681768 raise SystemExit
17691769
17701770
1771+ class ListMigration (command .Command ):
1772+ _description = _ ("""List server migrations.""" )
1773+
1774+ def get_parser (self , prog_name ):
1775+ parser = super (ListMigration , self ).get_parser (prog_name )
1776+ parser .add_argument (
1777+ "--server" ,
1778+ metavar = "<server>" ,
1779+ dest = 'server' ,
1780+ default = None ,
1781+ help = _ ('Server to show migration details (name or ID).' )
1782+ )
1783+ parser .add_argument (
1784+ "--host" ,
1785+ metavar = "<host>" ,
1786+ default = None ,
1787+ help = _ ('Fetch migrations for the given host.' )
1788+ )
1789+ parser .add_argument (
1790+ "--status" ,
1791+ metavar = "<status>" ,
1792+ default = None ,
1793+ help = _ ('Fetch migrations for the given status.' )
1794+ )
1795+ parser .add_argument (
1796+ "--marker" ,
1797+ metavar = "<marker>" ,
1798+ dest = 'marker' ,
1799+ default = None ,
1800+ help = _ ("The last migration of the previous page; displays list "
1801+ "of migrations after 'marker'. Note that the marker is "
1802+ "the migration UUID. (Supported with "
1803+ "``--os-compute-api-version`` 2.59 or greater.)" )
1804+ )
1805+ parser .add_argument (
1806+ "--limit" ,
1807+ metavar = "<limit>" ,
1808+ dest = 'limit' ,
1809+ type = int ,
1810+ default = None ,
1811+ help = _ ("Maximum number of migrations to display. Note that there "
1812+ "is a configurable max limit on the server, and the limit "
1813+ "that is used will be the minimum of what is requested "
1814+ "here and what is configured in the server. "
1815+ "(Supported with ``--os-compute-api-version`` 2.59 "
1816+ "or greater.)" )
1817+ )
1818+ parser .add_argument (
1819+ '--changes-since' ,
1820+ dest = 'changes_since' ,
1821+ metavar = '<changes-since>' ,
1822+ default = None ,
1823+ help = _ ("List only migrations changed later or equal to a certain "
1824+ "point of time. The provided time should be an ISO 8061 "
1825+ "formatted time, e.g. ``2016-03-04T06:27:59Z``. "
1826+ "(Supported with ``--os-compute-api-version`` 2.59 "
1827+ "or greater.)" )
1828+ )
1829+ parser .add_argument (
1830+ '--changes-before' ,
1831+ dest = 'changes_before' ,
1832+ metavar = '<changes-before>' ,
1833+ default = None ,
1834+ help = _ ("List only migrations changed earlier or equal to a "
1835+ "certain point of time. The provided time should be an ISO "
1836+ "8061 formatted time, e.g. ``2016-03-04T06:27:59Z``. "
1837+ "(Supported with ``--os-compute-api-version`` 2.66 or "
1838+ "greater.)" )
1839+ )
1840+ parser .add_argument (
1841+ '--project' ,
1842+ metavar = '<project>' ,
1843+ dest = 'project_id' ,
1844+ default = None ,
1845+ help = _ ("Filter the migrations by the given project ID. "
1846+ "(Supported with ``--os-compute-api-version`` 2.80 "
1847+ "or greater.)" ),
1848+ )
1849+ parser .add_argument (
1850+ '--user' ,
1851+ metavar = '<user>' ,
1852+ dest = 'user_id' ,
1853+ default = None ,
1854+ help = _ ("Filter the migrations by the given user ID. "
1855+ "(Supported with ``--os-compute-api-version`` 2.80 "
1856+ "or greater.)" ),
1857+ )
1858+ return parser
1859+
1860+ def print_migrations (self , parsed_args , compute_client , migrations ):
1861+ columns = ['Source Node' , 'Dest Node' , 'Source Compute' ,
1862+ 'Dest Compute' , 'Dest Host' , 'Status' ,
1863+ 'Server UUID' , 'Old Flavor' , 'New Flavor' ,
1864+ 'Created At' , 'Updated At' ]
1865+
1866+ # Insert migrations UUID after ID
1867+ if compute_client .api_version >= api_versions .APIVersion ("2.59" ):
1868+ columns .insert (0 , "UUID" )
1869+
1870+ # TODO(brinzhang): It also suppports filter migrations by type
1871+ # since 2.1. https://review.opendev.org/#/c/675117 supported
1872+ # filtering the migrations by 'migration_type' and 'source_compute'
1873+ # in novaclient, that will be added in OSC by follow-up.
1874+ if compute_client .api_version >= api_versions .APIVersion ("2.23" ):
1875+ columns .insert (0 , "Id" )
1876+ columns .insert (len (columns ) - 2 , "Type" )
1877+
1878+ if compute_client .api_version >= api_versions .APIVersion ("2.80" ):
1879+ if parsed_args .project_id :
1880+ columns .insert (len (columns ) - 2 , "Project" )
1881+ if parsed_args .user_id :
1882+ columns .insert (len (columns ) - 2 , "User" )
1883+
1884+ columns_header = columns
1885+ return (columns_header , (utils .get_item_properties (
1886+ mig , columns ) for mig in migrations ))
1887+
1888+ def take_action (self , parsed_args ):
1889+ compute_client = self .app .client_manager .compute
1890+
1891+ search_opts = {
1892+ "host" : parsed_args .host ,
1893+ "server" : parsed_args .server ,
1894+ "status" : parsed_args .status ,
1895+ }
1896+
1897+ if (parsed_args .marker or parsed_args .limit or
1898+ parsed_args .changes_since ):
1899+ if compute_client .api_version < api_versions .APIVersion ("2.59" ):
1900+ msg = _ ("marker, limit and/or changes_since is not supported "
1901+ "for --os-compute-api-version less than 2.59" )
1902+ raise exceptions .CommandError (msg )
1903+ if parsed_args .marker :
1904+ search_opts ['marker' ] = parsed_args .marker
1905+ if parsed_args .limit :
1906+ search_opts ['limit' ] = parsed_args .limit
1907+ if parsed_args .changes_since :
1908+ search_opts ['changes_since' ] = parsed_args .changes_since
1909+
1910+ if parsed_args .changes_before :
1911+ if compute_client .api_version < api_versions .APIVersion ("2.66" ):
1912+ msg = _ ("changes_before is not supported for "
1913+ "--os-compute-api-version less than 2.66" )
1914+ raise exceptions .CommandError (msg )
1915+ search_opts ['changes_before' ] = parsed_args .changes_before
1916+
1917+ if parsed_args .project_id or parsed_args .user_id :
1918+ if compute_client .api_version < api_versions .APIVersion ("2.80" ):
1919+ msg = _ ("Project and/or user is not supported for "
1920+ "--os-compute-api-version less than 2.80" )
1921+ raise exceptions .CommandError (msg )
1922+ if parsed_args .project_id :
1923+ search_opts ['project_id' ] = parsed_args .project_id
1924+ if parsed_args .user_id :
1925+ search_opts ['user_id' ] = parsed_args .user_id
1926+
1927+ migrations = compute_client .migrations .list (** search_opts )
1928+
1929+ return self .print_migrations (parsed_args , compute_client , migrations )
1930+
1931+
17711932class PauseServer (command .Command ):
17721933 _description = _ ("Pause server(s)" )
17731934
0 commit comments