{
    "Resources": [
        {
            "Uri": "/cli/v1/service",
            "Interfaces": [
                {
                    "Type": "Patch",
                    "Description": "Operate with service"
                }
            ]
        },
        {
            "Uri": "/cli/v1/service/port",
            "Interfaces": [
                {
                    "Type": "Patch",
                    "Description": "Set service port",
                    "Usage": "ipmcset -t service -d port -v <option> <port1value(1~65535, SSDP:1024~65535)> [port2value(1~65535)]",
                    "Example": [
                        "ipmcset -t service -d port -v HTTP 80",
                        "ipmcset -t service -d port -v HTTPS 443"
                    ],
                    "ReqBody": {
                        "Type": "object",
                        "Required": true,
                        "Properties": {
                            "option": {
                                "Required": true,
                                "Type": "string",
                                "Description": "\n    SSH                    SSH service port(default value 22)\n    SNMP                   SNMP service port(default value 161)\n    KVM                    KVM service port(default value 2198)\n    VNC                    VNC service port(default value 5900)\n    VMM                    VMM service port(default value 8208)\n    Video                  Video service port(default value 2199)\n    HTTP                   web server HTTP service port(default value 80)\n    HTTPS                  web server HTTPS service port(default value 443)\n    RMCP                   RMCP/RMCP+ service port1 and port2(default value 623 and 664)\n    SSDP                   SSDP service port(default value 1900)"
                            },
                            "port1value": {
                                "Required": true,
                                "Type": "integer",
                                "Validator": [
                                    {
                                        "Type": "Range",
                                        "Formula": [
                                            1,
                                            65535
                                        ]
                                    }
                                ]
                            },
                            "port2value": {
                                "Required": false,
                                "Type": "integer",
                                "Validator": [
                                    {
                                        "Type": "Range",
                                        "Formula": [
                                            1,
                                            65535
                                        ]
                                    }
                                ]
                            }
                        }
                    },
                    "RspBody": {
                        "option": "${Statements/GetServicePortType()[2]}",
                        "portstring": "${Statements/PortString()}",
                        "portcount": "${Statements/PortCount()}",
                        "IsMultihost": "${ProcessingFlow[1]/Destination/HostType}"
                    },
                    "Statements": {
                        "GetServicePortType": {
                            "Input": "${ReqBody/option}",
                            "Steps": [
                                {
                                    "Type": "Script",
                                    "Formula": "get_service_port_type.lua"
                                }
                            ]
                        },
                        "GetServiceTypeRmcp": {
                            "Input": "${Statements/GetServicePortType()[2]}",
                            "Steps": [
                                {
                                    "Type": "Switch",
                                    "Formula": [
                                        {
                                            "Case": "RMCP",
                                            "To": true
                                        },
                                        {
                                            "To": false
                                        }
                                    ]
                                }
                            ]
                        },
                        "GetMultiSystemServiceType": {
                            "Input": "${Statements/GetServicePortType()[2]}",
                            "Steps": [
                                {
                                    "Type": "Switch",
                                    "Formula": [
                                        {
                                            "Case": "KVMIP",
                                            "To": true
                                        },
                                        {
                                            "Case": "VirtualMedia",
                                            "To": true
                                        },
                                        {
                                            "To": false
                                        }
                                    ]
                                }
                            ]
                        },
                        "PortString": {
                            "Steps": [
                                {
                                    "Type": "Script",
                                    "Formula": "return ReqBody.port2value ~= nil and ReqBody.port1value .. ',' .. ReqBody.port2value or ReqBody.port1value .. ''"
                                }
                            ]
                        },
                        "PortCount": {
                            "Input": "${ReqBody/port2value}",
                            "Steps": [
                                {
                                    "Type": "Switch",
                                    "Formula": [
                                        {
                                            "Case": null,
                                            "To": 1
                                        },
                                        {
                                            "To": 2
                                        }
                                    ]
                                }
                            ]
                        },
                        "CheckMultihost": {
                            "Input": "${ProcessingFlow[1]/Destination/HostType}",
                            "Steps": [
                                {
                                    "Type": "Script",
                                    "Formula": "local opt = string.upper(ReqBody.option) if Input == 'Multihost' and (opt == 'SNMP' or opt == 'VNC' or opt == 'VMM' or opt == 'KVM' or opt == 'VIDEO') then return false else return true end"
                                }
                            ]
                        }
                    },
                    "ProcessingFlow": [
                        {
                            "Type": "Property",
                            "Path": "/bmc/kepler/Managers/1/Multihost",
                            "Interface": "bmc.kepler.Managers.Multihost",
                            "Destination": {
                                "HostType": "HostType"
                            }
                        },
                        {
                            "Type": "Property",
                            "Path": "/bmc/kepler/Managers/1/NetworkProtocol/${Statements/GetServicePortType()[2]}",
                            "Interface": "bmc.kepler.Managers.NetworkProtocol.PortConfig",
                            "Source": {
                                "Port": "${ReqBody/port1value}"
                            },
                            "CallIf": {
                                "${Statements/GetServicePortType()[1]}": true,
                                "${ReqBody/port1value}": "#WITH",
                                "${ReqBody/port2value}": "#WITHOUT",
                                "${Statements/CheckMultihost()}": true,
                                "${Statements/GetMultiSystemServiceType()}": false
                            }
                        },
                        {
                            "Type": "Method",
                            "Path": "/bmc/kepler/Managers/1/NetworkProtocol/${Statements/GetServicePortType()[2]}",
                            "Interface": "bmc.kepler.Managers.NetworkProtocol.PortConfig",
                            "Name": "SetPorts",
                            "Params": [
                                "${ReqBody/port1value}",
                                "${ReqBody/port2value}"
                            ],
                            "CallIf": {
                                "${Statements/GetServicePortType()[1]}": true,
                                "${Statements/GetServiceTypeRmcp()}": true,
                                "${ReqBody/port1value}": "#WITH",
                                "${ReqBody/port2value}": "#WITH"
                            }
                        },
                        {
                            "Type": "Property",
                            "Path": "/bmc/kepler/Managers/1/NetworkProtocol/${Statements/GetServicePortType()[2]}/1",
                            "Interface": "bmc.kepler.Managers.NetworkProtocol.PortConfig",
                            "Source": {
                                "Port": "${ReqBody/port1value}"
                            },
                            "CallIf": {
                                "${Statements/GetServicePortType()[1]}": true,
                                "${ReqBody/port1value}": "#WITH",
                                "${ReqBody/port2value}": "#WITHOUT",
                                "${Statements/CheckMultihost()}": true,
                                "${Statements/GetMultiSystemServiceType()}": true
                            }
                        }
                    ],
                    "Echoes": [
                        "ipmcset/service_port",
                        ""
                    ]
                }
            ]
        },
        {
            "Uri": "/cli/v1/service/state",
            "Interfaces": [
                {
                    "Type": "Patch",
                    "Description": "Set service enable state",
                    "Usage": "ipmcset -t service -d state -v <option> <enabled|disabled>",
                    "Example": [
                        "ipmcset -t service -d state -v HTTP enabled"
                    ],
                    "ReqBody": {
                        "Type": "object",
                        "Required": true,
                        "Properties": {
                            "option": {
                                "Type": "string",
                                "Required": true,
                                "Description": "\n    SSH                    SSH service state\n    SNMP                   SNMP service state\n    KVM                    KVM service state\n    VNC                    VNC service state\n    VMM                    VMM service state\n    Video                  Video service state\n    HTTP                   web server HTTP service state\n    HTTPS                  web server HTTPS service state\n    RMCP                   RMCP service state\n    RMCP+                  RMCP+ service state\n    SSDP                   SSDP service state"
                            },
                            "state": {
                                "Type": "string",
                                "Required": true,
                                "Validator": [
                                    {
                                        "Type": "Enum",
                                        "Formula": [
                                            "enabled",
                                            "disabled"
                                        ]
                                    }
                                ]
                            }
                        }
                    },
                    "Confirm": {
                        "Condition": "${Statements/Condition()}",
                        "Description": "WARNING: Enabling the http/rmcp functions may reduce system security.Exercise caution when enabling these functions.\r\nDo you want to continue?[Y/N]:"
                    },
                    "RspBody": {
                        "option": "${Statements/GetServiceStateType()[2]}",
                        "state": "${ReqBody/state}",
                        "AuthenticationEnabled": "${ProcessingFlow[1]/Destination/AuthenticationEnabled}",
                        "IsMultihost": "${ProcessingFlow[5]/Destination/HostType}"
                    },
                    "Statements": {
                        "GetServiceStateType": {
                            "Input": "${ReqBody/option}",
                            "Steps": [
                                {
                                    "Type": "Script",
                                    "Formula": "get_service_state_type.lua"
                                }
                            ]
                        },
                        "Condition": {
                            "Input": "${Statements/GetServiceStateType()[2]}",
                            "Steps": [
                                {
                                    "Type": "Script",
                                    "Formula": "check_service_state_condition.lua"
                                }
                            ]
                        },
                        "GetServiceTypeSsh": {
                            "Input": "${Statements/GetServiceStateType()[2]}",
                            "Steps": [
                                {
                                    "Type": "Switch",
                                    "Formula": [
                                        {
                                            "Case": "SSH",
                                            "To": true
                                        },
                                        {
                                            "To": false
                                        }
                                    ]
                                }
                            ]
                        },
                        "GetState": {
                            "Input": "${ReqBody/state}",
                            "Steps": [
                                {
                                    "Type": "Switch",
                                    "Formula": [
                                        {
                                            "Case": "enabled",
                                            "To": true
                                        },
                                        {
                                            "Case": "disabled",
                                            "To": false
                                        }
                                    ]
                                }
                            ]
                        },
                        "GetMultiSystemServiceType": {
                            "Input": "${Statements/GetServiceStateType()[2]}",
                            "Steps": [
                                {
                                    "Type": "Switch",
                                    "Formula": [
                                        {
                                            "Case": "KVMIP",
                                            "To": true
                                        },
                                        {
                                            "Case": "VirtualMedia",
                                            "To": true
                                        },
                                        {
                                            "To": false
                                        }
                                    ]
                                }
                            ]
                        }
                    },
                    "ProcessingFlow": [
                        {
                            "Type": "Property",
                            "Path": "/bmc/kepler/AccountService/CertificateAuthentication",
                            "Interface": "bmc.kepler.AccountService.CertificateAuthentication",
                            "Destination": {
                                "Enabled": "AuthenticationEnabled"
                            }
                        },
                        {
                            "Type": "Property",
                            "Path": "/bmc/kepler/Managers/1/NetworkProtocol/${Statements/GetServiceStateType()[2]}",
                            "Interface": "bmc.kepler.Managers.NetworkProtocol.PortConfig",
                            "Source": {
                                "Enabled": "${Statements/GetState()}"
                            },
                            "CallIf": {
                                "${Statements/GetServiceStateType()[1]}": true,
                                "${Statements/GetServiceTypeSsh()}": false,
                                "${Statements/GetMultiSystemServiceType()}": false
                            }
                        },
                        {
                            "Type": "Property",
                            "Path": "/bmc/kepler/Managers/1/NetworkProtocol/${Statements/GetServiceStateType()[2]}",
                            "Interface": "bmc.kepler.Managers.NetworkProtocol.PortConfig",
                            "Source": {
                                "Enabled": "${Statements/GetState()}"
                            },
                            "CallIf": {
                                "${Statements/GetServiceStateType()[1]}": true,
                                "${Statements/GetServiceTypeSsh()}": true,
                                "${Statements/GetState()}": true,
                                "${ProcessingFlow[1]/Destination/AuthenticationEnabled}": false
                            }
                        },
                        {
                            "Type": "Property",
                            "Path": "/bmc/kepler/Managers/1/NetworkProtocol/${Statements/GetServiceStateType()[2]}",
                            "Interface": "bmc.kepler.Managers.NetworkProtocol.PortConfig",
                            "Source": {
                                "Enabled": "${Statements/GetState()}"
                            },
                            "CallIf": {
                                "${Statements/GetServiceStateType()[1]}": true,
                                "${Statements/GetServiceTypeSsh()}": true,
                                "${Statements/GetState()}": false
                            }
                        },
                        {
                            "Type": "Property",
                            "Path": "/bmc/kepler/Managers/1/Multihost",
                            "Interface": "bmc.kepler.Managers.Multihost",
                            "Destination": {
                                "HostType": "HostType"
                            }
                        },
                        {
                            "Type": "Property",
                            "Path": "/bmc/kepler/Managers/1/NetworkProtocol/${Statements/GetServiceStateType()[2]}/1",
                            "Interface": "bmc.kepler.Managers.NetworkProtocol.PortConfig",
                            "Source": {
                                "Enabled": "${Statements/GetState()}"
                            },
                            "CallIf": {
                                "${Statements/GetServiceStateType()[1]}": true,
                                "${Statements/GetMultiSystemServiceType()}": true
                            }
                        }
                    ],
                    "Echoes": [
                        "ipmcset/service_state",
                        ""
                    ]
                }
            ]
        }
    ]
}