Ejemplo n.º 1
0
 def create_device(self):
     venture = Venture(name='TestVenture', symbol='testventure')
     venture.save()
     Device.create(
         sn='000000001',
         model_name='test_model',
         model_type=DeviceType.unknown,
         priority=SAVE_PRIORITY,
         venture=venture,
         name='test_device',
     )
     return Device.objects.get(sn='000000001')
Ejemplo n.º 2
0
 def create_device(self):
     venture = Venture(name='TestVenture', symbol='testventure')
     venture.save()
     Device.create(
         sn='000000001',
         model_name='test_model',
         model_type=DeviceType.unknown,
         priority=SAVE_PRIORITY,
         venture=venture,
         name='test_device',
     )
     return Device.objects.get(sn='000000001')
Ejemplo n.º 3
0
def device_from_data(
    data, save_priority=SAVE_PRIORITY, user=None, warnings=[]
):
    """
    Create or find a device based on the provided scan data.
    """

    sn = data.get('serial_number')
    ethernets = [('', mac, None) for mac in data.get('mac_addresses', [])]
    model_name = data.get('model_name')
    model_type = _get_choice_by_name(
        DeviceType,
        data.get('type', 'unknown')
    )
    device = Device.create(
        sn=sn,
        ethernets=ethernets,
        model_name=model_name,
        model_type=model_type,
    )
    set_device_data(
        device, data, save_priority=save_priority, warnings=warnings
    )
    device.save(priority=save_priority, user=user)
    return device
Ejemplo n.º 4
0
 def create_stock_device(self):
     if self.type != AssetType.data_center.id:
         return
     try:
         if self.sn:
             device = Device.objects.get(sn=self.sn)
         elif self.barcode:
             device = Device.objects.get(barcode=self.barcode)
         else:
             raise UserWarning("No barcode and no sn")
     except Device.DoesNotExist:
         try:
             venture = Venture.objects.get(name='Stock')
         except Venture.DoesNotExist:
             venture = Venture(name='Stock', symbol='stock')
             venture.save()
         device = Device.create(
             sn=self.sn or 'bc-' + self.barcode,
             barcode=self.barcode,
             model_name='Unknown',
             model_type=DeviceType.unknown,
             priority=SAVE_PRIORITY,
             venture=venture,
             name='Unknown',
         )
     if self.device_info:
         self.device_info.ralph_device_id = device
         self.device_info.save()
Ejemplo n.º 5
0
 def setUp(self):
     self.asset = AssetFactory(
         invoice_date=datetime.date(2012, 11, 28),
         support_period=1,
         deprecation_rate=100,
     )
     self.asset.device_info.ralph_device_id = 666
     self.asset.device_info.save()
     self.asset2 = AssetFactory(
         invoice_date=datetime.date(2012, 11, 28),
         support_period=120,
         deprecation_rate=50,
     )
     self.asset2.device_info.ralph_device_id = 667
     self.asset2.device_info.save()
     self.asset3 = AssetFactory(
         invoice_date=datetime.date(2012, 11, 28),
         support_period=120,
         deprecation_rate=50,
         force_deprecation=True,
     )
     self.asset_depr_date = AssetFactory(
         sn='1111-1111-1111-1114',
         invoice_date=datetime.date(2012, 11, 28),
         support_period=120,
         deprecation_rate=50,
         deprecation_end_date=datetime.date(2014, 12, 15),
     )
     dev1 = Device.create(
         [('1', 'sda', 0)],
         model_name='xxx',
         model_type=DeviceType.rack_server,
         allow_stub=1,
     )
     dev1.id = 666
     dev1.save()
     dev2 = Device.create(
         [('1', 'dawdwad', 0)],
         model_name='Unknown',
         model_type=DeviceType.unknown,
         allow_stub=1,
     )
     dev2.id = 667
     dev2.save()
Ejemplo n.º 6
0
 def setUp(self):
     self.asset = AssetFactory(
         invoice_date=datetime.date(2012, 11, 28),
         support_period=1,
         deprecation_rate=100,
     )
     self.asset.device_info.ralph_device_id = 666
     self.asset.device_info.save()
     self.asset2 = AssetFactory(
         invoice_date=datetime.date(2012, 11, 28),
         support_period=120,
         deprecation_rate=50,
     )
     self.asset2.device_info.ralph_device_id = 667
     self.asset2.device_info.save()
     self.asset3 = AssetFactory(
         invoice_date=datetime.date(2012, 11, 28),
         support_period=120,
         deprecation_rate=50,
         force_deprecation=True,
     )
     self.asset_depr_date = AssetFactory(
         sn='1111-1111-1111-1114',
         invoice_date=datetime.date(2012, 11, 28),
         support_period=120,
         deprecation_rate=50,
         deprecation_end_date=datetime.date(2014, 12, 15),
     )
     self.dev1 = Device.create(
         [('1', 'sda', 0)],
         model_name='xxx',
         model_type=DeviceType.rack_server,
         allow_stub=1,
     )
     self.dev1.id = 666
     self.dev1.save()
     dev2 = Device.create(
         [('1', 'dawdwad', 0)],
         model_name='Unknown',
         model_type=DeviceType.unknown,
         allow_stub=1,
     )
     dev2.id = 667
     dev2.save()
Ejemplo n.º 7
0
 def create_device(self, sn, barcode):
     venture, _ = Venture.objects.get_or_create(name='TestVenture',
                                                symbol='testventure')
     return Device.create(
         sn=sn,
         barcode=barcode,
         model_name='test_model',
         model_type=DeviceType.unknown,
         priority=SAVE_PRIORITY,
         venture=venture,
         name='test_device',
     )
Ejemplo n.º 8
0
    def setUp(self):
        self.client = login_as_su()

        self.deprecation_kind = DeprecationKind(months=24, remarks='Default')
        self.deprecation_kind.save()

        self.margin = MarginKind(margin=100, remarks='100%')
        self.margin.save()

        self.venture = Venture(name='VenureName')
        self.venture.save()

        self.role = VentureRole(venture=self.venture, name='VentureRole')
        self.role.save()

        self.device = Device.create(
            sn=DEVICE['sn'],
            barcode=DEVICE['barcode'],
            remarks=DEVICE['remarks'],
            model_name=DEVICE['model_name'],
            model_type=DeviceType.unknown,
            rack=DEVICE['rack'],
            position=DEVICE['position'],
            dc=DATACENTER,
        )
        self.device.name = DEVICE['name']
        self.device.save()

        self.device2 = Device.create(
            sn=DEVICE2['sn'],
            barcode=DEVICE2['barcode'],
            remarks=DEVICE2['remarks'],
            model_name=DEVICE2['model_name'],
            model_type=DeviceType.unknown,
            rack=DEVICE2['rack'],
            position=DEVICE2['position'],
            dc=DATACENTER,
        )
        self.device2.name = DEVICE2['name']
        self.device2.save()
Ejemplo n.º 9
0
 def create_device(self, sn, barcode):
     venture, _ = Venture.objects.get_or_create(
         name='TestVenture',
         symbol='testventure'
     )
     return Device.create(
         sn=sn,
         barcode=barcode,
         model_name='test_model',
         model_type=DeviceType.unknown,
         priority=SAVE_PRIORITY,
         venture=venture,
         name='test_device',
     )
Ejemplo n.º 10
0
def device_from_data(data):
    """
    Create or find a device based on the provided scan data.
    """

    sn = data.get('serial_number')
    ethernets = [('', mac, None) for mac in data.get('mac_addresses', [])]
    model_name = data.get('model_name')
    model_type = DeviceType.from_name(data.get('type', 'unknown').lower())
    device = Device.create(
        sn=sn,
        ethernets=ethernets,
        model_name=model_name,
        model_type=model_type,
    )
    set_device_data(device, data)
    device.save()
    return device
Ejemplo n.º 11
0
 def create_stock_device(self):
     if not self.type == AssetType.data_center:
         return
     if not self.device_info.ralph_device_id:
         try:
             venture = Venture.objects.get(name='Stock')
         except Venture.DoesNotExist:
             venture = Venture(name='Stock', symbol='stock')
             venture.save()
         device = Device.create(
             sn=self.sn or 'bc-' + self.barcode,
             barcode=self.barcode,
             model_name='Unknown',
             model_type=DeviceType.unknown,
             priority=SAVE_PRIORITY,
             venture=venture,
             name='Unknown',
         )
         self.device_info.ralph_device_id = device.id
         self.device_info.save()
Ejemplo n.º 12
0
 def create_stock_device(self):
     if not self.type == AssetType.data_center:
         return
     if not self.device_info.ralph_device_id:
         try:
             venture = Venture.objects.get(name='Stock')
         except Venture.DoesNotExist:
             venture = Venture(name='Stock', symbol='stock')
             venture.save()
         device = Device.create(
             sn=self.sn or 'bc-' + self.barcode,
             barcode=self.barcode,
             model_name='Unknown',
             model_type=DeviceType.unknown,
             priority=SAVE_PRIORITY,
             venture=venture,
             name='Unknown',
         )
         self.device_info.ralph_device_id = device.id
         self.device_info.save()
Ejemplo n.º 13
0
Archivo: data.py Proyecto: ar4s/ralph
def device_from_data(data, save_priority=SAVE_PRIORITY, user=None):
    """
    Create or find a device based on the provided scan data.
    """

    sn = data.get('serial_number')
    ethernets = [('', mac, None) for mac in data.get('mac_addresses', [])]
    model_name = data.get('model_name')
    model_type = DeviceType.from_name(
        '_'.join(
            data.get('type', 'unknown',).split(),
        ).lower(),
    )
    device = Device.create(
        sn=sn,
        ethernets=ethernets,
        model_name=model_name,
        model_type=model_type,
    )
    set_device_data(device, data, save_priority=save_priority)
    device.save(priority=save_priority, user=user)
    return device
Ejemplo n.º 14
0
 def create_stock_device(self):
     if not self.type == AssetType.data_center:
         return
     if not self.device_info.ralph_device_id:
         try:
             venture = Venture.objects.get(name='Stock')
         except Venture.DoesNotExist:
             venture = Venture(name='Stock', symbol='stock')
             venture.save()
         device = Device.create(
             sn=self.sn or 'bc-' + self.barcode,
             barcode=self.barcode,
             model_name='Unknown',
             model_type=DeviceType.unknown,
             priority=SAVE_PRIORITY,
             venture=venture,
         )
         device.name = getattr(self.model, 'name', 'Unknown')
         device.remarks = self.order_no or ''
         device.dc = getattr(self.warehouse, 'name', '')
         device.save()
         self.device_info.ralph_device_id = device.id
         self.device_info.save()
Ejemplo n.º 15
0
 def create_stock_device(self):
     if not self.type_is_data_center:
         return
     if not self.device_info.ralph_device_id:
         try:
             venture = Venture.objects.get(name='Stock')
         except Venture.DoesNotExist:
             venture = Venture(name='Stock', symbol='stock')
             venture.save()
         device = Device.create(
             sn=self.sn or 'bc-' + self.barcode,
             barcode=self.barcode,
             model_name='Unknown',
             model_type=DeviceType.unknown,
             priority=SAVE_PRIORITY,
             venture=venture,
         )
         device.name = getattr(self.model, 'name', 'Unknown')
         device.remarks = self.order_no or ''
         device.dc = getattr(self.warehouse, 'name', '')
         device.save()
         self.device_info.ralph_device_id = device.id
         self.device_info.save()