Class: ONVIF::DeviceManagementAction::SetNetworkInterfaces

Inherits:
Action
  • Object
show all
Defined in:
lib/ruby_onvif_client/device_management/set_network_interfaces.rb

Instance Method Summary collapse

Methods inherited from Action

#attribute, #callback, #create_event_onvif_message, #create_media_onvif_message, #create_ptz_onvif_message, #initialize, #send_message, #value

Constructor Details

This class inherits a constructor from ONVIF::Action

Instance Method Details

#run(network_interface, cb) ⇒ Object

network_interface 的结构 {

interface_token: 'xxxxxx',  // optional name [string]
nwif:{ // #NetworkInterface 
    enabled: true,   //optional  true, false  [boolean]
    link: {//optional
        auto_negotiation: true,  //true, false [boolean]
        speed: 3,        // [int]
        duplex: 'Full'   //'Full', 'Half' 
    }
    mtu: 2,   //optional  [int]
    ipv4: { //optional
        enabled: true, //optional true, false [boolean]
        manual: [{ //optional
            address: "xxx.xxx.xxx.xxx", // [IPv4Address]
            prefix_length: 22 // [int]
        }],
        dhcp: true //optional true, false [boolean]
    },
    ipv6: {//optional
        enabled: true, //optional  true, false [boolean]
        ara: false//optional  true, false  #AcceptRouterAdvert    [boolean]
        manual: [{//optional
            address: "xxx.xxx.xxx.xxx", // [IPv4Address]
            prefix_length: 22 // [int]
        }],
        dhcp: true //optional  true, false [boolean]
    }
}

}



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ruby_onvif_client/device_management/set_network_interfaces.rb', line 36

def run network_interface, cb
    message = Message.new namespaces: {:'xmlns:sch' => 'http://www.onvif.org/ver10/schema'}
    message.body =  ->(xml) do
        xml.wsdl(:SetNetworkInterfaces) do
            xml.wsdl :InterfaceToken, network_interface[:interface_token]
            xml.wsdl :NetworkInterface do
                unless options[:nwif][:enabled].nil?
                    xml.sch :Enabled, network_interface[:nwif][:enabled]
                end
                unless options[:nwif][:link].nil?
                    xml.sch :Link do
                        xml.sch :AutoNegotiation, network_interface[:nwif][:link][:auto_negotiation]
                        xml.sch :Speed, network_interface[:nwif][:link][:speed]
                        xml.sch :Duplex, network_interface[:nwif][:link][:duplex]
                    end
                end
                unless options[:nwif][:mtu].nil?
                    xml.sch :MTU, network_interface[:nwif][:mtu]
                end
                unless options[:nwif][:ipv4].nil?
                    xml.sch :IPv4 do
                        unless options[:nwif][:ipv4][:enabled].nil?
                            xml.sch :Enabled, network_interface[:nwif][:ipv4][:enabled]
                        end
                        unless options[:nwif][:ipv4][:manual].nil?
                            network_interface[:nwif][:ipv4][:manual].each do |manual|
                                xml.sch :Manual do
                                    xml.sch :Address, manual[:address]
                                    xml.sch :PrefixLength, manual[:prefix_length]
                                end
                            end
                        end
                        unless options[:nwif][:ipv4][:dhcp].nil?
                            xml.sch :DHCP, network_interface[:nwif][:ipv4][:dhcp]
                        end
                    end
                end
                unless options[:nwif][:ipv6].nil?
                    xml.sch :IPv6 do
                        unless options[:nwif][:ipv6][:enabled].nil?
                            xml.sch :Enabled, network_interface[:nwif][:ipv6][:enabled]
                        end
                        unless options[:nwif][:ipv6][:ara].nil?
                            xml.sch :AcceptRouterAdvert, network_interface[:nwif][:ipv6][:ara]
                        end
                        unless options[:nwif][:ipv6][:manual].nil?
                            network_interface[:nwif][:ipv6][:manual].each do |manual|
                                xml.sch :Manual do
                                    xml.sch :Address, manual[:address]
                                    xml.sch :PrefixLength, manual[:prefix_length]
                                end
                            end
                        end
                        unless options[:nwif][:ipv6][:dhcp].nil?
                            xml.sch :DHCP, network_interface[:nwif][:ipv6][:dhcp]
                        end
                    end
                end
            end
            xml.wsdl :Extension do
            end
        end
    end
    send_message message do |success, result|
        if success
            xml_doc = Nokogiri::XML(result[:content])
            info = {
                reboot_needed: value(xml_doc, '//tds:RebootNeeded')
            }

            callback cb, success, info
        else
            callback cb, success, result
        end
    end
end