Пример #1
0
 def handle(self, request, data):
     #waiting api call
     type = data['res_type']
     api_mapping = {
         "volume": lambda: api.cinder.volume_type_list(request),
     }
     charging_key_id = data['charging_key']
     if type == "volume":
       resources = api_mapping[type]()
       for resource in resources:
         if resource.name == data['charging_key']:
           charging_key_id = resource.id
     price = {
              'res_type':data['res_type'],
              'charging_key': data['charging_key'],
              'unit_price': data['unit_price'],
              'time_based': (str(True)==data['time_based']),
              'charging_key_id': charging_key_id,
              'version': data['pricing_version']
              }
     try:
       cloudkitty_api.cloudkittyclient(request).common.pricing_infos.create(**price)
     except Exception:
       exceptions.handle(request, _('Fail to Create price.'))
     message = _('Price was successfully created.')
     messages.success(request, message)
     return True
Пример #2
0
    def handle(self, request, data):
        version = {
          'effective_billing_month': data['effective_billing_month']
        }

        try:
          cloudkitty_api.cloudkittyclient(request).common.pricing_vers.create(**version)
        except Exception:
          exceptions.handle(request, _('Fail to Create pricing version.'))
        message = _('Pricing version was successfully created.')
        messages.success(request, message)
        return True
Пример #3
0
 def handle(self, request, data):
     thresholds_mgr = api.cloudkittyclient(request).rating.hashmap
     threshold = {}
     for k, v in data.items():
         if v:
             threshold[k] = float(v) if isinstance(v, Decimal) else v
     return thresholds_mgr.create_threshold(**threshold)
Пример #4
0
 def handle(self, request, data):
     thresholds_mgr = api.cloudkittyclient(request).hashmap.thresholds
     threshold = {}
     for k, v in data.items():
         if v:
             threshold[k] = v
     return thresholds_mgr.create(**threshold)
Пример #5
0
 def handle(self, request, data):
     script_id = self.initial['script_id']
     LOG.info('Updating script with id %s' % (script_id))
     ck_client = api.cloudkittyclient(request)
     return ck_client.pyscripts.scripts.update(script_id=script_id,
                                               name=data['name'],
                                               data=data['script_data'])
Пример #6
0
 def handle(self, request, data):
     thresholds_mgr = api.cloudkittyclient(request).hashmap.thresholds
     threshold = {}
     for k, v in data.items():
         if v:
             threshold[k] = v
     return thresholds_mgr.create(**threshold)
Пример #7
0
 def handle(self, request, data):
     script_id = self.initial['script_id']
     LOG.info('Updating script with id %s' % (script_id))
     ck_client = api.cloudkittyclient(request)
     return ck_client.pyscripts.scripts.update(script_id=script_id,
                                               name=data['name'],
                                               data=data['script_data'])
Пример #8
0
 def handle(self, request, data):
     mapping_mgr = api.cloudkittyclient(request).hashmap.mappings
     mapping = {}
     for k, v in data.items():
         if v:
             mapping[k] = v
     return mapping_mgr.create(**mapping)
Пример #9
0
 def handle(self, request, data):
     mapping_mgr = api.cloudkittyclient(request).rating.hashmap
     mapping = {}
     for k, v in data.items():
         if v:
             mapping[k] = float(v) if isinstance(v, Decimal) else v
     return mapping_mgr.create_mapping(**mapping)
Пример #10
0
 def handle(self, request, data):
     thresholds_mgr = api.cloudkittyclient(request).rating.hashmap
     threshold = {}
     for k, v in data.items():
         if v:
             threshold[k] = float(v) if isinstance(v, Decimal) else v
     return thresholds_mgr.create_threshold(**threshold)
Пример #11
0
 def handle(self, request, data):
     mapping_mgr = api.cloudkittyclient(request).rating.hashmap
     mapping = {}
     for k, v in data.items():
         if v:
             mapping[k] = float(v) if isinstance(v, Decimal) else v
     return mapping_mgr.create_mapping(**mapping)
Пример #12
0
 def get(self, *args, **kwargs):
     service = api.cloudkittyclient(
         self.request).rating.hashmap.get_service(
             service_id=kwargs['service_id'])
     self.request.service_id = service['service_id']
     self.page_title = "Hashmap Service : %s" % service['name']
     return super(ServiceView, self).get(*args, **kwargs)
Пример #13
0
 def action(self, request, obj_id):
     client = api.cloudkittyclient(request)
     module = client.rating.get_module(module_id=obj_id)
     self.enabled = module.get('enabled', False)
     self.current_past_action = DISABLE if self.enabled else ENABLE
     client.rating.update_module(module_id=obj_id,
                                 enabled=(not self.enabled))
Пример #14
0
 def get(self, *args, **kwargs):
     group = api.cloudkittyclient(self.request).hashmap.groups.get(
         group_id=kwargs['group_id']
     )
     self.request.group_id = group.group_id
     self.page_title = "Hashmap Group : %s" % group.name
     return super(GroupView, self).get(*args, **kwargs)
Пример #15
0
    def allowed(self, request, pricing_version):
        try:
            pricing_infos = cloudkitty_api.cloudkittyclient(request).common.pricing_infos.list(pricing_version=pricing_version.version)
        except:
            pricing_infos = ['DELETE_DISALLOWD']

        return len(pricing_infos) == 0
Пример #16
0
def quote(request):
    pricing = 0.0
    if request.is_ajax():
        if request.method == 'POST':
            json_data = json.loads(request.body)

            def __update_quotation_data(element, service):
                if isinstance(element, dict):
                    element['service'] = service
                else:
                    for elem in element:
                        __update_quotation_data(elem, service)

            try:
                service = getattr(
                    settings, 'CLOUDKITTY_QUOTATION_SERVICE', 'instance')
                __update_quotation_data(json_data, service)
                pricing = float(api.cloudkittyclient(request)
                                .rating.get_quotation(res_data=json_data))
            except Exception:
                exceptions.handle(request,
                                  _('Unable to retrieve price.'))

    return http.HttpResponse(json.dumps(pricing),
                             content_type='application/json')
Пример #17
0
 def action(self, request, obj_id):
     client = api.cloudkittyclient(request)
     module = client.rating.get_module(module_id=obj_id)
     self.enabled = module.get('enabled', False)
     self.current_past_action = DISABLE if self.enabled else ENABLE
     client.rating.update_module(module_id=obj_id,
                                 enabled=(not self.enabled))
Пример #18
0
 def get_data(self):
     # Add data to the context here...
     modules = api.identify(
         api.cloudkittyclient(self.request).modules.list(),
         name=True
     )
     return modules
Пример #19
0
 def get(self, *args, **kwargs):
     service = api.cloudkittyclient(
         self.request).rating.hashmap.get_service(
         service_id=kwargs['service_id'])
     self.request.service_id = service['service_id']
     self.page_title = "Hashmap Service : %s" % service['name']
     return super(ServiceView, self).get(*args, **kwargs)
Пример #20
0
    def get_context_data(self, **kwargs):
        context = super(IndexView, self).get_context_data(**kwargs)
        context["organization"] = get_tenant_list(self.request)

        now = datetime.today()
        date_choice = [now]
        for i in range(1,12):
            now = self.back_months(now, 1)
            date_choice.append(now)
        context["dates"] = date_choice

        search_opts = self.get_filters({})
        for key,value in search_opts.iteritems():
            context[key] = value
        context["resource_type"] = context["resource_type"] or "total"

        #services_rate_list = api.cloudkittyclient(self.request).billings.list_services_cost("2015-10","f277f582888a4130a0546294697d9d3f")
        services_rate_list = api.cloudkittyclient(self.request).billings.list_services_cost(search_opts["billing_month"],
                                                                                          search_opts["total_tenant_id"])
        total_rate = {"service_id": "total", "rate":0, "unit": "total", "qty": 0}
        for rate in services_rate_list["servicesRate"]:
            total_rate["rate"] += rate["rate"]
            total_rate["qty"] += rate["qty"]
        services_rate_list["servicesRate"].insert(0, total_rate)
        context["services_rate_list"] = services_rate_list["servicesRate"]
        return context
Пример #21
0
 def get(self, *args, **kwargs):
     threshold = api.cloudkittyclient(self.request).hashmap.thresholds.get(
         threshold_id=kwargs['threshold_id']
     )
     self.request.threshold_id = threshold.threshold_id
     self.page_title = "Hashmap Threshold : %s" % threshold.threshold_id
     return super(FieldThresholdView, self).get(*args, **kwargs)
Пример #22
0
    def get_data(self, request, context, *args, **kwargs):
        group_id = kwargs.get("group_id")
        ck_client = api.cloudkittyclient(self.request)

        try:
            group = ck_client.hashmap.groups.get(group_id=group_id)
        except Exception:
            group = None

        try:
            mappings = ck_client.hashmap.mappings.findall(group_id=group_id)
        except Exception:
            mappings = []

        try:
            thresholds = ck_client.hashmap.thresholds.findall(
                group_id=group_id)
        except Exception:
            thresholds = []

        values = {
            "mappings": {"fields": [], "services": []},
            "thresholds": {"fields": [], "services": []}
            }
        for key, value in dict(
                mappings=mappings, thresholds=thresholds).items():
            for entry in value:
                if entry.service_id:
                    values[key]['services'].append(entry)
                else:
                    values[key]['fields'].append(entry)
        context.update(values)
        context['group'] = group
        return context
Пример #23
0
 def handle(self, request, data):
     name = data['name']
     LOG.info('Creating script with name %s' % (name))
     ck_client = api.cloudkittyclient(request)
     return ck_client.rating.pyscripts.create_script(
         name=name,
         data=data['script_data'])
Пример #24
0
 def get(self, *args, **kwargs):
     service = api.cloudkittyclient(self.request).hashmap.services.get(
         service_id=kwargs['service_id']
     )
     self.request.service_id = service.service_id
     self.page_title = "Hashmap Service : %s" % service.name
     return super(ServiceView, self).get(*args, **kwargs)
Пример #25
0
 def get(self, *args, **kwargs):
     field = api.cloudkittyclient(self.request).hashmap.fields.get(
         field_id=kwargs['field_id']
     )
     self.request.field_id = field.field_id
     self.page_title = "Hashmap Field : %s" % field.name
     return super(FieldView, self).get(*args, **kwargs)
Пример #26
0
 def handle(self, request, data):
     mapping_mgr = api.cloudkittyclient(request).hashmap.mappings
     mapping = {}
     for k, v in data.items():
         if v:
             mapping[k] = v
     return mapping_mgr.create(**mapping)
Пример #27
0
 def handle(self, request, data):
     if data['service_type'] == 'service':
         service = data['service']
     else:
         service = data['custom_service']
     services_mgr = api.cloudkittyclient(request).rating.hashmap
     LOG.info('Creating service with name %s' % (service))
     return services_mgr.create_service(name=service)
Пример #28
0
    def get_initial(self):
        client = api.cloudkittyclient(self.request)

        script = client.rating.pyscripts.get_script(
            script_id=self.kwargs['script_id'])
        self.initial = script
        self.initial['script_data'] = self.initial['data']
        return self.initial
Пример #29
0
    def get_initial(self):
        client = api.cloudkittyclient(self.request)

        script = client.rating.pyscripts.get_script(
            script_id=self.kwargs['script_id'])
        self.initial = script
        self.initial['script_data'] = self.initial['data']
        return self.initial
Пример #30
0
def get_pricing_versions(request):
  try:
    versions = cloudkitty_api.cloudkittyclient(request).common.pricing_vers.list()
    vers = [v.version for v in versions]
  except Exception:
    vers = []

  return HttpResponse(json.dumps({"versions": vers}), content_type='application/json')
Пример #31
0
    def get_pricing_versions_data(self):
        try:
            pricing_versions = cloudkitty_api.cloudkittyclient(self.request).common.pricing_vers.list()
        except Exception:
            pricing_versions = []
            exceptions.handle(self.request, _('Unable to retrieve pricing versions list.'))

        return pricing_versions
Пример #32
0
 def handle(self, request, data):
     mapping_mgr = api.cloudkittyclient(request).hashmap.mappings
     mapping = {}
     for k, v in data.items():
         if v:
             mapping[k] = v
     mapping['mapping_id'] = self.initial['mapping_id']
     return mapping_mgr.update(**mapping)
Пример #33
0
 def __init__(self, request, *args, **kwargs):
     super(BaseForm, self).__init__(request, *args, **kwargs)
     self.order_fields()
     groups = api.cloudkittyclient(request).hashmap.groups.list()
     groups = api.identify(groups)
     choices = [(group.id, group.name) for group in groups]
     choices.insert(0, (None, ' '))
     self.fields['group_id'].choices = choices
Пример #34
0
 def handle(self, request, data):
     threshold_mgr = api.cloudkittyclient(request).hashmap.thresholds
     threshold = {}
     for k, v in data.items():
         if v:
             threshold[k] = v
     threshold['threshold_id'] = self.initial['threshold_id']
     return threshold_mgr.update(**threshold)
Пример #35
0
 def handle(self, request, data):
     if data['service_type'] == 'service':
         service = data['service']
     else:
         service = data['custom_service']
     services_mgr = api.cloudkittyclient(request).hashmap.services
     LOG.info('Creating service with name %s' % (service))
     return services_mgr.create(name=service)
Пример #36
0
 def handle(self, request, data):
     threshold_mgr = api.cloudkittyclient(request).hashmap.thresholds
     threshold = {}
     for k, v in data.items():
         if v:
             threshold[k] = v
     threshold['threshold_id'] = self.initial['threshold_id']
     return threshold_mgr.update(**threshold)
Пример #37
0
 def handle(self, request, data):
     mapping_mgr = api.cloudkittyclient(request).hashmap.mappings
     mapping = {}
     for k, v in data.items():
         if v:
             mapping[k] = v
     mapping['mapping_id'] = self.initial['mapping_id']
     return mapping_mgr.update(**mapping)
Пример #38
0
 def get_data(self, request, context, *args, **kwargs):
     script_id = kwargs.get("script_id")
     try:
         script = api.cloudkittyclient(
             self.request).pyscripts.scripts.get(script_id=script_id)
     except Exception:
         script = None
     context['script'] = script
     return context
Пример #39
0
 def action(self, request, obj_id):
     module = api.cloudkittyclient(request).modules.get(module_id=obj_id)
     self.enabled = module.enabled
     if self.enabled:
         self.current_past_action = DISABLE
         module.disable()
     else:
         module.enable()
         self.current_past_action = ENABLE
Пример #40
0
 def _get_object(self, *args, **kwargs):
     pricing_id = self.kwargs['pricing_id']
     try:
         price = cloudkitty_api.cloudkittyclient(self.request).common.pricing_infos.get(pricing_info_id=pricing_id)
         return price
     except Exception:
         redirect = self.success_url
         msg = _('Unable to retrieve price details.')
         exceptions.handle(self.request, msg, redirect=redirect)
Пример #41
0
 def get_data(self, request, context, *args, **kwargs):
     script_id = kwargs.get("script_id")
     try:
         client = api.cloudkittyclient(self.request)
         script = client.rating.pyscripts.get_script(script_id=script_id)
     except Exception:
         script = None
     context['script'] = script
     return context
Пример #42
0
 def action(self, request, obj_id):
     module = api.cloudkittyclient(request).modules.get(module_id=obj_id)
     self.enabled = module.enabled
     if self.enabled:
         self.current_past_action = DISABLE
         module.disable()
     else:
         module.enable()
         self.current_past_action = ENABLE
 def get_context_data(self, request, **kwargs):
     today = datetime.datetime.today()
     day_start, day_end = calendar.monthrange(today.year, today.month)
     begin = "%4d-%02d-01T00:00:00" % (today.year, today.month)
     end = "%4d-%02d-%02dT23:59:59" % (today.year, today.month, day_end)
     client = api.cloudkittyclient(request)
     data = client.storage.dataframes.list(
         begin=begin, end=end, tenant_id=request.user.tenant_id)
     parsed_data = _do_this_month(data)
     return {'repartition_data': parsed_data}
Пример #44
0
 def delete(self, request, invoice_id):
     """
     Method: delete
     desc: Used to delete the invoice.
     params:
         self, request and invoice_id
     return: True/False
     """
     cloudkitty_conn = kittyapi.cloudkittyclient(request)
     cloudkitty_conn.reports.delete_invoice(invoice_id=invoice_id)
Пример #45
0
 def get_data(self, request, context, *args, **kwargs):
     module_id = kwargs.get("module_id")
     try:
         module = api.cloudkittyclient(
             self.request).modules.get(module_id=module_id)
     except Exception:
         module = None
     context['hotconfig'] = module._info['hot-config']
     context['module'] = module
     return context
Пример #46
0
 def get_data(self, request, context, *args, **kwargs):
     module_id = kwargs.get("module_id")
     try:
         module = api.cloudkittyclient(
             self.request).rating.get_module(module_id=module_id)
         context['hotconfig'] = module['hot-config']
         context['module'] = module
     except Exception:
         context['hotconfig'] = False
         context['module'] = {}
     return context
Пример #47
0
 def get_data(self):
     summary = api.cloudkittyclient(self.request).report.get_summary(
         tenant_id=self.request.user.tenant_id,
         groupby=['tenant_id', 'res_type'])['summary']
     summary = api.identify(summary, key='res_type', name=True)
     summary.append(
         TemplatizableDict({
             'id': 'ALL',
             'res_type': 'TOTAL',
             'name': 'ALL',
             'rate': sum([float(i['rate']) for i in summary]),
         }))
     return summary
Пример #48
0
    def __init__(self, request, *args, **kwargs):
        super(BaseForm, self).__init__(request, *args, **kwargs)
        self.order_fields()
        groups = api.cloudkittyclient(request).hashmap.groups.list()
        groups = api.identify(groups)
        choices = [(group.id, group.name) for group in groups]
        choices.insert(0, ('', ' '))
        self.fields['group_id'].choices = choices

        tenants, __ = api_keystone.keystone.tenant_list(request)
        choices_tenants = [(tenant.id, tenant.name) for tenant in tenants]
        choices_tenants.insert(0, (None, ' '))
        self.fields['tenant_id'].choices = choices_tenants
Пример #49
0
def add_groupname(request, datums):
    client = api.cloudkittyclient(request)
    groups = client.hashmap.groups.list()
    full_groups = OrderedDict([(str(group.group_id), group.name)
                               for group in groups])

    for datum in datums:
        if datum.group_id:
            if datum.group_id in full_groups:
                datum.group_name = full_groups[datum.group_id]
            else:
                group = client.hashmap.groups.get(group_id=datum.group_id)
                datum.group_name = group.name
Пример #50
0
    def get_context_data(self, **kwargs):
        context = super(ServiceView, self).get_context_data(**kwargs)
        manager = api.cloudkittyclient(self.request)
        service = manager.rating.hashmap.get_service(
            service_id=kwargs['service_id'])
        config = manager.info.get_config()
        period = None

        if service['name'] in config['metrics'].keys():
            period = config.get('period', 3600)

        context["service_period"] = period
        return context
Пример #51
0
def add_groupname(request, datums):
    client = api.cloudkittyclient(request)
    groups = client.rating.hashmap.get_group().get('groups', [])
    full_groups = OrderedDict([(str(group['group_id']), group['name'])
                               for group in groups])

    for datum in datums:
        if datum.get('group_id'):
            if datum['group_id'] in full_groups:
                datum['group_name'] = full_groups[datum['group_id']]
            else:
                group = client.rating.hashmap.get_group(
                    group_id=datum['group_id'])
                datum['group_name'] = group['name']
Пример #52
0
def quote(request):
    pricing = "0"
    if request.is_ajax():
        if request.method == 'POST':
            json_data = json.loads(request.body)
            try:
                pricing = decimal.Decimal(
                    api.cloudkittyclient(request).quotations.quote(json_data))
                pricing = pricing.normalize().to_eng_string()
            except Exception:
                exceptions.handle(request, _('Unable to retrieve price.'))

    return http.HttpResponse(json.dumps(pricing),
                             content_type='application/json')