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.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/zm/client/cluster/cluster.rb', line 24

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.new(
    @config.zimbra_admin_scheme,
    @config.zimbra_admin_host,
    @config.zimbra_admin_port
  )
  @soap_admin_connector.logger = logger
end

Instance Attribute Details

#buildDateObject (readonly)

Returns the value of attribute buildDate.



22
23
24
# File 'lib/zm/client/cluster/cluster.rb', line 22

def buildDate
  @buildDate
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#hostObject (readonly)

Returns the value of attribute host.



22
23
24
# File 'lib/zm/client/cluster/cluster.rb', line 22

def host
  @host
end

#majorversionObject (readonly)

Returns the value of attribute majorversion.



22
23
24
# File 'lib/zm/client/cluster/cluster.rb', line 22

def majorversion
  @majorversion
end

#microversionObject (readonly)

Returns the value of attribute microversion.



22
23
24
# File 'lib/zm/client/cluster/cluster.rb', line 22

def microversion
  @microversion
end

#minorversionObject (readonly)

Returns the value of attribute minorversion.



22
23
24
# File 'lib/zm/client/cluster/cluster.rb', line 22

def minorversion
  @minorversion
end

#releaseObject (readonly)

Returns the value of attribute release.



22
23
24
# File 'lib/zm/client/cluster/cluster.rb', line 22

def release
  @release
end

#soap_admin_connectorObject (readonly)

Returns the value of attribute soap_admin_connector.



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

def soap_admin_connector
  @soap_admin_connector
end

#typeObject (readonly)

Returns the value of attribute type.



22
23
24
# File 'lib/zm/client/cluster/cluster.rb', line 22

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



22
23
24
# File 'lib/zm/client/cluster/cluster.rb', line 22

def version
  @version
end

#zimbra_attributesObject (readonly)

Returns the value of attribute zimbra_attributes.



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

def zimbra_attributes
  @zimbra_attributes
end

Instance Method Details

#accountsObject



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

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

#alive?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
# File 'lib/zm/client/cluster/cluster.rb', line 59

def alive?
  @soap_admin_connector.noop
  true
rescue Zm::Client::SoapError => e
  logger.error "Admin session token alive ? #{e.message}"
  false
end

#cosesObject



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

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

#count_object(type) ⇒ Object

Raises:



122
123
124
125
126
127
# File 'lib/zm/client/cluster/cluster.rb', line 122

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

  resp = soap_admin_connector.count_object(type)
  resp[:Body][:CountObjectsResponse][:num]
end

#distributionlistsObject Also known as: distribution_lists



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

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

#domain_key(domain_name) ⇒ Object



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

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

#domainsObject



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

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

#email_exist?(email) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
132
133
134
# File 'lib/zm/client/cluster/cluster.rb', line 129

def email_exist?(email)
  filter = "(mail=#{email})"
  resp = soap_admin_connector.search_directory(filter, nil, nil, nil, nil, nil, nil, nil, 'accounts,distributionlists,aliases,resources',nil, 1)
  num = resp[:Body][:SearchDirectoryResponse][:num]
  !num.zero?
end

#has_admin_credentials?Boolean

Returns:

  • (Boolean)


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

def has_admin_credentials?
  @config.has_admin_credentials?
end

#infos!Object



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

def infos!
  rep = soap_admin_connector.get_version_info
  json = rep[:Body][: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



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

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)


55
56
57
# File 'lib/zm/client/cluster/cluster.rb', line 55

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

#loginObject

Raises:



45
46
47
48
49
50
51
52
53
# 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.auth(
    @config.,
    @config.zimbra_admin_password
  )
end

#resourcesObject



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

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

#serversObject



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

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

#soap_account_connectorObject



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/zm/client/cluster/cluster.rb', line 67

def 
  return  unless .nil?

   = SoapAccountConnector.new(
    @config.zimbra_public_scheme,
    @config.zimbra_public_host,
    @config.zimbra_public_port
  )
  .logger = logger
  
end

#token_metadataObject



79
80
81
# File 'lib/zm/client/cluster/cluster.rb', line 79

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