xcat2 / xcat-inventory

An inventory tool for xcat cluster
8 stars 16 forks source link

add normal regular expression transform for node attribute #215

Closed bybai closed 5 years ago

bybai commented 5 years ago

for https://github.ibm.com/xcat2/task_management/issues/260

  1. Use python to realize the Easy Regular expressions of perl function transRegexAttrs in Table.pm

UT: 1.

[root@byrh07 allien]# lsdef -t group bybai
Object name: bybai
    members=c910f04x12v04
    nichostnamesuffixes.ens4=-ens4
    nicips.ens4=|\D+\d+\D+\d+\D+(\d)+\D+(\d+)|30.0.($1).($2/1000+9)|
    nicnetworks.ens4=30_0_0_0-255_255_0_0
    nictypes.ens4=Ethernet
[root@byrh07 allien]# lsdef c910f04x12v04
Object name: c910f04x12v04
    groups=bybai
    nichostnamesuffixes.ens4=-ens4
    nicips.ens4=30.0.2.9
    nicnetworks.ens4=30_0_0_0-255_255_0_0
    nictypes.ens4=Ethernet
    postbootscripts=otherpkgs
    postscripts=syslog,remoteshell,syncfiles
[root@byrh07 allien]# curl -X GET "http://10.4.41.7:5000/api/v2/system/nodes/c910f04x12v04/_detail" -H  "accept: application/json"
{
    "meta": {
        "name": "c910f04x12v04"
    },
    "spec": {
        "obj_type": "node",
        "engines": {
            "netboot_engine": {
                "engine_info": {
                    "postbootscripts": "otherpkgs,",
                    "postscripts": "syslog,remoteshell,syncfiles,"
                }
            }
        },
        "obj_info": {
            "groups": "bybai"
        },
        "role": "compute",
        "device_type": "server",
        "network_info": {
            "nics": {
                "ens4": {
                    "ips": "30.0.2.9",
                    "hostnamesuffixes": [
                        "-ens4"
                    ],
                    "networks": [
                        "30_0_0_0-255_255_0_0"
                    ],
                    "type": [
                        "Ethernet"
                    ]
                }
            }
        }
    }
}

2.

[root@byrh07 allien]# lsdef -t group bybai -i nicips.ens4
Object name: bybai
    nicips.ens4=|\D+\d+\D+\d+\D+(\d)+\D+(\d+)|30.0.($2+$1).($2+9)|
[root@byrh07 allien]# lsdef c910f04x12v04 -i nicips.ens4
Object name: c910f04x12v04
    nicips.ens4=30.0.6.13

[root@byrh07 allien]# curl -X GET "http://10.4.41.7:5000/api/v2/system/nodes/c910f04x12v04/_detail" -H  "accept: application/json"
{
    "meta": {
        "name": "c910f04x12v04"
    },
    "spec": {
        "obj_type": "node",
        "engines": {
            "netboot_engine": {
                "engine_info": {
                    "postbootscripts": "otherpkgs,",
                    "postscripts": "syslog,remoteshell,syncfiles,"
                }
            }
        },
        "obj_info": {
            "groups": "bybai"
        },
        "role": "compute",
        "device_type": "server",
        "network_info": {
            "nics": {
                "ens4": {
                    "ips": "30.0.6.13",
                    "hostnamesuffixes": [
                        "-ens4"
                    ],
                    "networks": [
                        "30_0_0_0-255_255_0_0"
                    ],
                    "type": [
                        "Ethernet"
                    ]
                }
            }
        }
    }
}

3.

]# lsdef -t group bybai -i nicips.ens4
Object name: bybai
    nicips.ens4=|\D+\d+\D+\d+\D+(\d)+\D+(\d+)|30.0.($2+($1*3)).($2+9)|
[root@byrh07 allien]# lsdef c910f04x12v04 -i nicips.ens4
Object name: c910f04x12v04
    nicips.ens4=30.0.10.13
[root@byrh07 allien]# curl -X GET "http://10.4.41.7:5000/api/v2/system/nodes/c910f04x12v04/_detail" -H  "accept: application/json"
{
    "meta": {
        "name": "c910f04x12v04"
    },
    "spec": {
        "obj_type": "node",
        "engines": {
            "netboot_engine": {
                "engine_info": {
                    "postbootscripts": "otherpkgs,",
                    "postscripts": "syslog,remoteshell,syncfiles,"
                }
            }
        },
        "obj_info": {
            "groups": "bybai"
        },
        "role": "compute",
        "device_type": "server",
        "network_info": {
            "nics": {
                "ens4": {
                    "ips": "30.0.10.13",
                    "hostnamesuffixes": [
                        "-ens4"
                    ],
                    "networks": [
                        "30_0_0_0-255_255_0_0"
                    ],
                    "type": [
                        "Ethernet"
                    ]
                }
            }
        }
    }
}
  1. if using wrong format regular expression
    [root@byrh07 ~]# lsdef -t group bybai -i nicips.ens4
    Object name: bybai
    nicips.ens4=|\D+\d+\D+\d+\D+(\d)+\D+(\d+)|30.0.($2+($1*3).($2+9)|
    [root@byrh07 ~]# lsdef c910f04x12v04 -i nicips.ens4
    Object name: c910f04x12v04
    nicips.ens4=30.0.($2+($1*3).($2+9)
    [root@byrh07 ~]# curl -X GET "http://10.4.41.7:5000/api/v2/system/nodes/c910f04x12v04/_detail" -H  "accept: application/json"
    {
    "meta": {
        "name": "c910f04x12v04"
    },
    "spec": {
        "obj_type": "node",
        "engines": {
            "netboot_engine": {
                "engine_info": {
                    "postbootscripts": "otherpkgs,",
                    "postscripts": "syslog,remoteshell,syncfiles,"
                }
            }
        },
        "obj_info": {
            "groups": "bybai"
        },
        "role": "compute",
        "device_type": "server",
        "network_info": {
            "nics": {
                "ens4": {
                    "ips": "30.0.(04+(2*3).(04+9)",
                    "hostnamesuffixes": [
                        "-ens4"
                    ],
                    "networks": [
                        "30_0_0_0-255_255_0_0"
                    ],
                    "type": [
                        "Ethernet"
                    ]
                }
            }
        }
    }
    }