Example #1
0
                    unit_price += p * sub['quantity']

        # Create an order for this router
        self.create_order(order_id, unit_price, unit, message, state=state)

        # Notify master
        remarks = 'Router Has Been Created.'
        action_time = message['timestamp']
        if state:
            self.resource_created_again(order_id, action_time, remarks)
        else:
            self.resource_created(order_id, action_time, remarks)


services.register_class(ks_client,
                        'network',
                        const.RESOURCE_ROUTER,
                        RouterCreateEnd)


class RouterDeleteEnd(RouterNotificationBase):
    """Handle the event that router be deleted
    """
    event_types = ['router.delete.end']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
                 message['event_type'],
                 message['payload']['router_id'])

        # Get the order of this resource
        resource_id = message['payload']['router_id']
Example #2
0
    def get_unit_price(self, order_id, message, status, cron_time=None):
        unit_price = 0

        # Create subscriptions for this order
        for ext in self.product_items.extensions:
            if ext.name.startswith(status):
                unit_price += ext.obj.get_unit_price(order_id, message)

        return unit_price

    def change_unit_price(self, message, status, order_id):
        quantity = message['payload']['size']
        self.change_order_unit_price(order_id, quantity, status)


services.register_class(ks_client, 'share', const.RESOURCE_SHARE,
                        ShareCreateEnd)


class ShareDeleteEnd(ShareNotificationBase):
    """Handle the event that volume be deleted
    """
    event_types = ['share.delete.end']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
                 message['event_type'], message['payload']['share_id'])

        # Get the order of this resource
        resource_id = message['payload']['share_id']
        order = self.get_order_by_resource_id(resource_id)
Example #3
0
        # Create subscriptions for this order
        for ext in self.product_items.extensions:
            if ext.name.startswith(status):
                unit_price += ext.obj.get_unit_price(order_id, message)

        return unit_price

    def change_unit_price(self, message, status, order_id):
        payload = get_payload(message)
        quantity = pricing.rate_limit_to_unit(payload['rate_limit'])
        self.change_order_unit_price(order_id, quantity, status)


services.register_class(ks_client,
                        'network',
                        const.RESOURCE_FLOATINGIP,
                        FloatingIpCreateEnd)

services.register_class(ks_client,
                        'network',
                        const.RESOURCE_FLOATINGIPSET,
                        FloatingIpCreateEnd)


class FloatingIpResizeEnd(FloatingIpNotificationBase):
    """Handle the events that floating ip be changed
    """
    event_types = [
        EVENT_FLOATINGIP_RESIZE_END,
        EVENT_FLOATINGIPSET_RESIZE_END,
    ]
Example #4
0
                    unit_price += p * sub['quantity']

        # Create an order for this instance
        self.create_order(order_id, unit_price, unit, message, state=state)

        # Notify master
        remarks = 'Alarm Has Been Created.'
        action_time = message['timestamp']
        if state:
            self.resource_created_again(order_id, action_time, remarks)
        else:
            self.resource_created(order_id, action_time, remarks)


services.register_class(ks_client,
                        'metering',
                        const.RESOURCE_ALARM,
                        AlarmCreateEnd)


class AlarmOnOffEnd(AlarmNotificationBase):
    """Handle the events that instances be stopped, for now,
    it will only handle one product: volume.size.
    """

    #NOTE(suo): 'compute.instance.shutdown2.end' is sent out
    #           by soft shutdown operation
    event_types = ['alarm.on/off']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
                 message['event_type'],
Example #5
0
        unit_price = 0

        # Create subscriptions for this order
        for ext in self.product_items.extensions:
            if ext.name.startswith(status):
                unit_price += ext.obj.get_unit_price(order_id, message)

        return unit_price

    def change_unit_price(self, message, status, order_id):
        quantity = message['payload']['size']
        self.change_order_unit_price(order_id, quantity, status)


services.register_class(ks_client,
                        'volume',
                        const.RESOURCE_VOLUME,
                        VolumeCreateEnd)


class VolumeResizeEnd(VolumeNotificationBase):
    """Handle the events that volume be changed
    """
    event_types = ['volume.resize.end']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
                 message['event_type'],
                 message['payload']['volume_id'])

        # Get the order of this resource
        resource_id = message['payload']['volume_id']
Example #6
0
                    unit_price += p * sub['quantity']

        # Create an order for this instance
        self.create_order(order_id, unit_price, unit, message, state=state)

        # Notify master
        remarks = 'Image Has Been Created.'
        action_time = message['timestamp']
        if state:
            self.resource_created_again(order_id, action_time, remarks)
        else:
            self.resource_created(order_id, action_time, remarks)


services.register_class(ks_client,
                        'image',
                        const.RESOURCE_IMAGE,
                        ImageCreateEnd)


class ImageDeleteEnd(ImageNotificationBase):
    """Handle the event that snapthot be deleted
    """
    event_types = ['image.delete']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
                 message['event_type'], message['payload']['id'])

        # Get the order of this resource
        resource_id = message['payload']['id']
        order = self.get_order_by_resource_id(resource_id)
Example #7
0
                    p = gringutils._quantize_decimal(sub['unit_price'])
                    unit_price += p * sub['quantity']

        # Create an order for this router
        self.create_order(order_id, unit_price, unit, message, state=state)

        # Notify master
        remarks = 'Router Has Been Created.'
        action_time = message['timestamp']
        if state:
            self.resource_created_again(order_id, action_time, remarks)
        else:
            self.resource_created(order_id, action_time, remarks)


services.register_class(ks_client, 'network', const.RESOURCE_ROUTER,
                        RouterCreateEnd)


class RouterDeleteEnd(RouterNotificationBase):
    """Handle the event that router be deleted
    """
    event_types = ['router.delete.end']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
                 message['event_type'], message['payload']['router_id'])

        # Get the order of this resource
        resource_id = message['payload']['router_id']
        order = self.get_order_by_resource_id(resource_id)
Example #8
0
                    p = gringutils._quantize_decimal(sub["unit_price"])
                    unit_price += p * sub["quantity"]

        # Create an order for this instance
        self.create_order(order_id, unit_price, unit, message, state=state)

        # Notify master
        remarks = "Image Has Been Created."
        action_time = message["timestamp"]
        if state:
            self.resource_created_again(order_id, action_time, remarks)
        else:
            self.resource_created(order_id, action_time, remarks)


services.register_class(ks_client, "image", const.RESOURCE_IMAGE, ImageCreateEnd)


class ImageDeleteEnd(ImageNotificationBase):
    """Handle the event that snapthot be deleted
    """

    event_types = ["image.delete"]

    def process_notification(self, message):
        LOG.warn("Do action for event: %s, resource_id: %s", message["event_type"], message["payload"]["id"])

        # Get the order of this resource
        resource_id = message["payload"]["id"]
        order = self.get_order_by_resource_id(resource_id)
Example #9
0
                    p = gringutils._quantize_decimal(sub['unit_price'])
                    unit_price += p * sub['quantity']

        # Create an order for this instance
        self.create_order(order_id, unit_price, unit, message, state=state)

        # Notify master
        remarks = 'Alarm Has Been Created.'
        action_time = message['timestamp']
        if state:
            self.resource_created_again(order_id, action_time, remarks)
        else:
            self.resource_created(order_id, action_time, remarks)


services.register_class(ks_client, 'metering', const.RESOURCE_ALARM,
                        AlarmCreateEnd)


class AlarmOnOffEnd(AlarmNotificationBase):
    """Handle the events that instances be stopped, for now,
    it will only handle one product: volume.size.
    """

    #NOTE(suo): 'compute.instance.shutdown2.end' is sent out
    #           by soft shutdown operation
    event_types = ['alarm.on/off']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
                 message['event_type'], message['payload']['alarm_id'])
Example #10
0
        # charge account
        try:
            type = 'bonus'
            come_from = 'system'
            bonus = message['payload'].get('bonus', cfg.CONF.waiter.user_initial_balance)
            if float(bonus) > 0:
                self.charge_account(user_id, bonus, type, come_from)
        except Exception:
            LOG.exception('Fail to charge %s to account %s' % (bonus, user_id))
            raise exception.AccountChargeFailed(value=bonus, user_id=user_id)

        LOG.info('Create account %s for the domain %s successfully' % (user_id, domain_id))


services.register_class(ks_client,
                        'identity',
                        const.RESOURCE_USER,
                        UserCreatedEnd)


class ProjectCreatedEnd(RegisterNotificationBase):
    """Handle the event that project be created"""

    event_types = ['identity.project.create']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, project_id: %s',
                 message['event_type'],
                 message['payload']['project_id'])
        try:
            user_id = message['payload']['billing_owner_id']
            project_id = message['payload']['project_id']
Example #11
0
                    unit_price += p * sub['quantity']

        # Create an order for this instance
        self.create_order(order_id, unit_price, unit, message, state=state)

        # Notify master
        remarks = 'Snapshot Has Been Created.'
        action_time = message['timestamp']
        if state:
            self.resource_created_again(order_id, action_time, remarks)
        else:
            self.resource_created(order_id, action_time, remarks)


services.register_class(ks_client,
                        'volume',
                        const.RESOURCE_SNAPSHOT,
                        SnapshotCreateEnd)


class SnapshotDeleteEnd(SnapshotNotificationBase):
    """Handle the event that snapthot be deleted
    """
    event_types = ['snapshot.delete.end']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
                 message['event_type'],
                 message['payload']['snapshot_id'])

        # Get the order of this resource
        resource_id = message['payload']['snapshot_id']
Example #12
0
        # Create subscriptions for this order
        for ext in self.product_items.extensions:
            if ext.name.startswith(status):
                unit_price += ext.obj.get_unit_price(order_id, message)

        return unit_price

    def change_unit_price(self, message, status, order_id):
        payload = get_payload(message)
        quantity = pricing.rate_limit_to_unit(payload['rate_limit'])
        self.change_order_unit_price(order_id, quantity, status)


services.register_class(ks_client,
                        'network',
                        const.RESOURCE_FLOATINGIP,
                        FloatingIpCreateEnd)

services.register_class(ks_client,
                        'network',
                        const.RESOURCE_FLOATINGIPSET,
                        FloatingIpCreateEnd)


class FloatingIpResizeEnd(FloatingIpNotificationBase):
    """Handle the events that floating ip be changed
    """
    event_types = [
        EVENT_FLOATINGIP_RESIZE_END,
        EVENT_FLOATINGIPSET_RESIZE_END,
    ]
Example #13
0
        unit_price = 0

        # Create subscriptions for this order
        for ext in self.product_items.extensions:
            if ext.name.startswith(status):
                unit_price += ext.obj.get_unit_price(order_id, message)

        return unit_price

    def change_unit_price(self, message, status, order_id):
        quantity = message['payload']['size']
        self.change_order_unit_price(order_id, quantity, status)


services.register_class(ks_client,
                        'volume',
                        const.RESOURCE_VOLUME,
                        VolumeCreateEnd)


class VolumeResizeEnd(VolumeNotificationBase):
    """Handle the events that volume be changed
    """
    event_types = ['volume.resize.end']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
                 message['event_type'],
                 message['payload']['volume_id'])

        # Get the order of this resource
        resource_id = message['payload']['volume_id']
Example #14
0
        return unit_price

    def change_unit_price(self, message, status, order_id):
        """Just change the unit price that may changes, so we only consider the flavor"""
        instance_type = message['payload']['instance_type']

        product_name = '%s:%s' % (const.PRODUCT_INSTANCE_TYPE_PREFIX,
                                  instance_type)
        service = const.SERVICE_COMPUTE
        region_id = cfg.CONF.region_name

        self.change_flavor_unit_price(order_id, product_name, service,
                                      region_id, status)


services.register_class(ks_client, 'compute', const.RESOURCE_INSTANCE,
                        InstanceCreateEnd)


class InstanceStopEnd(ComputeNotificationBase):
    """Handle the events that instances be stopped, for now,
    it will only handle one product: volume.size.
    """

    # NOTE(suo): 'compute.instance.shutdown2.end' is sent out
    # by soft shutdown operation
    event_types = [
        'compute.instance.power_off.end', 'compute.instance.shutdown2.end'
    ]

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
Example #15
0
            return unit_price

        # Create subscriptions for this order
        for ext in self.product_items.extensions:
            if ext.name.startswith(status):
                unit_price += ext.obj.get_unit_price(order_id, message)

        return unit_price

    def change_unit_price(self, message, status, order_id):
        quantity = int(message['payload']['listener']['connection_limit']) / 1000
        self.change_order_unit_price(order_id, quantity, status)


services.register_class(ks_client,
                        'network',
                        const.RESOURCE_LISTENER,
                        ListenerCreateEnd)


class ListenerUpdateEnd(ListenerNotificationBase):
    """Handle the events that listener's connection_limit or admin_state_up
    be changed
    """
    event_types = ['listener.update.end']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
                 message['event_type'],
                 message['payload']['listener']['id'])

        quantity = int(message['payload']['listener']['connection_limit']) / 1000
Example #16
0
        unit_price = 0

        # Create subscriptions for this order
        for ext in self.product_items.extensions:
            if ext.name.startswith(status):
                unit_price += ext.obj.get_unit_price(order_id, message)

        return unit_price

    def change_unit_price(self, message, status, order_id):
        quantity = message['payload']['size']
        self.change_order_unit_price(order_id, quantity, status)


services.register_class(ks_client,
                        'share',
                        const.RESOURCE_SHARE,
                        ShareCreateEnd)


class ShareDeleteEnd(ShareNotificationBase):
    """Handle the event that volume be deleted
    """
    event_types = ['share.delete.end']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, resource_id: %s',
                 message['event_type'],
                 message['payload']['share_id'])

        # Get the order of this resource
        resource_id = message['payload']['share_id']
Example #17
0
                unit_price += ext.obj.get_unit_price(order_id, message)

        return unit_price

    def change_unit_price(self, message, status, order_id):
        """Just change the unit price that may changes, so we only consider the flavor"""
        instance_type = message["payload"]["instance_type"]

        product_name = "%s:%s" % (const.PRODUCT_INSTANCE_TYPE_PREFIX, instance_type)
        service = const.SERVICE_COMPUTE
        region_id = cfg.CONF.region_name

        self.change_flavor_unit_price(order_id, product_name, service, region_id, status)


services.register_class(ks_client, "compute", const.RESOURCE_INSTANCE, InstanceCreateEnd)


class InstanceStopEnd(ComputeNotificationBase):
    """Handle the events that instances be stopped, for now,
    it will only handle one product: volume.size.
    """

    # NOTE(suo): 'compute.instance.shutdown2.end' is sent out
    # by soft shutdown operation
    event_types = ["compute.instance.power_off.end", "compute.instance.shutdown2.end"]

    def process_notification(self, message):
        LOG.warn("Do action for event: %s, resource_id: %s", message["event_type"], message["payload"]["instance_id"])

        # Get the order of this resource
Example #18
0
        try:
            type = 'bonus'
            come_from = 'system'
            bonus = message['payload'].get(
                'bonus', cfg.CONF.waiter.user_initial_balance)
            if float(bonus) > 0:
                self.charge_account(user_id, bonus, type, come_from)
        except Exception:
            LOG.exception('Fail to charge %s to account %s' % (bonus, user_id))
            raise exception.AccountChargeFailed(value=bonus, user_id=user_id)

        LOG.info('Create account %s for the domain %s successfully' %
                 (user_id, domain_id))


services.register_class(ks_client, 'identity', const.RESOURCE_USER,
                        UserCreatedEnd)


class ProjectCreatedEnd(RegisterNotificationBase):
    """Handle the event that project be created"""

    event_types = ['identity.project.create']

    def process_notification(self, message):
        LOG.warn('Do action for event: %s, project_id: %s',
                 message['event_type'], message['payload']['project_id'])
        try:
            user_id = message['payload']['billing_owner_id']
            project_id = message['payload']['project_id']
            domain_id = message['payload']['domain_id']
            consumption = '0'