Esempio n. 1
0
    def test_blade_server(self):
        encl = Device.create(sn='devicex',
                             model_type=DeviceType.blade_system,
                             model_name='device encl')
        dev = Device.create(sn='device',
                            model_type=DeviceType.blade_server,
                            model_name='device',
                            parent=encl)

        encl_dmg = DeviceModelGroup(name='DeviceModelGroup encl')
        encl_dmg.slots = 4
        encl_dmg.price = 65535
        encl_dmg.save()
        encl.model.group = encl_dmg
        encl.model.save()

        dmg = DeviceModelGroup(name='DeviceModelGroup')
        dmg.price = 1337
        dmg.slots = 1
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        pricing.device_update_cached(encl)
        pricing.device_update_cached(dev)

        self.assertEquals(dev.cached_price, 17720.75)
        self.assertEquals(encl.cached_price, 49151.25)
        self.assertEquals(dev.cached_price + encl.cached_price, 65535 + 1337)
Esempio n. 2
0
 def form_valid(self, form):
     model = form.save(commit=False)
     model.save_comment = form.cleaned_data.get('save_comment')
     model.save(priority=SAVE_PRIORITY, user=self.request.user)
     pricing.device_update_cached(model)
     messages.success(self.request, "Changes saved.")
     return HttpResponseRedirect(self.request.path)
Esempio n. 3
0
    def test_blade_server(self):
        encl = Device.create(sn='devicex', model_type=DeviceType.blade_system,
                             model_name='device encl')
        dev = Device.create(sn='device', model_type=DeviceType.blade_server,
                            model_name='device', parent=encl)

        encl_dmg = DeviceModelGroup(name='DeviceModelGroup encl')
        encl_dmg.slots = 4
        encl_dmg.price = 65535
        encl_dmg.save()
        encl.model.group = encl_dmg
        encl.model.save()

        dmg = DeviceModelGroup(name='DeviceModelGroup')
        dmg.price = 1337
        dmg.slots = 1
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        pricing.device_update_cached(encl)
        pricing.device_update_cached(dev)
        dev = Device.objects.get(id=dev.id)
        encl = Device.objects.get(id=encl.id)

        self.assertEquals(dev.cached_price, 17720.75)
        self.assertEquals(encl.cached_price, 49151.25)
        self.assertEquals(dev.cached_price + encl.cached_price, 65535 + 1337)
Esempio n. 4
0
 def form_valid(self, form):
     model = form.save(commit=False)
     model.save_comment = form.cleaned_data.get('save_comment')
     model.save(priority=SAVE_PRIORITY, user=self.request.user)
     pricing.device_update_cached(model)
     messages.success(self.request, "Changes saved.")
     return HttpResponseRedirect(self.request.path)
Esempio n. 5
0
 def perform_move(self, address, new_ip, new_hostname):
     old_ipaddress = IPAddress.objects.get(address=address)
     device = old_ipaddress.device
     mac = None
     for r in Record.objects.filter(
             db.Q(name=old_ipaddress.hostname) |
             db.Q(content=old_ipaddress.hostname) |
             db.Q(content=old_ipaddress.address)
         ):
         r.delete()
     for e in DHCPEntry.objects.filter(ip=old_ipaddress.address):
         mac = e.mac
         e.delete()
     old_ipaddress.device = None
     old_ipaddress.save()
     reset_dns(new_hostname, new_ip)
     new_ipaddress, c = IPAddress.concurrent_get_or_create(
             address=new_ip,
         )
     new_ipaddress.device = device
     new_ipaddress.hostname = new_hostname
     new_ipaddress.save()
     if mac:
         entry = DHCPEntry(ip=new_ip, mac=mac)
         entry.save()
     pricing.device_update_cached(device)
Esempio n. 6
0
 def update_cached(self, group):
     devices = set()
     for _class in (Storage, Memory, Processor, DiskShare, FibreChannel,
                    GenericComponent, OperatingSystem, Software):
         for component in _class.objects.filter(model__group=group):
             devices.add(component.device)
     for device in devices:
         pricing.device_update_cached(device)
Esempio n. 7
0
def bulk_update(devices, fields, data, user):
    for d in devices:
        if 'venture' in fields:
            d.venture_role = None
        for name in fields:
            setattr(d, name, data[name])
        d.save_comment = data.get('save_comment')
        d.save(priority=SAVE_PRIORITY, user=user)
        pricing.device_update_cached(d)
Esempio n. 8
0
def bulk_update(devices, fields, data, user):
    for d in devices:
        if 'venture' in fields:
            d.venture_role = None
        for name in fields:
            setattr(d, name, data[name])
        d.save_comment = data.get('save_comment')
        d.save(priority=SAVE_PRIORITY, user=user)
        pricing.device_update_cached(d)
Esempio n. 9
0
def run_job(ip_address):
    try:
        ip = IPAddress.objects.select_related().get(address=ip_address)
    except IPAddress.DoesNotExist:
        return
    device = ip.device
    if not device:
        return  # no device...
    pricing.device_update_cached(device)
Esempio n. 10
0
 def test_rack_server(self):
     dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                         model_name='device')
     dmg = DeviceModelGroup(name='DeviceModelGroup')
     dmg.price = 1337
     dmg.save()
     dev.model.group = dmg
     dev.model.save()
     pricing.device_update_cached(dev)
     dev = Device.objects.get(id=dev.id)
     self.assertEquals(dev.cached_price, 1337)
Esempio n. 11
0
 def test_rack_server(self):
     dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                         model_name='device')
     dmg = DeviceModelGroup(name='DeviceModelGroup')
     dmg.price = 1337
     dmg.save()
     dev.model.group = dmg
     dev.model.save()
     pricing.device_update_cached(dev)
     dev = Device.objects.get(id=dev.id)
     self.assertEquals(dev.cached_price, 1337)
Esempio n. 12
0
File: tests.py Progetto: viciu/ralph
    def test_rack_server(self):
        dev = Device.create(sn="device", model_type=DeviceType.rack_server, model_name="device")
        dmg = DeviceModelGroup(name="DeviceModelGroup")
        dmg.price = 1337
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        pricing.device_update_cached(dev)

        self.assertEquals(dev.cached_price, 1337)
Esempio n. 13
0
def cache_price(ip, **kwargs):
    ip = str(ip)
    try:
        ipaddr = IPAddress.objects.select_related().get(address=ip)
    except IPAddress.DoesNotExist:
        return False, 'no device.', kwargs
    dev = ipaddr.device
    if dev is None:
        return False, 'no device.', kwargs
    pricing.device_update_cached(dev)
    return True, 'price=%.2f cost=%.2f, name=%s' % (
        dev.cached_price or 0, dev.cached_cost or 0, dev.name), kwargs
Esempio n. 14
0
def cache_price(ip, **kwargs):
    ip = str(ip)
    try:
        ipaddr = IPAddress.objects.select_related().get(address=ip)
    except IPAddress.DoesNotExist:
        return False, 'no device.', kwargs
    dev = ipaddr.device
    if dev is None:
        return False, 'no device.', kwargs
    pricing.device_update_cached(dev)
    return True, 'price=%.2f cost=%.2f, name=%s' % (dev.cached_price or 0,
            dev.cached_cost or 0, dev.name), kwargs
Esempio n. 15
0
    def test_manual_price(self):
        dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                            model_name='device')
        dmg = DeviceModelGroup(name='DeviceModelGroup')
        dmg.price = 1337
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        dev.price = 238
        dev.save()
        pricing.device_update_cached(dev)

        self.assertEquals(dev.cached_price, 238)
Esempio n. 16
0
    def test_cost(self):
        dev = Device.create(sn="device", model_type=DeviceType.rack_server, model_name="device")
        dmg = DeviceModelGroup(name="DeviceModelGroup")
        dmg.price = 100
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        dev.margin_kind = MarginKind(name="50%", margin=50)
        dev.margin_kind.save()
        dev.deprecation_kind = DeprecationKind(name="10 months", months=10)
        dev.deprecation_kind.save()
        dev.save()
        pricing.device_update_cached(dev)
        self.assertEqual(dev.cached_cost, 15)
Esempio n. 17
0
    def test_manual_price(self):
        dev = Device.create(sn='device',
                            model_type=DeviceType.rack_server,
                            model_name='device')
        dmg = DeviceModelGroup(name='DeviceModelGroup')
        dmg.price = 1337
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        dev.price = 238
        dev.save()
        pricing.device_update_cached(dev)

        self.assertEquals(dev.cached_price, 238)
Esempio n. 18
0
    def test_cost(self):
        dev = Device.create(sn='device',
                            model_type=DeviceType.rack_server,
                            model_name='device')
        dmg = DeviceModelGroup(name='DeviceModelGroup')
        dmg.price = 100
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        dev.margin_kind = MarginKind(name='50%', margin=50)
        dev.margin_kind.save()
        dev.deprecation_kind = DeprecationKind(name='10 months', months=10)
        dev.deprecation_kind.save()
        dev.save()
        pricing.device_update_cached(dev)
        self.assertEqual(dev.cached_cost, 15)
Esempio n. 19
0
 def test_price_deprecation(self):
     # Device after deprecation period should have raw price = 0
     dev = Device.create(sn="device", model_type=DeviceType.rack_server, model_name="device")
     dmg = DeviceModelGroup(name="DeviceModelGroup")
     dmg.price = 100
     dmg.save()
     dev.model.group = dmg
     dev.purchase_date = datetime.today() - timedelta(11 * (365 / 12))
     dev.model.save()
     dev.margin_kind = MarginKind(name="50%", margin=50)
     dev.margin_kind.save()
     dev.deprecation_kind = DeprecationKind(name="10 months", months=10)
     dev.deprecation_kind.save()
     dev.save()
     pricing.device_update_cached(dev)
     self.assertEqual(get_device_raw_price(dev), 0)
     self.assertEqual(dev.cached_price, 0)
     self.assertEqual(dev.cached_cost, 0)
Esempio n. 20
0
 def test_price_deprecation_in_progress(self):
     # Device in deprecation period should have raw price >0 if price is set
     dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                         model_name='device')
     dmg = DeviceModelGroup(name='DeviceModelGroup')
     dmg.price = 100
     dmg.save()
     dev.model.group = dmg
     # currently first month in deprecation period
     dev.purchase_date = datetime.today() - timedelta(1 * (365 / 12))
     dev.model.save()
     dev.margin_kind = MarginKind(name='50%', margin=50)
     dev.margin_kind.save()
     dev.deprecation_kind = DeprecationKind(name='10 months', months=10)
     dev.deprecation_kind.save()
     dev.save()
     pricing.device_update_cached(dev)
     self.assertEqual(get_device_raw_price(dev), 100)
     self.assertEqual(dev.cached_cost, 15)
     self.assertEqual(dev.cached_price, 100)
Esempio n. 21
0
def bulk_update(devices, fields, data, user):
    for d in devices:
        if 'venture' in fields:
            d.venture_role = None

        field_classes = {
            'deprecation_kind': DeprecationKind,
            'venture': Venture,
            'venture_role': VentureRole,
            'margin_kind': MarginKind,
        }

        for name in fields:
            if name in field_classes:
                setattr(d, name, field_classes[name].objects.get(id=data[name]))
            else:
                setattr(d, name, data[name])
        d.save_comment = data.get('save_comment')
        d.save(priority=SAVE_PRIORITY, user=user)
        pricing.device_update_cached(d)
Esempio n. 22
0
 def test_price_deprecation(self):
     # Device after deprecation period should have raw price = 0
     dev = Device.create(sn='device',
                         model_type=DeviceType.rack_server,
                         model_name='device')
     dmg = DeviceModelGroup(name='DeviceModelGroup')
     dmg.price = 100
     dmg.save()
     dev.model.group = dmg
     dev.purchase_date = datetime.today() - timedelta(11 * (365 / 12))
     dev.model.save()
     dev.margin_kind = MarginKind(name='50%', margin=50)
     dev.margin_kind.save()
     dev.deprecation_kind = DeprecationKind(name='10 months', months=10)
     dev.deprecation_kind.save()
     dev.save()
     pricing.device_update_cached(dev)
     self.assertEqual(get_device_raw_price(dev), 0)
     self.assertEqual(dev.cached_price, 0)
     self.assertEqual(dev.cached_cost, 0)
Esempio n. 23
0
    def test_cost(self):
        dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                            model_name='device')
        dmg = DeviceModelGroup(name='DeviceModelGroup')
        dmg.price = 100
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        mk = MarginKind(name='50%', margin=50)
        mk.save()
        dev.margin_kind = mk
        dk = DeprecationKind(name='10 months', months=10)
        dk.save()
        dev.deprecation_kind = dk
        dev.save()
        self.assertEqual(pricing.get_device_cost(dev), 15)
        pricing.device_update_cached(dev)
        dev = Device.objects.get(id=dev.id)
        self.assertEqual(pricing.get_device_cost(dev), 15)
        self.assertEqual(dev.cached_cost, 15)
Esempio n. 24
0
 def test_price_deprecation(self):
     # Device after deprecation period should have raw price = 0
     dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                         model_name='device')
     dmg = DeviceModelGroup(name='DeviceModelGroup')
     dmg.price = 100
     dmg.save()
     dev.model.group = dmg
     dev.purchase_date = datetime.today() - timedelta(11 * (365 / 12))
     dev.model.save()
     mk = MarginKind(name='50%', margin=50)
     mk.save()
     dev.margin_kind = mk
     dk = DeprecationKind(name='10 months', months=10)
     dk.save()
     dev.deprecation_kind = dk
     dev.save()
     pricing.device_update_cached(dev)
     dev = Device.objects.get(id=dev.id)
     self.assertEqual(get_device_raw_price(dev), 0)
     self.assertEqual(dev.cached_price, 0)
     self.assertEqual(dev.cached_cost, 0)
Esempio n. 25
0
 def test_price_deprecation_in_progress(self):
     # Device in deprecation period should have raw price >0 if price is set
     dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                         model_name='device')
     dmg = DeviceModelGroup(name='DeviceModelGroup')
     dmg.price = 100
     dmg.save()
     dev.model.group = dmg
     # currently first month in deprecation period
     dev.purchase_date = datetime.today() - timedelta(1 * (365 / 12))
     dev.model.save()
     mk = MarginKind(name='50%', margin=50)
     mk.save()
     dev.margin_kind = mk
     dk = DeprecationKind(name='10 months', months=10)
     dk.save()
     dev.deprecation_kind = dk
     dev.save()
     pricing.device_update_cached(dev)
     dev = Device.objects.get(id=dev.id)
     self.assertEqual(get_device_raw_price(dev), 100)
     self.assertEqual(dev.cached_cost, 15)
     self.assertEqual(dev.cached_price, 100)
Esempio n. 26
0
 def update_cached(self, group):
     for device in Device.objects.filter(model__group=group):
         pricing.device_update_cached(device)
Esempio n. 27
0
def run_job(ip, **kwargs):
    device = ip.device
    if not device:
        return  # no device...
    pricing.device_update_cached(device)