Class: Yast::SLPClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/SLP.rb

Instance Method Summary (collapse)

Instance Method Details

- (String) AttrSummary(_Attrs)

Attribute summary

Parameters:

  • Attrs (Array<String>)

    attribute list

Returns:

  • (String)

    summary



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File '../../src/modules/SLP.rb', line 136

def AttrSummary(_Attrs)
  _Attrs = deep_copy(_Attrs)
  summary = ""
  summary = Summary.AddHeader(summary, _("Attributes"))
  summary = Summary.OpenList(summary)
  Builtins.foreach(_Attrs) do |a|
    s = Builtins.substring(a, 1, Ops.subtract(Builtins.size(a), 2))
    aa = Builtins.splitstring(s, "=")
    summary = Summary.AddListItem(
      summary,
      Builtins.sformat(
        "%1: %2",
        HTML.Bold(Ops.get_string(aa, 0, "")),
        Ops.get_string(aa, 1, "")
      )
    )
  end

  summary = Summary.CloseList(summary)
  summary
end

- (Boolean) DeReg(service)

Deregister service with SLP

Parameters:

  • service (String)

    Service to be deregistered

Returns:

  • (Boolean)

    True on success



169
170
171
172
# File '../../src/modules/SLP.rb', line 169

def DeReg(service)
  ret = Convert.to_boolean(SCR.Execute(path(".slp.dereg"), service))
  ret
end

- (Boolean) DeRegFile(regfile)

De-Register service with SLP by removing the reg file

Parameters:

  • regfile (String)

    The service to be deregistered

Returns:

  • (Boolean)

    True on success



203
204
205
206
# File '../../src/modules/SLP.rb', line 203

def DeRegFile(regfile)
  ret = Convert.to_boolean(SCR.Execute(path(".target.remove"), regfile))
  ret
end

- (Array<String>) FindAttrs(pcURLOrServiceType)

Find attributes of a service

Parameters:

  • pcURLOrServiceType (String)

    service url or type

Returns:

  • (Array<String>)

    attributes



75
76
77
78
79
80
81
82
83
84
85
# File '../../src/modules/SLP.rb', line 75

def FindAttrs(pcURLOrServiceType)
  _Attrs = Convert.convert(
    SCR.Read(
      path(".slp.findattrs"),
      { "pcURLOrServiceType" => pcURLOrServiceType }
    ),
    :from => "any",
    :to   => "list <string>"
  )
  deep_copy(_Attrs)
end

- (Array<Hash>) FindSrvs(pcServiceType, pcScopeList)

Issue the query for services any, for the request, such as can be discovered using SLPSrvTypes(). This could be, for example "service:printer:lpr" or "service:nfs". service types.

Parameters:

  • pcServiceType (String)

    The Service Type String, including authority string if

  • pcScopeList (String)

    comma separated list of scope names to search for

Returns:

  • (Array<Hash>)

    List of Services



30
31
32
33
34
35
36
37
38
39
40
41
# File '../../src/modules/SLP.rb', line 30

def FindSrvs(pcServiceType, pcScopeList)
  _Srvs = Convert.convert(
    SCR.Read(
      path(".slp.findsrvs"),
      { "pcServiceType" => pcServiceType, "pcScopeList" => pcScopeList }
    ),
    :from => "any",
    :to   => "list <map>"
  )
  Builtins.y2debug("FindSrvs: %1", _Srvs)
  deep_copy(_Srvs)
end

- (Array<String>) FindSrvTypes(pcNamingAuthority, pcScopeList)

Issues an SLP service type request for service types in the scopes indicated by the pcScopeList.

If the naming authority is “*”, then results are returned for all naming authorities. If the naming authority is the empty string, i.e. "", then the default naming authority, "IANA", is used.

service types.

Parameters:

  • pcNamingAuthority (String)

    The naming authority to search.

  • pcScopeList (String)

    comma separated list of scope names to search for

Returns:

  • (Array<String>)

    Service Types



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File '../../src/modules/SLP.rb', line 55

def FindSrvTypes(pcNamingAuthority, pcScopeList)
  _Types = Convert.convert(
    SCR.Read(
      path(".slp.findsrvtypes"),
      {
        "pcNamingAuthority" => pcNamingAuthority,
        "pcScopeList"       => pcScopeList
      }
    ),
    :from => "any",
    :to   => "list <string>"
  )
  deep_copy(_Types)
end

- (Hash{String => String}) GetAttrMap(pcURLOrServiceType)

Find attributes of a service and return a map

Parameters:

  • pcURLOrServiceType (String)

    service url or type

Returns:

  • (Hash{String => String})

    attributes



123
124
125
126
127
128
129
130
131
# File '../../src/modules/SLP.rb', line 123

def GetAttrMap(pcURLOrServiceType)
  _Attrs = FindAttrs(pcURLOrServiceType)
  att = Builtins.listmap(_Attrs) do |a|
    s = Builtins.substring(a, 1, Ops.subtract(Builtins.size(a), 2))
    aa = Builtins.splitstring(s, "=")
    { Ops.get_string(aa, 0, "empty") => Ops.get_string(aa, 1, "empty") }
  end
  deep_copy(att)
end

- (Hash{String => String}) GetUnicastAttrMap(pcURLOrServiceType, ip)

Find attributes (using unicast query) of a service and return a map

Parameters:

  • pcURLOrServiceType (String)

    service url or type

  • ip (String)

    IP address of the server

Returns:

  • (Hash{String => String})

    attributes



111
112
113
114
115
116
117
118
# File '../../src/modules/SLP.rb', line 111

def GetUnicastAttrMap(pcURLOrServiceType, ip)
  _Attrs = UnicastFindAttrs(pcURLOrServiceType, ip)
  Builtins.listmap(_Attrs) do |a|
    s = Builtins.substring(a, 1, Ops.subtract(Builtins.size(a), 2))
    aa = Builtins.splitstring(s, "=")
    { Ops.get_string(aa, 0, "empty") => Ops.get_string(aa, 1, "empty") }
  end
end

- (Object) main



14
15
16
17
18
19
20
21
# File '../../src/modules/SLP.rb', line 14

def main
  textdomain "slp"
  Yast.import "Summary"
  Yast.import "HTML"


  @Regd = "/etc/slp.reg.d"
end

- (Array<Hash>) MatchType(match)

Match Srv Type and return all data

Parameters:

  • match (String)

    match string

Returns:

  • (Array<Hash>)

    list of services matching with all relevant data



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File '../../src/modules/SLP.rb', line 210

def MatchType(match)
  t = FindSrvTypes("*", "")
  ret = []
  Builtins.foreach(t) do |type|
    if Builtins.regexpmatch(type, match)
      matched = FindSrvs(type, "")
      ret = Convert.convert(
        Builtins.union(ret, Builtins.maplist(matched) do |m|
          Ops.set(m, "attr", GetAttrMap(Ops.get_string(m, "srvurl", "")))
          deep_copy(m)
        end),
        :from => "list",
        :to   => "list <map>"
      )
    end
  end
  deep_copy(ret)
end

- (Boolean) Reg(service)

Register service with SLP

Parameters:

  • service (String)

    Service to be registered

Returns:

  • (Boolean)

    True on success



161
162
163
164
# File '../../src/modules/SLP.rb', line 161

def Reg(service)
  ret = Convert.to_boolean(SCR.Execute(path(".slp.reg"), service))
  ret
end

- (Boolean) RegFile(service, attr, regfile)

Register service with SLP using a reg file

Parameters:

  • service (String)

    The service to be registered

  • attr (Hash{String => String})

    Attributes

  • regfile (String)

    Reg File

Returns:

  • (Boolean)

    True on Success



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File '../../src/modules/SLP.rb', line 179

def RegFile(service, attr, regfile)
  attr = deep_copy(attr)
  slp = []
  slp = Builtins.add(slp, service)
  Builtins.foreach(attr) do |k, v|
    slp = Builtins.add(
      slp,
      Builtins.sformat("%1=%2", Builtins.tolower(k), v)
    )
  end

  all = Builtins.mergestring(slp, "\n")
  SCR.Execute(path(".target.mkdir"), @Regd)
  ret = SCR.Write(
    path(".target.string"),
    Builtins.sformat("%1/%2", @Regd, regfile),
    all
  )
  ret
end

- (Array<String>) UnicastFindAttrs(pcURLOrServiceType, ip)

Find attributes of a service using a unicast query

Parameters:

  • pcURLOrServiceType (String)

    service url or type

  • ip (String)

    IP address of the server

Returns:

  • (Array<String>)

    attributes



92
93
94
95
96
97
98
99
100
101
102
103
104
# File '../../src/modules/SLP.rb', line 92

def UnicastFindAttrs(pcURLOrServiceType, ip)
  return FindAttrs(pcURLOrServiceType) if ip == ""

  _Attrs = Convert.convert(
    SCR.Read(
      path(".slp.unicastfindattrs"),
      { "pcURLOrServiceType" => pcURLOrServiceType, "ip-address" => ip }
    ),
    :from => "any",
    :to   => "list <string>"
  )
  deep_copy(_Attrs)
end