Ejemplo n.º 1
0
def stub_instance(id=1,
                  user_id=None,
                  project_id=None,
                  host=None,
                  node=None,
                  vm_state=None,
                  task_state=None,
                  reservation_id="",
                  uuid=FAKE_UUID,
                  image_ref="10",
                  flavor_id="1",
                  name=None,
                  key_name='',
                  access_ipv4=None,
                  access_ipv6=None,
                  progress=0,
                  auto_disk_config=False,
                  display_name=None,
                  display_description=None,
                  include_fake_metadata=True,
                  config_drive=None,
                  power_state=None,
                  nw_cache=None,
                  metadata=None,
                  security_groups=None,
                  root_device_name=None,
                  limit=None,
                  marker=None,
                  launched_at=timeutils.utcnow(),
                  terminated_at=timeutils.utcnow(),
                  availability_zone='',
                  locked_by=None,
                  cleaned=False,
                  memory_mb=0,
                  vcpus=0,
                  root_gb=0,
                  ephemeral_gb=0,
                  instance_type=None,
                  launch_index=0,
                  kernel_id="",
                  ramdisk_id="",
                  user_data=None,
                  system_metadata=None,
                  services=None):
    if user_id is None:
        user_id = 'fake_user'
    if project_id is None:
        project_id = 'fake_project'

    if metadata:
        metadata = [{'key': k, 'value': v} for k, v in metadata.items()]
    elif include_fake_metadata:
        metadata = [models.InstanceMetadata(key='seq', value=str(id))]
    else:
        metadata = []

    inst_type = flavors.get_flavor_by_flavor_id(int(flavor_id))
    sys_meta = flavors.save_flavor_info({}, inst_type)
    sys_meta.update(system_metadata or {})

    if host is not None:
        host = str(host)

    if key_name:
        key_data = 'FAKE'
    else:
        key_data = ''

    if security_groups is None:
        security_groups = [{
            "id": 1,
            "name": "test",
            "description": "Foo:",
            "project_id": "project",
            "user_id": "user",
            "created_at": None,
            "updated_at": None,
            "deleted_at": None,
            "deleted": False
        }]

    # ReservationID isn't sent back, hack it in there.
    server_name = name or "server%s" % id
    if reservation_id != "":
        server_name = "reservation_%s" % (reservation_id, )

    info_cache = create_info_cache(nw_cache)

    if instance_type is None:
        instance_type = flavors.get_default_flavor()
    flavorinfo = jsonutils.dumps({
        'cur': instance_type.obj_to_primitive(),
        'old': None,
        'new': None,
    })

    instance = {
        "id": int(id),
        "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
        "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
        "deleted_at": datetime.datetime(2010, 12, 12, 10, 0, 0),
        "deleted": None,
        "user_id": user_id,
        "project_id": project_id,
        "image_ref": image_ref,
        "kernel_id": kernel_id,
        "ramdisk_id": ramdisk_id,
        "launch_index": launch_index,
        "key_name": key_name,
        "key_data": key_data,
        "config_drive": config_drive,
        "vm_state": vm_state or vm_states.ACTIVE,
        "task_state": task_state,
        "power_state": power_state,
        "memory_mb": memory_mb,
        "vcpus": vcpus,
        "min_vcpus": vcpus,
        "max_vcpus": vcpus,
        "root_gb": root_gb,
        "ephemeral_gb": ephemeral_gb,
        "ephemeral_key_uuid": None,
        "hostname": display_name or server_name,
        "host": host,
        "node": node,
        "instance_type_id": 1,
        "instance_type": inst_type,
        "user_data": user_data,
        "reservation_id": reservation_id,
        "mac_address": "",
        "launched_at": launched_at,
        "terminated_at": terminated_at,
        "availability_zone": availability_zone,
        "display_name": display_name or server_name,
        "display_description": display_description,
        "locked": locked_by is not None,
        "locked_by": locked_by,
        "metadata": metadata,
        "access_ip_v4": access_ipv4,
        "access_ip_v6": access_ipv6,
        "uuid": uuid,
        "progress": progress,
        "auto_disk_config": auto_disk_config,
        "name": "instance-%s" % id,
        "shutdown_terminate": True,
        "disable_terminate": False,
        "security_groups": security_groups,
        "root_device_name": root_device_name,
        "system_metadata": utils.dict_to_metadata(sys_meta),
        "pci_devices": [],
        "vm_mode": "",
        "default_swap_device": "",
        "default_ephemeral_device": "",
        "launched_on": "",
        "cell_name": "",
        "architecture": "",
        "os_type": "",
        "extra": {
            "numa_topology": None,
            "pci_requests": None,
            "flavor": flavorinfo,
        },
        "cleaned": cleaned,
        "services": services
    }

    instance.update(info_cache)
    instance['info_cache']['instance_uuid'] = instance['uuid']

    return instance
Ejemplo n.º 2
0
def stub_instance(id,
                  user_id=None,
                  project_id=None,
                  host=None,
                  node=None,
                  vm_state=None,
                  task_state=None,
                  reservation_id="",
                  uuid=FAKE_UUID,
                  image_ref="10",
                  flavor_id="1",
                  name=None,
                  key_name='',
                  access_ipv4=None,
                  access_ipv6=None,
                  progress=0,
                  auto_disk_config=False,
                  display_name=None,
                  include_fake_metadata=True,
                  config_drive=None,
                  power_state=None,
                  nw_cache=None,
                  metadata=None,
                  security_groups=None,
                  root_device_name=None,
                  limit=None,
                  marker=None):

    if user_id is None:
        user_id = 'fake_user'
    if project_id is None:
        project_id = 'fake_project'

    if metadata:
        metadata = [{'key': k, 'value': v} for k, v in metadata.items()]
    elif include_fake_metadata:
        metadata = [models.InstanceMetadata(key='seq', value=str(id))]
    else:
        metadata = []

    inst_type = flavors.get_instance_type_by_flavor_id(int(flavor_id))
    sys_meta = flavors.save_instance_type_info({}, inst_type)

    if host is not None:
        host = str(host)

    if key_name:
        key_data = 'FAKE'
    else:
        key_data = ''

    if security_groups is None:
        security_groups = [{"id": 1, "name": "test"}]

    # ReservationID isn't sent back, hack it in there.
    server_name = name or "server%s" % id
    if reservation_id != "":
        server_name = "reservation_%s" % (reservation_id, )

    info_cache = create_info_cache(nw_cache)

    instance = {
        "id": int(id),
        "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
        "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
        "user_id": user_id,
        "project_id": project_id,
        "image_ref": image_ref,
        "kernel_id": "",
        "ramdisk_id": "",
        "launch_index": 0,
        "key_name": key_name,
        "key_data": key_data,
        "config_drive": config_drive,
        "vm_state": vm_state or vm_states.BUILDING,
        "task_state": task_state,
        "power_state": power_state,
        "memory_mb": 0,
        "vcpus": 0,
        "root_gb": 0,
        "ephemeral_gb": 0,
        "hostname": display_name or server_name,
        "host": host,
        "node": node,
        "instance_type_id": 1,
        "instance_type": dict(inst_type),
        "user_data": "",
        "reservation_id": reservation_id,
        "mac_address": "",
        "scheduled_at": timeutils.utcnow(),
        "launched_at": timeutils.utcnow(),
        "terminated_at": timeutils.utcnow(),
        "availability_zone": "",
        "display_name": display_name or server_name,
        "display_description": "",
        "locked": False,
        "metadata": metadata,
        "access_ip_v4": access_ipv4,
        "access_ip_v6": access_ipv6,
        "uuid": uuid,
        "progress": progress,
        "auto_disk_config": auto_disk_config,
        "name": "instance-%s" % id,
        "shutdown_terminate": True,
        "disable_terminate": False,
        "security_groups": security_groups,
        "root_device_name": root_device_name,
        "system_metadata": utils.dict_to_metadata(sys_meta),
        "vm_mode": "",
        "default_swap_device": "",
        "default_ephemeral_device": "",
        "launched_on": "",
        "cell_name": "",
        "architecture": "",
        "os_type": ""
    }

    instance.update(info_cache)

    return instance