plesk_kit 2.0.17 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzA5MmQxZGRjYjI2ZWU1YmVlNDIxZTI2OGVlMmQ0OTliOTI2ZDUwZA==
4
+ ZDA2YjIyZjRmYTM3Y2E5NjUzMDA2YzIyMDU4ZmRmYTJhOGEzNTM2MA==
5
5
  data.tar.gz: !binary |-
6
- YzkxNzY3MjJkMWJhMzhmZGZiNTBjMTQ3ZGZlN2Q1YWZjNGRmMDZlYw==
6
+ MWUzYzQ0YjAyNmYxN2I4Yjg2NTcyYzEwOTAxZjY2MWVkZWVjNjhlNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OTY5YTczYzFlNDAyMWMzZWFmZDVkNDgzOTM5NjZmYTVjZjc4YTllM2QxOTBm
10
- YmYwZmM5MjJiYWNlY2RlNDRlZDlkMzBjYzJjN2Y1ZWE1ODU3NjM1YTU0NGY3
11
- YTRlZWJhZjdlYTRiZjNkMmY4ZDliYzViMzYwM2Y4YmEwNDAzYzU=
9
+ MGZmZDE0Zjc0ZmJjOWRhNDcwYWM1YTU4OWE2YzM4MjhlNTVmYzVjNzNiNzIx
10
+ ZGU5OWI0MzVmZjFmMjA0MDk0NWRlNDIyOGRhOWM0YmRmYjBkOTg1NDRlNDVk
11
+ NDVjOWMxMTU2YzdmMGJjZDUzMTAyYjU0NDVkNzk5ZTNhYTMzZWU=
12
12
  data.tar.gz: !binary |-
13
- NzZiYzUxNjk2NzRmZTY0NGM1ODU1MGExOTczNTYyYmJjMzgyMTRlYjdkMzI3
14
- MjAzYjIxYzkxMTY1MDgwNjgxNmYxYWUzOWZlY2MwNmZiZTU1ZmNlZjk1OGUz
15
- MTgyNGEwNzZhZTRjY2UxNTdiMzM4MDQ1MWUwOTYwMzQ2YjEzYjI=
13
+ NTY0ZjQzZmJjOWFlMGFjNDA5Nzc1NzdkYTk1YWJlMzYxYmExNmQ0NzY2NmYw
14
+ Nzc3M2M0ZjJhOGQ0Njc2MTZiZDIwNzdiMjZiMDUxZTEyMzEwMTJhM2FhNGJi
15
+ YjBjZTIyMzIxOTUxNGMxMDY4ZTkwNDA0MDczNDk0YTdhOGQ5NzI=
@@ -58,6 +58,12 @@ module PleskKit
58
58
  service_plan.analyse response[0], server
59
59
  end
60
60
 
61
+ def self.get_subscription_usage(subscription,plesk_sub_id,server)
62
+ packet = subscription.usage_pack shell, plesk_sub_id
63
+ response = transportation_for packet, server
64
+ subscription.analyse_usage response[0]
65
+ end
66
+
61
67
  def self.push_service_plan service_plan, server
62
68
  packet = service_plan.build_xml_for_add shell
63
69
  response = transportation_for packet, server
@@ -101,7 +101,7 @@ module PleskKit
101
101
  }
102
102
  xml.limit{
103
103
  xml.name('max_db')
104
- xml.value('10')
104
+ xml.value('-1')
105
105
  }
106
106
  xml.limit{
107
107
  xml.name('max_box')
@@ -7,10 +7,24 @@ module PleskKit
7
7
  belongs_to :service_plan
8
8
  before_create :provision_in_plesk
9
9
 
10
+ # TODO: doing checks before downgrades
11
+ # box is returned in stat, it shoulds how many are consumed
12
+ # real_size is returned in gen_info, it should show how big the entire subscription is... hopefully
10
13
 
14
+ #request should look like this:
15
+ #<packet version="1.6.3.0">
16
+ # <webspace>
17
+ # <get>
18
+ # <filter>
19
+ # <id>subscription_id.to_i</id>
20
+ # </filter>
21
+ # <gen_info>
22
+ # <stat/>
23
+ # </get>
24
+ # </webspace>
25
+ #</packet>
11
26
 
12
27
  def provision_in_plesk
13
-
14
28
  account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : raise(msg="no accounts?")))
15
29
  plan = PleskKit::ServicePlan.find_by_name self.plan_name
16
30
  self.service_plan_id = plan.id
@@ -32,6 +46,37 @@ module PleskKit
32
46
  end
33
47
  end
34
48
 
49
+ def downgradable?(to=new_plan)
50
+ account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : raise(msg="no accounts?")))
51
+ mbox_limit = new_plan.mailboxes
52
+ space_limit = new_plan.storage #needs to be in bytes or convert the next value to GB
53
+
54
+ plesk_subscription_identifier = PleskKit::Communicator.get_subscription_id(self)
55
+ usage = PleskKit::Communicator.get_subscription_usage(self,plesk_subscription_identifier, account.server)
56
+ if usage[0] < space_limit && usage[1] < mbox_limit
57
+ return true
58
+ else
59
+ return false
60
+ end
61
+ end
62
+
63
+
64
+ def usage_pack shell, plesk_sub_id
65
+ xml = shell
66
+ xml.instruct!
67
+ xml.packet(:version => '1.6.3.0') {
68
+ xml.webspace{
69
+ xml.get {
70
+ xml.filter{
71
+ xml.id(plesk_sub_id) # TODO!!!
72
+ }
73
+ xml.gen_info
74
+ xml.stat
75
+ }
76
+ }
77
+ }
78
+ end
79
+
35
80
  # update the plan name attr here before switching
36
81
  def switch_in_plesk
37
82
  account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : raise(msg="no accounts?")))
@@ -166,5 +211,21 @@ module PleskKit
166
211
  return sub_guid || true
167
212
  end
168
213
 
214
+ def analyse_usage response_string
215
+ xml = REXML::Document.new(response_string)
216
+ status = xml.root.elements['//status'].text if xml.root.elements['//status'].present?
217
+ space = ''
218
+ mbox = ''
219
+ if status == "error"
220
+ code = xml.root.elements['//errcode'].text
221
+ message = xml.root.elements['//errtext'].text
222
+ raise "#{code}: #{message}"
223
+ else
224
+ space = xml.root.elements['//real_size'].text if xml.root.elements['//real_size'].present?
225
+ mbox = xml.root.elements['//box'].text if xml.root.elements['//box'].present?
226
+ end
227
+ return [space,mbox]
228
+ end
229
+
169
230
  end
170
231
  end
@@ -1,3 +1,3 @@
1
1
  module PleskKit
2
- VERSION = "2.0.17"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plesk_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.17
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dionne Saunders