@@ -20,6 +20,7 @@ import {
2020 Repo ,
2121 System ,
2222 File ,
23+ Menu ,
2324} from './custom-types/items' ;
2425import {
2526 BackgroundAclSetupOptions ,
@@ -917,7 +918,36 @@ export class CobblerApiService {
917918 ) ;
918919 }
919920
920- // TODO: Add endpoint for menu
921+ get_menu (
922+ name : string ,
923+ flatten : boolean = false ,
924+ resolved : boolean = false ,
925+ token : string ,
926+ ) : Observable < Menu > {
927+ return this . client
928+ . methodCall ( 'get_menu' , [ name , flatten , resolved , token ] )
929+ . pipe (
930+ map < MethodResponse | MethodFault , Menu > (
931+ ( data : MethodResponse | MethodFault ) => {
932+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
933+ if ( ! ( data . value instanceof Map ) ) {
934+ throw new Error ( 'Expected Map not something else!' ) ;
935+ }
936+ const result = this . rebuildItem ( data . value ) ;
937+ return result as Menu ;
938+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
939+ throw new Error (
940+ 'Getting the requested menu failed with code "' +
941+ data . faultCode +
942+ '" and error message "' +
943+ data . faultString +
944+ '"' ,
945+ ) ;
946+ }
947+ } ,
948+ ) ,
949+ ) ;
950+ }
921951
922952 get_items ( what : string ) : Observable < Array < object > > {
923953 // TODO: Add magic for casting to correct Collection
@@ -1204,7 +1234,35 @@ export class CobblerApiService {
12041234 ) ;
12051235 }
12061236
1207- // TODO: Create method for Menus
1237+ get_menus ( ) : Observable < Array < Menu > > {
1238+ return this . client . methodCall ( 'get_menus' ) . pipe (
1239+ map < MethodResponse | MethodFault , Array < Menu > > (
1240+ ( data : MethodResponse | MethodFault ) => {
1241+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
1242+ if ( ! ( data . value instanceof Array ) ) {
1243+ throw new Error ( 'Expected Array but got something else!' ) ;
1244+ }
1245+ const result = [ ] ;
1246+ data . value . forEach ( ( value ) => {
1247+ if ( ! ( value instanceof Map ) ) {
1248+ throw new Error ( 'Expected Map not something else!' ) ;
1249+ }
1250+ result . push ( this . rebuildItem ( value ) ) ;
1251+ } ) ;
1252+ return result as Array < Menu > ;
1253+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
1254+ throw new Error (
1255+ 'Getting the files failed with code "' +
1256+ data . faultCode +
1257+ '" and error message "' +
1258+ data . faultString +
1259+ '"' ,
1260+ ) ;
1261+ }
1262+ } ,
1263+ ) ,
1264+ ) ;
1265+ }
12081266
12091267 find_items (
12101268 what : string ,
@@ -1426,7 +1484,28 @@ export class CobblerApiService {
14261484 ) ;
14271485 }
14281486
1429- // TODO: Create find for menu
1487+ find_menu ( criteria : object , expand : boolean ) : Observable < Array < Menu > > {
1488+ return this . client
1489+ . methodCall ( 'find_menu' , [ criteria as XmlRpcStruct , expand ] )
1490+ . pipe (
1491+ map < MethodResponse | MethodFault , Array < Menu > > (
1492+ ( data : MethodResponse | MethodFault ) => {
1493+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
1494+ // FIXME: Make the cast without the unknown possible
1495+ return data . value as unknown as Array < Menu > ;
1496+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
1497+ throw new Error (
1498+ 'Finding the requested files failed with code "' +
1499+ data . faultCode +
1500+ '" and error message "' +
1501+ data . faultString +
1502+ '"' ,
1503+ ) ;
1504+ }
1505+ } ,
1506+ ) ,
1507+ ) ;
1508+ }
14301509
14311510 find_items_paged (
14321511 what : string ,
@@ -1669,6 +1748,26 @@ export class CobblerApiService {
16691748 ) ;
16701749 }
16711750
1751+ get_menu_handle ( name : string , token : string ) : Observable < string > {
1752+ return this . client . methodCall ( 'get_menu_handle' , [ name , token ] ) . pipe (
1753+ map < MethodResponse | MethodFault , string > (
1754+ ( data : MethodResponse | MethodFault ) => {
1755+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
1756+ return data . value as string ;
1757+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
1758+ throw new Error (
1759+ 'Getting the file handle failed with code "' +
1760+ data . faultCode +
1761+ '" and error message "' +
1762+ data . faultString +
1763+ '"' ,
1764+ ) ;
1765+ }
1766+ } ,
1767+ ) ,
1768+ ) ;
1769+ }
1770+
16721771 remove_item (
16731772 what : string ,
16741773 name : string ,
@@ -1900,6 +1999,30 @@ export class CobblerApiService {
19001999 ) ;
19012000 }
19022001
2002+ remove_menu (
2003+ name : string ,
2004+ token : string ,
2005+ recursive = true ,
2006+ ) : Observable < boolean > {
2007+ return this . client . methodCall ( 'remove_menu' , [ name , token , recursive ] ) . pipe (
2008+ map < MethodResponse | MethodFault , boolean > (
2009+ ( data : MethodResponse | MethodFault ) => {
2010+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
2011+ return data . value as boolean ;
2012+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
2013+ throw new Error (
2014+ 'Removing the requested file failed with code "' +
2015+ data . faultCode +
2016+ '" and error message "' +
2017+ data . faultString +
2018+ '"' ,
2019+ ) ;
2020+ }
2021+ } ,
2022+ ) ,
2023+ ) ;
2024+ }
2025+
19032026 copy_item (
19042027 what : string ,
19052028 objectId : string ,
@@ -2131,6 +2254,30 @@ export class CobblerApiService {
21312254 ) ;
21322255 }
21332256
2257+ copy_menu (
2258+ objectId : string ,
2259+ newName : string ,
2260+ token : string ,
2261+ ) : Observable < boolean > {
2262+ return this . client . methodCall ( 'copy_menu' , [ objectId , newName , token ] ) . pipe (
2263+ map < MethodResponse | MethodFault , boolean > (
2264+ ( data : MethodResponse | MethodFault ) => {
2265+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
2266+ return data . value as boolean ;
2267+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
2268+ throw new Error (
2269+ 'Copying the requested file failed with code "' +
2270+ data . faultCode +
2271+ '" and error message "' +
2272+ data . faultString +
2273+ '"' ,
2274+ ) ;
2275+ }
2276+ } ,
2277+ ) ,
2278+ ) ;
2279+ }
2280+
21342281 rename_item (
21352282 what : string ,
21362283 objectId : string ,
@@ -2366,6 +2513,32 @@ export class CobblerApiService {
23662513 ) ;
23672514 }
23682515
2516+ rename_menu (
2517+ objectId : string ,
2518+ newName : string ,
2519+ token : string ,
2520+ ) : Observable < boolean > {
2521+ return this . client
2522+ . methodCall ( 'rename_menu' , [ objectId , newName , token ] )
2523+ . pipe (
2524+ map < MethodResponse | MethodFault , boolean > (
2525+ ( data : MethodResponse | MethodFault ) => {
2526+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
2527+ return data . value as boolean ;
2528+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
2529+ throw new Error (
2530+ 'Renaming the requested menu failed with code "' +
2531+ data . faultCode +
2532+ '" and error message "' +
2533+ data . faultString +
2534+ '"' ,
2535+ ) ;
2536+ }
2537+ } ,
2538+ ) ,
2539+ ) ;
2540+ }
2541+
23692542 new_item (
23702543 what : string ,
23712544 token : string ,
@@ -2570,6 +2743,26 @@ export class CobblerApiService {
25702743 ) ;
25712744 }
25722745
2746+ new_menu ( token : string ) : Observable < string > {
2747+ return this . client . methodCall ( 'new_menu' , [ token ] ) . pipe (
2748+ map < MethodResponse | MethodFault , string > (
2749+ ( data : MethodResponse | MethodFault ) => {
2750+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
2751+ return data . value as string ;
2752+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
2753+ throw new Error (
2754+ 'Creating a new menu failed with code "' +
2755+ data . faultCode +
2756+ '" and error message "' +
2757+ data . faultString +
2758+ '"' ,
2759+ ) ;
2760+ }
2761+ } ,
2762+ ) ,
2763+ ) ;
2764+ }
2765+
25732766 modify_item (
25742767 what : string ,
25752768 objectId : string ,
@@ -2814,6 +3007,33 @@ export class CobblerApiService {
28143007 ) ;
28153008 }
28163009
3010+ modify_menu (
3011+ objectId : string ,
3012+ attribute : string ,
3013+ arg : any ,
3014+ token : string ,
3015+ ) : Observable < boolean > {
3016+ return this . client
3017+ . methodCall ( 'modify_menu' , [ objectId , attribute , arg , token ] )
3018+ . pipe (
3019+ map < MethodResponse | MethodFault , boolean > (
3020+ ( data : MethodResponse | MethodFault ) => {
3021+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
3022+ return data . value as boolean ;
3023+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
3024+ throw new Error (
3025+ 'Modifying the requested menu failed with code "' +
3026+ data . faultCode +
3027+ '" and error message "' +
3028+ data . faultString +
3029+ '"' ,
3030+ ) ;
3031+ }
3032+ } ,
3033+ ) ,
3034+ ) ;
3035+ }
3036+
28173037 modify_setting ( name : string , value : any , token : string ) : Observable < number > {
28183038 return this . client . methodCall ( 'modify_setting' , [ name , value , token ] ) . pipe (
28193039 map < MethodResponse | MethodFault , number > (
@@ -3123,6 +3343,32 @@ export class CobblerApiService {
31233343 ) ;
31243344 }
31253345
3346+ save_menu (
3347+ objectId : string ,
3348+ token : string ,
3349+ editmode = 'bypass' ,
3350+ ) : Observable < boolean > {
3351+ return this . client
3352+ . methodCall ( 'save_menu' , [ objectId , token , editmode ] )
3353+ . pipe (
3354+ map < MethodResponse | MethodFault , boolean > (
3355+ ( data : MethodResponse | MethodFault ) => {
3356+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
3357+ return data . value as boolean ;
3358+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
3359+ throw new Error (
3360+ 'Saving the requested menu failed with code "' +
3361+ data . faultCode +
3362+ '" and error message "' +
3363+ data . faultString +
3364+ '"' ,
3365+ ) ;
3366+ }
3367+ } ,
3368+ ) ,
3369+ ) ;
3370+ }
3371+
31263372 get_autoinstall_templates ( token : string ) : Observable < Array < string > > {
31273373 return this . client . methodCall ( 'get_autoinstall_templates' , [ token ] ) . pipe (
31283374 map < MethodResponse | MethodFault , Array < any > > (
@@ -3965,7 +4211,25 @@ export class CobblerApiService {
39654211 ) ;
39664212 }
39674213
3968- // TODO: Add gem_menus_since
4214+ get_menus_since ( mtime : number ) : Observable < object > {
4215+ return this . client . methodCall ( 'get_menus_since' , [ mtime ] ) . pipe (
4216+ map < MethodResponse | MethodFault , object > (
4217+ ( data : MethodResponse | MethodFault ) => {
4218+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
4219+ return data . value as object ;
4220+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
4221+ throw new Error (
4222+ 'Getting the menus modified since the requested mtime failed with code "' +
4223+ data . faultCode +
4224+ '" and error message "' +
4225+ data . faultString +
4226+ '"' ,
4227+ ) ;
4228+ }
4229+ } ,
4230+ ) ,
4231+ ) ;
4232+ }
39694233
39704234 get_repos_compatible_with_profile (
39714235 profile : string ,
@@ -4202,7 +4466,28 @@ export class CobblerApiService {
42024466 ) ;
42034467 }
42044468
4205- // TODO: menu_as_rendered
4469+ get_menu_as_rendered (
4470+ name : string ,
4471+ token : string ,
4472+ ) : Observable < Map < string , any > > {
4473+ return this . client . methodCall ( 'get_menu_as_rendered' , [ name , token ] ) . pipe (
4474+ map < MethodResponse | MethodFault , Map < string , any > > (
4475+ ( data : MethodResponse | MethodFault ) => {
4476+ if ( AngularXmlrpcService . instanceOfMethodResponse ( data ) ) {
4477+ return data . value as Map < string , any > ;
4478+ } else if ( AngularXmlrpcService . instanceOfMethodFault ( data ) ) {
4479+ throw new Error (
4480+ 'Getting the requested menu in a rendered format failed with code "' +
4481+ data . faultCode +
4482+ '" and error message "' +
4483+ data . faultString +
4484+ '"' ,
4485+ ) ;
4486+ }
4487+ } ,
4488+ ) ,
4489+ ) ;
4490+ }
42064491
42074492 get_random_mac ( virtType : string ) : Observable < string > {
42084493 return this . client . methodCall ( 'get_random_mac' , [ virtType ] ) . pipe (
0 commit comments