Exemplo n.º 1
0
    def create_host(self, context, segment_uuid, host_data):
        """Create host"""
        segment = objects.FailoverSegment.get_by_uuid(context, segment_uuid)
        host = objects.Host(context=context)

        # Populate host object for create
        host.name = host_data.get('name')
        host.failover_segment = segment
        host.type = host_data.get('type')
        host.control_attributes = host_data.get('control_attributes')
        host.on_maintenance = strutils.bool_from_string(host_data.get(
            'on_maintenance', False),
                                                        strict=True)
        host.reserved = strutils.bool_from_string(host_data.get(
            'reserved', False),
                                                  strict=True)

        self._is_valid_host_name(context, host.name)

        try:
            host.create()
        except Exception as e:
            with excutils.save_and_reraise_exception():
                tb = traceback.format_exc()
                api_utils.notify_about_host_api(
                    context,
                    host,
                    action=fields.EventNotificationAction.HOST_CREATE,
                    phase=fields.EventNotificationPhase.ERROR,
                    exception=e,
                    tb=tb)

        return host
Exemplo n.º 2
0
def create_fake_host(name='fake_host', id=1, reserved=False,
                     on_maintenance=False, type='SSH',
                     control_attributes='fake',
                     uuid=uuidsentinel.fake_host,
                     failover_segment_id=uuidsentinel.fake_segment):
    return objects.Host(
        name=name, id=id, reserved=reserved, on_maintenance=on_maintenance,
        type=type, control_attributes=control_attributes, uuid=uuid,
        failover_segment_id=failover_segment_id)
Exemplo n.º 3
0
def create_fake_host(**updates):
    host = {
        'name': 'fake_host', 'id': 1, 'reserved': False,
        'on_maintenance': False, 'type': 'SSH',
        'control_attributes': 'fake', 'uuid': uuidsentinel.fake_host,
        'failover_segment': FAILOVER_SEGMENT,
        'created_at': datetime.datetime(
            2019, 8, 8, 0, 0, 0, tzinfo=iso8601.UTC),
        'updated_at': None, 'deleted_at': None, 'deleted': False
    }
    if updates:
        host.update(updates)
    return objects.Host(**host)
Exemplo n.º 4
0
    def create_host(self, context, segment_uuid, host_data):
        """Create host"""
        segment = objects.FailoverSegment.get_by_uuid(context, segment_uuid)
        host = objects.Host(context=context)

        # Populate host object for create
        host.name = host_data.get('name')
        host.failover_segment_id = segment.uuid
        host.type = host_data.get('type')
        host.control_attributes = host_data.get('control_attributes')
        host.on_maintenance = strutils.bool_from_string(
            host_data.get('on_maintenance', False), strict=True)
        host.reserved = strutils.bool_from_string(
            host_data.get('reserved', False), strict=True)

        host.create()
        return host