Class: Zm::Client::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/zm/client/cluster/cluster.rb

Overview

class admin connection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Cluster

Returns a new instance of Cluster.



22
23
24
25
26
27
28
29
30
# File 'lib/zm/client/cluster/cluster.rb', line 22

def initialize(config)
  @config = config
  @version = config.zimbra_version

  @zimbra_attributes = Base::ZimbraAttributesCollection.new(self)
  @zimbra_attributes.set_methods

  @soap_admin_connector = SoapAdminConnector.create(@config)
end

Instance Attribute Details

#buildDateObject (readonly)

Returns the value of attribute buildDate.



19
20
21
# File 'lib/zm/client/cluster/cluster.rb', line 19

def buildDate
  @buildDate
end

#configObject (readonly)

Returns the value of attribute config.



19
20
21
# File 'lib/zm/client/cluster/cluster.rb', line 19

def config
  @config
end

#hostObject (readonly)

Returns the value of attribute host.



19
20
21
# File 'lib/zm/client/cluster/cluster.rb', line 19

def host
  @host
end

#majorversionObject (readonly)

Returns the value of attribute majorversion.



19
20
21
# File 'lib/zm/client/cluster/cluster.rb', line 19

def majorversion
  @majorversion
end

#microversionObject (readonly)

Returns the value of attribute microversion.



19
20
21
# File 'lib/zm/client/cluster/cluster.rb', line 19

def microversion
  @microversion
end

#minorversionObject (readonly)

Returns the value of attribute minorversion.



19
20
21
# File 'lib/zm/client/cluster/cluster.rb', line 19

def minorversion
  @minorversion
end

#releaseObject (readonly)

Returns the value of attribute release.



19
20
21
# File 'lib/zm/client/cluster/cluster.rb', line 19

def release
  @release
end

#soap_admin_connectorObject (readonly)

Returns the value of attribute soap_admin_connector.



19
20
21
# File 'lib/zm/client/cluster/cluster.rb', line 19

def soap_admin_connector
  @soap_admin_connector
end

#typeObject (readonly)

Returns the value of attribute type.



19
20
21
# File 'lib/zm/client/cluster/cluster.rb', line 19

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



19
20
21
# File 'lib/zm/client/cluster/cluster.rb', line 19

def version
  @version
end

#zimbra_attributesObject (readonly)

Returns the value of attribute zimbra_attributes.



19
20
21
# File 'lib/zm/client/cluster/cluster.rb', line 19

def zimbra_attributes
  @zimbra_attributes
end

Instance Method Details

#accountsObject



92
93
94
95
96
# File 'lib/zm/client/cluster/cluster.rb', line 92

def accounts
  return @accounts if defined? @accounts

  @accounts = AccountsCollection.new self
end

#alive?Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
# File 'lib/zm/client/cluster/cluster.rb', line 64

def alive?
  soap_request = SoapElement.admin(SoapAdminConstants::NO_OP_REQUEST)
  @soap_admin_connector.invoke(soap_request)
  true
rescue Zm::Client::SoapError => e
  logger.error "Admin session token alive ? #{e.message}"
  false
end

#batchObject



174
175
176
177
178
# File 'lib/zm/client/cluster/cluster.rb', line 174

def batch
  return @batch if defined? @batch

  @batch = BatchRequest.new(@soap_admin_connector)
end

#cosesObject



110
111
112
113
114
# File 'lib/zm/client/cluster/cluster.rb', line 110

def coses
  return @coses if defined? @coses

  @coses = CosesCollection.new self
end

#count_object(type) ⇒ Object

Raises:



132
133
134
135
136
137
138
139
# File 'lib/zm/client/cluster/cluster.rb', line 132

def count_object(type)
  raise ZmError, 'Unknown object type' unless Zm::Client::CountTypes::ALL.include?(type)

  soap_request = SoapElement.admin(SoapAdminConstants::COUNT_OBJECTS_REQUEST)
  soap_request.add_attribute('type', type)
  soap_resp = @soap_admin_connector.invoke(soap_request)
  soap_resp[:CountObjectsResponse][:num]
end

#distributionlistsObject Also known as: distribution_lists



116
117
118
119
120
# File 'lib/zm/client/cluster/cluster.rb', line 116

def distributionlists
  return @distributionlists if defined? @distributionlists

  @distributionlists = DistributionListsCollection.new self
end

#domain_key(domain_name) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/zm/client/cluster/cluster.rb', line 124

def domain_key(domain_name)
  if logged?
    find_domain_key(domain_name)
  else
    @config.domain_key(domain_name)
  end
end

#domainsObject



86
87
88
89
90
# File 'lib/zm/client/cluster/cluster.rb', line 86

def domains
  return @domains if defined? @domains

  @domains = DomainsCollection.new self
end

#email_exist?(email) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/zm/client/cluster/cluster.rb', line 141

def email_exist?(email)
  jsns = {
    query: "(mail=#{email})",
    types: 'accounts,distributionlists,aliases,resources',
    countOnly: SoapUtils::ON
  }

  soap_request = SoapElement.admin(SoapAdminConstants::SEARCH_DIRECTORY_REQUEST)
  soap_request.add_attributes(jsns)
  soap_resp = @soap_admin_connector.invoke(soap_request)
  !soap_resp[:SearchDirectoryResponse][:num].zero?
end

#has_admin_credentials?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/zm/client/cluster/cluster.rb', line 32

def has_admin_credentials?
  @config.has_admin_credentials?
end

#infos!Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/zm/client/cluster/cluster.rb', line 154

def infos!
  soap_request = SoapElement.admin(SoapAdminConstants::GET_VERSION_INFO_REQUEST)
  soap_response = @soap_admin_connector.invoke(soap_request)

  json = soap_response[:GetVersionInfoResponse][:info].first

  instance_variable_set(:@type, json.delete(:type))
  instance_variable_set(:@version, json.delete(:version))
  instance_variable_set(:@release, json.delete(:release))
  instance_variable_set(:@buildDate, json.delete(:buildDate))
  instance_variable_set(:@host, json.delete(:host))
  instance_variable_set(:@majorversion, json.delete(:majorversion))
  instance_variable_set(:@minorversion, json.delete(:minorversion))
  instance_variable_set(:@microversion, json.delete(:microversion))
end

#licenseObject



77
78
79
80
81
82
83
84
# File 'lib/zm/client/cluster/cluster.rb', line 77

def license
  return @license if defined? @license

  @license = LicensesCollection.new(self).find
rescue Zm::Client::SoapError => e
  logger.error "Get License info #{e.message}"
  nil
end

#logged?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/zm/client/cluster/cluster.rb', line 60

def logged?
  !token.nil? && !token.expired?
end

#logged_and_alive?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/zm/client/cluster/cluster.rb', line 73

def logged_and_alive?
  logged? && alive?
end

#loggerObject



170
171
172
# File 'lib/zm/client/cluster/cluster.rb', line 170

def logger
  @config.logger
end

#loginObject

Raises:



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/zm/client/cluster/cluster.rb', line 46

def 
  raise ClusterConfigError, 'admin credentials are missing' unless @config.has_admin_credentials?

  logger.info 'Get Admin session token'

  @soap_admin_connector.token = nil if logged?

  soap_request = SoapElement.admin(SoapAdminConstants::AUTH_REQUEST)
  soap_request.add_attributes(name: @config., password: @config.zimbra_admin_password)
  soap_resp = @soap_admin_connector.invoke(soap_request, Zm::Client::AuthError)
  soap_resp_token = soap_resp[:AuthResponse][:authToken].first[:_content]
  self.token = soap_resp_token
end

#resourcesObject



98
99
100
101
102
# File 'lib/zm/client/cluster/cluster.rb', line 98

def resources
  return @resources if defined? @resources

  @resources = ResourcesCollection.new self
end

#serversObject



104
105
106
107
108
# File 'lib/zm/client/cluster/cluster.rb', line 104

def servers
  return @servers if defined? @servers

  @servers = ServersCollection.new self
end

#tokenObject



36
37
38
39
40
# File 'lib/zm/client/cluster/cluster.rb', line 36

def token
  return @token if defined? @token

  @token = (Token.new(@soap_admin_connector.token) if @soap_admin_connector.token)
end

#token=(value) ⇒ Object



42
43
44
# File 'lib/zm/client/cluster/cluster.rb', line 42

def token=(value)
  @token = Token.new(@soap_admin_connector.token = value)
end