def create_subscriptions(account_number: int) -> Dict[str, mapping.SiteIndex]: """ :param account_number: :return: created subscription map """ new_subscription = defaultdict( lambda: mapping.SiteIndex(0, [mapping.SubscriptionId()]) ) dog_group = int( ONYMA.attribute.get_attribute( account_number, mapping.agreement.dog_group_id.onyma_key ) ) domain = int(ONYMA.function.group_to_domain(dog_group)) assert domain, "Cannot resolve domain ID!" new_subscription["ipoe_juniper"] = create_subscription_ipoe_juniper( account_number, domain ) new_subscription["juniper_mac"] = create_subscription_juniper_mac( account_number, domain ) new_subscription["wifi_tv"] = create_subscription_wifi_tv( account_number, domain ) new_subscription["cas"] = create_subscription_cas(account_number, domain) # create other subscriptions subscriptions = { "close_juniper_mac": mapping.subscription.juniper_mac, "docsis": mapping.subscription.docsis, "ipoe_mac": mapping.subscription.ipoe_mac, "iptv": mapping.subscription.iptv, # "juniper_mac": mapping.subscription.juniper_mac, "lk": mapping.subscription.lk, "mobile": mapping.subscription.mobile, "pppoe": mapping.subscription.pppoe, "qinq": mapping.subscription.qinq, "rent": mapping.subscription.rent, "vps": mapping.subscription.vps, } for subscription_name, subscription in subscriptions.items(): time.sleep(20) # waiting for create subscription site_id, subscription_id = create_new_subscription( account_number, domain, subscription, subscription_name ) new_subscription[subscription_name] = mapping.SiteIndex( site_id, [mapping.SubscriptionId(subscription_id, subscription)] ) return new_subscription
def create_subscription_juniper_mac( account_number: int, domain: int ) -> mapping.SiteIndex: site_id, subscription_id = create_new_subscription( account_number, domain, mapping.subscription.juniper_mac, mapping.subscription.juniper_mac.description, ) time.sleep(30) # это для того, чтобы события не попали в одну пачку! # juniper_mac: Tariff price factor factor = ONYMA.tariff.Tariff( site_id, subscription_id, mapping.subscription.Tariff.Wifire_100.value.tmid, mapping.subscription.Service.Internet.value.servid, 0.0, 0.25, ) ONYMA.tariff.set_price(factor) return mapping.SiteIndex( site_id, [ mapping.SubscriptionId( subscription_id, mapping.subscription.juniper_mac ) ], )
def create_subscription_ipoe_juniper( account_number: int, domain: int ) -> mapping.SiteIndex: site_id, subscription_id = create_new_subscription( account_number, domain, mapping.subscription.ipoe_juniper, mapping.subscription.ipoe_juniper.description, ) time.sleep(30) # это для того, чтобы события не попали в одну пачку! # ipoe_juniper: Tariff pers price price = ONYMA.tariff.Tariff( site_id, subscription_id, mapping.subscription.Tariff.Wifire_100.value.tmid, mapping.subscription.Service.Internet.value.servid, 100.0, 0.0, ) ONYMA.tariff.set_price(price) return mapping.SiteIndex( site_id, [ mapping.SubscriptionId( subscription_id, mapping.subscription.ipoe_juniper ) ], )
def create_subscription_cas( account_number: int, domain: int ) -> mapping.SiteIndex: attributes = generator.SubscriptionAttribute() site_id, site_name = create_new_site( account_number, domain, mapping.subscription.cas.description ) properties_cas = ONYMA.subscription.Subscription( site_id, mapping.subscription.cas.onyma_key, mapping.subscription.cas.tariff_id, attributes.make(mapping.subscription.cas), mapping.status.active.onyma_id, ) subscription_cas = ONYMA.subscription.create(properties_cas) properties_cas_pack = ONYMA.subscription.Subscription( properties_cas.site_id, mapping.subscription.cas_pack.onyma_key, mapping.subscription.cas_pack.tariff_id, properties_cas.attributes, properties_cas.status, ) subscription_cas_pack = ONYMA.subscription.create(properties_cas_pack) attach = { "SiteId": site_id, "SiteName": site_name, "SubscriptionId": [subscription_cas, subscription_cas_pack], } allure.attach( json.dumps(attach), attachment_type=allure.attachment_type.JSON ) return mapping.SiteIndex( site_id, [ mapping.SubscriptionId( subscription_cas, mapping.subscription.cas ), mapping.SubscriptionId( subscription_cas_pack, mapping.subscription.cas_pack ), ], )
def create_subscription_wifi_tv( account_number: int, domain: int ) -> mapping.SiteIndex: attributes = generator.SubscriptionAttribute() waiting_sec = 120 prefix = "_".join( ( mapping.subscription.wifi_tv.description, mapping.subscription.sale.description, ) ) site_id, site_name = create_new_site(account_number, domain, prefix) properties = ONYMA.subscription.Subscription( site_id, mapping.subscription.sale.onyma_key, mapping.subscription.sale.tariff_id, [{}], mapping.status.active.onyma_id, ) subscription_sale = ONYMA.subscription.create(properties) properties = ONYMA.subscription.Subscription( site_id, mapping.subscription.wifi_tv.onyma_key, mapping.subscription.wifi_tv.tariff_id, attributes.make(mapping.subscription.wifi_tv), mapping.status.active.onyma_id, ) subscription_wifi_tv_id = ONYMA.subscription.create(properties) attach = { "SiteId": site_id, "SiteName": site_name, "SubscriptionId": [subscription_wifi_tv_id, subscription_sale], } LOGGER.info(f"Waiting for {waiting_sec}sec to get HHID for WiFi TV.") time.sleep(waiting_sec) try: hhid = int( ONYMA.subscription.get_property_real( subscription_wifi_tv_id, mapping.subscription.hhid.onyma_key ) ) LOGGER.debug(f"HHID = {hhid}") except TypeError: LOGGER.error( "There is not HHID property in created WiFi TV subscription" ) hhid = 0 except ValueError: LOGGER.error( "There is not HHID property in created WiFi TV subscription" ) hhid = 0 if hhid: properties = ONYMA.subscription.Subscription( site_id, mapping.subscription.wifi_tv_pack.onyma_key, mapping.subscription.wifi_tv_pack.tariff_id, attributes.make( mapping.subscription.wifi_tv_pack, opt=[ { "prop": mapping.subscription.hhid.onyma_key, "val": hhid, "num": 0, } ], ), mapping.status.active.onyma_id, ) subscription_wifi_tv_pack_id = ONYMA.subscription.create(properties) attach["SubscriptionId"].append(subscription_wifi_tv_pack_id) allure.attach( str(subscription_wifi_tv_pack_id), attachment_type=allure.attachment_type.TEXT, ) else: subscription_wifi_tv_pack_id = 0 allure.attach( json.dumps(attach), attachment_type=allure.attachment_type.JSON ) return mapping.SiteIndex( site_id, [ mapping.SubscriptionId( subscription_sale, mapping.subscription.sale ), mapping.SubscriptionId( subscription_wifi_tv_id, mapping.subscription.wifi_tv ), mapping.SubscriptionId( subscription_wifi_tv_pack_id, mapping.subscription.wifi_tv_pack, ), ], )