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.



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

def initialize(config)
  # extend(ZmLogger)

  @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.



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

def buildDate
  @buildDate
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#majorversionObject (readonly)

Returns the value of attribute majorversion.



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

def majorversion
  @majorversion
end

#microversionObject (readonly)

Returns the value of attribute microversion.



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

def microversion
  @microversion
end

#minorversionObject (readonly)

Returns the value of attribute minorversion.



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

def minorversion
  @minorversion
end

#releaseObject (readonly)

Returns the value of attribute release.



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

def release
  @release
end

#soap_admin_connectorObject (readonly)

Returns the value of attribute soap_admin_connector.



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

def soap_admin_connector
  @soap_admin_connector
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



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

def version
  @version
end

#zimbra_attributesObject (readonly)

Returns the value of attribute zimbra_attributes.



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

def zimbra_attributes
  @zimbra_attributes
end

Instance Method Details

#accountsObject



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

def accounts
  @accounts ||= AccountsCollection.new self
end

#alive?Boolean

Returns:

  • (Boolean)


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

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

#cosesObject



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

def coses
  @coses ||= CosesCollection.new self
end

#count_object(type) ⇒ Object

Raises:



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

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



102
103
104
# File 'lib/zm/client/cluster/cluster.rb', line 102

def distributionlists
  @distributionlists ||= DistributionListsCollection.new self
end

#domain_key(domain_name) ⇒ Object



108
109
110
111
112
# File 'lib/zm/client/cluster/cluster.rb', line 108

def domain_key(domain_name)
  key = @config.domain_key(domain_name)
  key ||= find_domain_key(domain_name)
  key
end

#domainsObject



82
83
84
# File 'lib/zm/client/cluster/cluster.rb', line 82

def domains
  @domains ||= DomainsCollection.new self
end

#email_exist?(email) ⇒ Boolean

Returns:

  • (Boolean)


123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/zm/client/cluster/cluster.rb', line 123

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)


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

def has_admin_credentials?
  @config.has_admin_credentials?
end

#infos!Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/zm/client/cluster/cluster.rb', line 136

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[:type])
  instance_variable_set(:@version, json[:version])
  instance_variable_set(:@release, json[:release])
  instance_variable_set(:@buildDate, json[:buildDate])
  instance_variable_set(:@host, json[:host])
  instance_variable_set(:@majorversion, json[:majorversion])
  instance_variable_set(:@minorversion, json[:minorversion])
  instance_variable_set(:@microversion, json[:microversion])
end

#licenseObject



75
76
77
78
79
80
# File 'lib/zm/client/cluster/cluster.rb', line 75

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

#logged?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/zm/client/cluster/cluster.rb', line 58

def logged?
  !@soap_admin_connector.token.nil?
end

#loginObject

Raises:



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

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_admin_connector.context.token(soap_resp[:AuthResponse][:authToken].first[:_content])
end

#resourcesObject



90
91
92
# File 'lib/zm/client/cluster/cluster.rb', line 90

def resources
  @resources ||= ResourcesCollection.new self
end

#serversObject



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

def servers
  @servers ||= ServersCollection.new self
end

#tokenObject



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

def token
  @soap_admin_connector.token
end

#token=(value) ⇒ Object



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

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

#token_metadataObject



71
72
73
# File 'lib/zm/client/cluster/cluster.rb', line 71

def 
  @token_metadata ||= TokenMetaData.new(@soap_admin_connector.token)
end