示例#1
0
文件: common.py 项目: damjanek/ralph
 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)
示例#2
0
文件: deploy.py 项目: ReJeCtAll/ralph
 def post(self, request, *args, **kwargs):
     from ralph.urls import LATEST_API
     actor = User.objects.get(
         username=ApiKeyAuthentication().get_identifier(request)
     )
     if not actor.has_perm('create_devices'):
         raise HttpResponse(_('You cannot create new devices'), status=401)
     data = Serializer().deserialize(
         request.body,
         format=request.META.get('CONTENT_TYPE', 'application/json')
     )
     mac = MACAddressField.normalize(data['mac'])
     parent = self.get_parent_device(data)
     ip_addr = get_first_free_ip(data['network'])
     hostname = self.get_hostname(parent)
     venture = get_object_or_404(
         Venture,
         symbol=data['venture']
     )
     role = get_object_or_404(
         VentureRole,
         venture=venture,
         name=data['venture-role']
     )
     ethernets = [Eth(
         'DEPLOYMENT MAC',
         mac,
         EthernetSpeed.unknown,
     )]
     device = Device.create(
         ethernets=ethernets,
         model_type=DeviceType.unknown,
         model_name='Unknown',
         verified=True,
     )
     device.name = hostname
     device.parent = parent
     device.venture = venture
     device.venture_role = role
     device.save()
     IPAddress.objects.create(
         address=ip_addr,
         device=device,
         hostname=hostname,
     )
     reset_dns(hostname, ip_addr)
     reset_dhcp(ip_addr, data['mac'])
     resp = HttpResponse('', status=201)
     resp['Location'] = LATEST_API.canonical_resource_for(
         'dev'
     ).get_resource_uri(device)
     return resp
示例#3
0
def change_ip_address(current_ip_address, new_ip_address):
    _change_ip_address_validation(current_ip_address, new_ip_address)

    # change device ip address
    ip_current = _get_changed_ip_address_object(current_ip_address)
    ip_new = _get_or_create_ip_address(new_ip_address)
    hostname = ip_current.hostname
    device = _get_connected_device(ip_current)
    _change_device_ip_address(device, ip_current, ip_new)

    # change dhcp entries
    _change_ip_address_dhcp_entry(ip_current, ip_new)

    # change dns
    clean_dns_entries(ip_current.address)
    reset_dns(hostname, ip_new.address)
示例#4
0
文件: util.py 项目: 4i60r/ralph
def change_ip_address(current_ip_address, new_ip_address):
    _change_ip_address_validation(current_ip_address, new_ip_address)

    # change device ip address
    ip_current = _get_changed_ip_address_object(current_ip_address)
    ip_new = _get_or_create_ip_address(new_ip_address)
    hostname = ip_current.hostname
    device = _get_connected_device(ip_current)
    _change_device_ip_address(device, ip_current, ip_new)

    # change dhcp entries
    _change_ip_address_dhcp_entry(ip_current, ip_new)

    # change dns
    clean_dns_entries(ip_current.address)
    reset_dns(hostname, ip_new.address)
示例#5
0
 def post(self, request, *args, **kwargs):
     from ralph.urls import LATEST_API
     actor = User.objects.get(
         username=ApiKeyAuthentication().get_identifier(request))
     if not actor.has_perm('create_devices'):
         raise HttpResponse(_('You cannot create new devices'), status=401)
     data = Serializer().deserialize(request.body,
                                     format=request.META.get(
                                         'CONTENT_TYPE',
                                         'application/json'))
     mac = MACAddressField.normalize(data['mac'])
     parent = self.get_parent_device(data)
     ip_addr = get_first_free_ip(data['network'])
     hostname = self.get_hostname(parent)
     venture = get_object_or_404(Venture, symbol=data['venture'])
     role = get_object_or_404(VentureRole,
                              venture=venture,
                              name=data['venture-role'])
     ethernets = [Eth(
         'DEPLOYMENT MAC',
         mac,
         EthernetSpeed.unknown,
     )]
     device = Device.create(
         ethernets=ethernets,
         model_type=DeviceType.unknown,
         model_name='Unknown',
         verified=True,
     )
     device.name = hostname
     device.parent = parent
     device.venture = venture
     device.venture_role = role
     device.save()
     IPAddress.objects.create(
         address=ip_addr,
         device=device,
         hostname=hostname,
     )
     reset_dns(hostname, ip_addr)
     reset_dhcp(ip_addr, data['mac'])
     resp = HttpResponse('', status=201)
     resp['Location'] = LATEST_API.canonical_resource_for(
         'dev').get_resource_uri(device)
     return resp
示例#6
0
文件: dns.py 项目: smagowr/ralph
def dns(deployment_id):
    deployment = Deployment.objects.get(id=deployment_id)
    reset_dns(deployment.hostname, deployment.ip)
    return True
示例#7
0
文件: deploy.py 项目: 4i60r/ralph
 def post(self, request, *args, **kwargs):
     from ralph.urls import LATEST_API
     try:
         actor = User.objects.get(
             username=ApiKeyAuthentication().get_identifier(request)
         )
     except User.DoesNotExist:
         actor = None
     if not (actor and actor.profile.has_perm(Perm.has_core_access)):
         return HttpResponse(
             unicode(_('You cannot create new devices')),
             status=401
         )
     data = Serializer().deserialize(
         request.body,
         format=request.META.get('CONTENT_TYPE', 'application/json')
     )
     missing_keys = {
         'mac',
         'network',
         'management-ip',
         'venture',
         'venture-role'
     } - set(data.keys())
     if missing_keys:
         return HttpResponse(
             _('Missing data: {}').format(', '.join(missing_keys)),
             status=400,
         )
     mac = MACAddressField.normalize(data['mac'])
     existing_mac = DHCPEntry.objects.filter(mac=mac).count()
     if existing_mac:
         return HttpResponse(unicode(_('MAC already exists')), status=400)
     parent = self.get_parent_device(data)
     try:
         ip_addr = get_first_free_ip(data['network'])
     except Network.DoesNotExist:
         raise Http404('No network with such name exists')
     hostname = self.get_hostname(parent)
     venture = get_object_or_404(
         Venture,
         symbol=data['venture']
     )
     role_name = data.get('venture-role')
     role = role_name and get_object_or_404(
         VentureRole,
         venture=venture,
         name=role_name,
     )
     ethernets = [Eth(
         'DEPLOYMENT MAC',
         mac,
         EthernetSpeed.unknown,
     )]
     device = Device.create(
         ethernets=ethernets,
         model_type=DeviceType.unknown,
         model_name='Unknown',
         verified=True,
     )
     device.name = hostname
     device.parent = parent
     device.venture = venture
     device.venture_role = role
     device.rack = parent.rack
     device.dc = parent.dc
     device.save()
     IPAddress.objects.create(
         address=ip_addr,
         device=device,
         hostname=hostname,
     )
     reset_dns(hostname, ip_addr)
     reset_dhcp(ip_addr, data['mac'])
     resp = HttpResponse('', status=201)
     resp['Location'] = LATEST_API.canonical_resource_for(
         'dev'
     ).get_resource_uri(device)
     return resp
示例#8
0
 def post(self, request, *args, **kwargs):
     from ralph.urls import LATEST_API
     try:
         actor = User.objects.get(
             username=ApiKeyAuthentication().get_identifier(request))
     except User.DoesNotExist:
         actor = None
     if not (actor and actor.has_perm('create_devices')):
         return HttpResponse(unicode(_('You cannot create new devices')),
                             status=401)
     data = Serializer().deserialize(request.body,
                                     format=request.META.get(
                                         'CONTENT_TYPE',
                                         'application/json'))
     missing_keys = {
         'mac', 'network', 'management-ip', 'venture', 'venture-role'
     } - set(data.keys())
     if missing_keys:
         return HttpResponse(
             _('Missing data: {}').format(', '.join(missing_keys)),
             status=400,
         )
     mac = MACAddressField.normalize(data['mac'])
     existing_mac = DHCPEntry.objects.filter(mac=mac).count()
     if existing_mac:
         return HttpResponse(unicode(_('MAC already exists')), status=400)
     parent = self.get_parent_device(data)
     try:
         ip_addr = get_first_free_ip(data['network'])
     except Network.DoesNotExist:
         raise Http404('No network with such name exists')
     hostname = self.get_hostname(parent)
     venture = get_object_or_404(Venture, symbol=data['venture'])
     role_name = data.get('venture-role')
     role = role_name and get_object_or_404(
         VentureRole,
         venture=venture,
         name=role_name,
     )
     ethernets = [Eth(
         'DEPLOYMENT MAC',
         mac,
         EthernetSpeed.unknown,
     )]
     device = Device.create(
         ethernets=ethernets,
         model_type=DeviceType.unknown,
         model_name='Unknown',
         verified=True,
     )
     device.name = hostname
     device.parent = parent
     device.venture = venture
     device.venture_role = role
     device.rack = parent.rack
     device.dc = parent.dc
     device.save()
     IPAddress.objects.create(
         address=ip_addr,
         device=device,
         hostname=hostname,
     )
     reset_dns(hostname, ip_addr)
     reset_dhcp(ip_addr, data['mac'])
     resp = HttpResponse('', status=201)
     resp['Location'] = LATEST_API.canonical_resource_for(
         'dev').get_resource_uri(device)
     return resp