Class: Yast::SLPClass

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

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) DeReg(service)

Deregister service with SLP

Parameters:

  • service (String)

    Service to be deregistered

Returns:

  • (Boolean)

    True on success



139
140
141
142
# File '../../src/modules/SLP.rb', line 139

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



173
174
175
176
# File '../../src/modules/SLP.rb', line 173

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



70
71
72
73
74
75
76
77
78
79
80
# File '../../src/modules/SLP.rb', line 70

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



25
26
27
28
29
30
31
32
33
34
35
36
# File '../../src/modules/SLP.rb', line 25

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File '../../src/modules/SLP.rb', line 50

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



118
119
120
121
122
123
124
125
126
# File '../../src/modules/SLP.rb', line 118

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



106
107
108
109
110
111
112
113
# File '../../src/modules/SLP.rb', line 106

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
# File '../../src/modules/SLP.rb', line 14

def main
  @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



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

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



131
132
133
134
# File '../../src/modules/SLP.rb', line 131

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



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File '../../src/modules/SLP.rb', line 149

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



87
88
89
90
91
92
93
94
95
96
97
98
99
# File '../../src/modules/SLP.rb', line 87

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