Class: PleskKit::Subscription
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PleskKit::Subscription
- Defined in:
- app/models/plesk_kit/subscription.rb
Instance Method Summary collapse
- #analyse(response_string, customer = nil) ⇒ Object
- #analyse_for_id(response_string, customer = nil) ⇒ Object
- #id_pack(shell, domain_name) ⇒ Object
- #pack_this(shell, customer) ⇒ Object
- #provision_in_plesk ⇒ Object
-
#switch_in_plesk ⇒ Object
update the plan name attr here before switching.
- #switch_pack(shell, sub_guid, plesk_sub_id) ⇒ Object
- #sync_pack(shell, sub_guid) ⇒ Object
Instance Method Details
#analyse(response_string, customer = nil) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/models/plesk_kit/subscription.rb', line 142 def analyse response_string, customer = nil xml = REXML::Document.new(response_string) status = xml.root.elements['//status'].text if xml.root.elements['//status'].present? if status == "error" code = xml.root.elements['//errcode'].text = xml.root.elements['//errtext'].text raise "#{code}: #{}" else sub_guid = xml.root.elements['//guid'].text if xml.root.elements['//guid'].present? end return sub_guid || true # TODO save plesk_id? Probably not necessary as we have the customer login end |
#analyse_for_id(response_string, customer = nil) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/models/plesk_kit/subscription.rb', line 155 def analyse_for_id response_string, customer = nil xml = REXML::Document.new(response_string) status = xml.root.elements['//status'].text if xml.root.elements['//status'].present? sub_guid ='' if status == "error" code = xml.root.elements['//errcode'].text = xml.root.elements['//errtext'].text raise "#{code}: #{}" else sub_guid = xml.root.elements['//id'].text if xml.root.elements['//id'].present? end return sub_guid || true end |
#id_pack(shell, domain_name) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/plesk_kit/subscription.rb', line 111 def id_pack shell, domain_name xml = shell xml.instruct! xml.packet(:version => '1.6.3.5') { xml.webspace{ xml.get{ xml.filter{ xml.name(domain_name) } xml.dataset{ xml.gen_info } } } } end |
#pack_this(shell, customer) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/models/plesk_kit/subscription.rb', line 61 def pack_this shell, customer digits = customer.login.to_s.split('') xx = '' digits.each {|d|xx << (d.to_i + 65).chr} xml = shell xml.instruct! xml.packet(:version => '1.6.3.5') { xml.webspace { xml.add{ xml.gen_setup{ xml.name(self.name) xml.tag! 'owner-login', self.owner_login xml.ip_address(self.ip_address) } xml.hosting{ xml.vrt_hst{ xml.property{ xml.name('ftp_login') xml.value(xx.downcase) #rand(36**8).to_s(36) } xml.property{ xml.name('ftp_password') xml.value(customer.passwd) } xml.ip_address(self.ip_address) } } xml.tag! 'plan-name', self.plan_name } } } puts xml.target! return xml.target! end |
#provision_in_plesk ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/plesk_kit/subscription.rb', line 12 def provision_in_plesk account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : raise(msg="no accounts?"))) plan = PleskKit::ServicePlan.find_by_name self.plan_name self.service_plan_id = plan.id if plan.find_or_push(account.server).present? self.plan_name = self.plan_name self.ip_address = account.server.host self.owner_login = account.login self.name = self.name if account.class.to_s == 'PleskKit::ResellerAccount' self.reseller_account_id = account.id elsif account.class.to_s == 'PleskKit::CustomerAccount' self.customer_account_id = account.id end guid = PleskKit::Communicator.pack_and_play_with_subscription self, account PleskKit::Communicator.sync_subscription self, guid, account self.id else return false end end |
#switch_in_plesk ⇒ Object
update the plan name attr here before switching
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/models/plesk_kit/subscription.rb', line 36 def switch_in_plesk account = (customer_account_id.present? ? customer_account : (reseller_account_id.present? ? reseller_account : raise(msg="no accounts?"))) plan = PleskKit::ServicePlan.find_by_name self.plan_name puts "|=|plan = PleskKit::ServicePlan.find_by_name self.plan_name ||| #{plan.inspect}" puts plan puts plan_name puts '_-_-_' plesk_subscription_identifier = PleskKit::Communicator.get_subscription_id(self) puts "plesk_subscription_identifier #{plesk_subscription_identifier}" if plan.find_or_push(account.server).present? #guid = PleskKit::Communicator.pack_and_play_with_subscription self, account guid = PleskKit::Communicator.get_service_plan plan, account.server puts "|=| THE GUID IS #{guid}" puts "|=| about to start the switch cmd" PleskKit::Communicator.pack_and_switch_subscription(self, guid, plesk_subscription_identifier) puts "|=| about to start the get_subscription_guid cmd" sub_guid = PleskKit::Communicator.get_subscription_guid(self) puts "|=| about to sync up" PleskKit::Communicator.sync_subscription self, sub_guid, self.customer_account true else puts "could not find or push?" end end |
#switch_pack(shell, sub_guid, plesk_sub_id) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/models/plesk_kit/subscription.rb', line 96 def switch_pack shell, sub_guid, plesk_sub_id xml = shell xml.instruct! xml.packet(:version => '1.6.3.5') { xml.webspace{ xml.send(:"switch-subscription") { xml.filter{ xml.id(plesk_sub_id) # TODO!!! } xml.tag! 'plan-guid', sub_guid } } } end |
#sync_pack(shell, sub_guid) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/models/plesk_kit/subscription.rb', line 128 def sync_pack shell, sub_guid xml = shell xml.instruct! xml.packet(:version => '1.6.3.5') { xml.webspace{ xml.send(:"sync-subscription") { xml.filter{ xml.guid(sub_guid) } } } } end |