def database_sw_update_add(sw_update_obj):
    """
    Add a software update object to the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.SoftwareUpdate)
    sw_update = query.filter(
        model.SoftwareUpdate.uuid == sw_update_obj.uuid).first()
    if not sw_update:
        sw_update = model.SoftwareUpdate()
        sw_update.uuid = sw_update_obj.uuid
        sw_update.sw_update_type = sw_update_obj.sw_update_type
        if sw_update_obj.strategy is None:
            sw_update.strategy_data = json.dumps(dict())
        else:
            sw_update.strategy_data = json.dumps(
                sw_update_obj.strategy.as_dict())
        session.add(sw_update)
    else:
        if sw_update_obj.strategy is None:
            sw_update.strategy_data = json.dumps(dict())
        else:
            sw_update.strategy_data = json.dumps(
                sw_update_obj.strategy.as_dict())
    db.commit()
def database_host_add(host_obj):
    """
    Add a host object to the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Host_v5).filter(model.Host_v5.name == host_obj.name)
    host = query.first()
    if not host:
        host = model.Host_v5()
        host.uuid = host_obj.uuid
        host.name = host_obj.name
        host.personality = host_obj.personality
        host.state = host_obj.state
        host.action = host_obj.action
        host.upgrade_inprogress = host_obj.upgrade_inprogress
        host.recover_instances = host_obj.recover_instances
        host.uptime = host_obj.uptime
        host.elapsed_time_in_state = host_obj.elapsed_time_in_state
        host.host_services_locked = host_obj.host_services_locked
        host.nfvi_host_data = json.dumps(host_obj.nfvi_host.as_dict())
        session.add(host)
    else:
        host.state = host_obj.state
        host.action = host_obj.action
        host.upgrade_inprogress = host_obj.upgrade_inprogress
        host.recover_instances = host_obj.recover_instances
        host.uptime = host_obj.uptime
        host.elapsed_time_in_state = host_obj.elapsed_time_in_state
        host.host_services_locked = host_obj.host_services_locked
        host.nfvi_host_data = json.dumps(host_obj.nfvi_host.as_dict())
    db.commit()
def database_volume_snapshot_add(volume_snapshot_obj):
    """
    Add a volume snapshot object to the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.VolumeSnapshot)
    query = query.filter(model.VolumeSnapshot.uuid == volume_snapshot_obj.uuid)
    volume_snapshot = query.first()
    if not volume_snapshot:
        volume_snapshot = model.VolumeSnapshot()
        volume_snapshot.uuid = volume_snapshot_obj.uuid
        volume_snapshot.name = volume_snapshot_obj.name
        volume_snapshot.description = volume_snapshot_obj.description
        volume_snapshot.size_gb = volume_snapshot_obj.size_gb
        volume_snapshot.volume_uuid = volume_snapshot_obj.volume_uuid
        volume_snapshot.nfvi_volume_snapshot_data = \
            json.dumps(volume_snapshot_obj.nfvi_volume_snapshot.as_dict())
        session.add(volume_snapshot)
    else:
        volume_snapshot.name = volume_snapshot_obj.name
        volume_snapshot.description = volume_snapshot_obj.description
        volume_snapshot.size_gb = volume_snapshot_obj.size_gb
        volume_snapshot.volume_uuid = volume_snapshot_obj.volume_uuid
        volume_snapshot.nfvi_volume_snapshot_data = \
            json.dumps(volume_snapshot_obj.nfvi_volume_snapshot.as_dict())
    db.commit()
def database_volume_add(volume_obj):
    """
    Add a volume object to the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Volume)
    query = query.filter(model.Volume.uuid == volume_obj.uuid)
    volume = query.first()
    if not volume:
        volume = model.Volume()
        volume.uuid = volume_obj.uuid
        volume.name = volume_obj.name
        volume.description = volume_obj.description
        volume.avail_status = json.dumps(volume_obj.avail_status)
        volume.action = volume_obj.action
        volume.size_gb = volume_obj.size_gb
        volume.bootable = volume_obj.bootable
        volume.encrypted = volume_obj.encrypted
        volume.image_uuid = volume_obj.image_uuid
        volume.nfvi_volume_data = json.dumps(volume_obj.nfvi_volume.as_dict())
        session.add(volume)
    else:
        volume.name = volume_obj.name
        volume.description = volume_obj.description
        volume.avail_status = json.dumps(volume_obj.avail_status)
        volume.action = volume_obj.action
        volume.size_gb = volume_obj.size_gb
        volume.bootable = volume_obj.bootable
        volume.encrypted = volume_obj.encrypted
        volume.image_uuid = volume_obj.image_uuid
        volume.nfvi_volume_data = json.dumps(volume_obj.nfvi_volume.as_dict())
    db.commit()
def database_host_get_list():
    """
    Fetch all the host objects from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Host_v5)

    host_objs = list()
    for host in query.all():
        nfvi_host_data = json.loads(host.nfvi_host_data)
        nfvi_host = nfvi.objects.v1.Host(nfvi_host_data['uuid'],
                                         nfvi_host_data['name'],
                                         nfvi_host_data['personality'],
                                         nfvi_host_data['admin_state'],
                                         nfvi_host_data['oper_state'],
                                         nfvi_host_data['avail_status'],
                                         nfvi_host_data['action'],
                                         nfvi_host_data['uptime'],
                                         nfvi_host_data['software_load'],
                                         nfvi_host_data['target_load'],
                                         nfvi_host_data['nfvi_data'])

        host_obj = objects.Host(nfvi_host, host.state, host.action,
                                host.elapsed_time_in_state, host.upgrade_inprogress,
                                host.recover_instances, host.host_services_locked)
        host_objs.append(host_obj)
    return host_objs
Beispiel #6
0
def database_instance_group_add(instance_group_obj):
    """
    Add an instance group object to the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.InstanceGroup)
    query = query.filter(model.InstanceGroup.uuid == instance_group_obj.uuid)
    instance_group = query.first()
    if not instance_group:
        instance_group = model.InstanceGroup()
        instance_group.uuid = instance_group_obj.uuid
        instance_group.name = instance_group_obj.name
        instance_group.member_uuids = json.dumps(
            instance_group_obj.member_uuids)
        instance_group.policies = json.dumps(instance_group_obj.policies)
        instance_group.nfvi_instance_group_data \
            = json.dumps(instance_group_obj.nfvi_instance_group.as_dict())
        session.add(instance_group)
    else:
        instance_group.name = instance_group_obj.name
        instance_group.member_uuids = json.dumps(
            instance_group_obj.member_uuids)
        instance_group.policies = json.dumps(instance_group_obj.policies)
        instance_group.nfvi_instance_group_data \
            = json.dumps(instance_group_obj.nfvi_instance_group.as_dict())
    db.commit()
Beispiel #7
0
def database_network_add(network_obj):
    """
    Add a network object to the database
    """
    provider_data = network_obj.provider_data

    db = database_get()
    session = db.session()
    query = session.query(model.Network)
    query = query.filter(model.Network.uuid == network_obj.uuid)
    network = query.first()
    if not network:
        network = model.Network()
        network.uuid = network_obj.uuid
        network.name = network_obj.name
        network.admin_state = network_obj.admin_state
        network.oper_state = network_obj.oper_state
        network.avail_status = json.dumps(network_obj.avail_status)
        network.is_shared = network_obj.is_shared
        network.mtu = network_obj.mtu
        network.physical_network = provider_data.physical_network
        network.network_type = provider_data.network_type
        network.segmentation_id = provider_data.segmentation_id
        session.add(network)
    else:

        network.admin_state = network_obj.admin_state
        network.oper_state = network_obj.oper_state
        network.avail_status = json.dumps(network_obj.avail_status)
        network.is_shared = network_obj.is_shared
        network.mtu = network_obj.mtu
        network.physical_network = provider_data.physical_network
        network.network_type = provider_data.network_type
        network.segmentation_id = provider_data.segmentation_id
    db.commit()
Beispiel #8
0
def database_subnet_delete(subnet_uuid):
    """
    Delete a subnet object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Subnet)
    query.filter(model.Subnet.uuid == subnet_uuid).delete()
    session.commit()
Beispiel #9
0
def database_network_delete(network_uuid):
    """
    Delete a network object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Network)
    query.filter(model.Network.uuid == network_uuid).delete()
    session.commit()
def database_host_delete(host_name):
    """
    Delete a host object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Host_v5)
    query.filter(model.Host_v5.name == host_name).delete()
    session.commit()
def database_system_delete(system_name):
    """
    Delete a system object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.System)
    query.filter(model.System.name == system_name).delete()
    session.commit()
def database_sw_update_delete(sw_update_uuid):
    """
    Delete a software update object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.SoftwareUpdate)
    query.filter(model.SoftwareUpdate.uuid == sw_update_uuid).delete()
    session.commit()
Beispiel #13
0
def database_image_delete(image_uuid):
    """
    Delete an image object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Image)
    query.filter(model.Image.uuid == image_uuid).delete()
    session.commit()
Beispiel #14
0
def database_instance_group_delete(instance_group_uuid):
    """
    Delete an instance group object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.InstanceGroup)
    query.filter(model.InstanceGroup.uuid == instance_group_uuid).delete()
    session.commit()
def database_volume_delete(volume_uuid):
    """
    Delete a volume object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Volume)
    query.filter(model.Volume.uuid == volume_uuid).delete()
    session.commit()
Beispiel #16
0
def database_service_host_delete(service_host_name):
    """
    Delete a service-host object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.ServiceHost)
    query.filter(model.ServiceHost.name == service_host_name).delete()
    session.commit()
Beispiel #17
0
def database_hypervisor_delete(hypervisor_uuid):
    """
    Delete a hypervisor object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Hypervisor)
    query.filter(model.Hypervisor.uuid == hypervisor_uuid).delete()
    session.commit()
def database_tenant_delete(tenant_uuid):
    """
    Delete a tenant object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Tenant)
    query.filter(model.Tenant.uuid == tenant_uuid).delete()
    session.commit()
Beispiel #19
0
def database_host_aggregate_delete(host_aggregate_name):
    """
    Delete a host aggregate object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.HostAggregate)
    query.filter(model.HostAggregate.name == host_aggregate_name).delete()
    session.commit()
Beispiel #20
0
def database_instance_type_delete(instance_type_uuid):
    """
    Delete an instance type object from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.InstanceType_v5)
    query.filter(model.InstanceType_v5.uuid == instance_type_uuid).delete()
    session.commit()
Beispiel #21
0
def database_instance_add(instance_obj):
    """
    Add an instance object to the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Instance_v5)
    query = query.filter(model.Instance_v5.uuid == instance_obj.uuid)
    instance = query.first()
    if not instance:
        instance = model.Instance_v5()
        instance.uuid = instance_obj.uuid
        instance.name = instance_obj.name
        instance.admin_state = instance_obj.admin_state
        instance.oper_state = instance_obj.oper_state
        instance.avail_status = json.dumps(instance_obj.avail_status)
        instance.action = instance_obj.action
        instance.host_name = instance_obj.host_name
        instance.image_uuid = instance_obj.image_uuid
        instance.live_migration_support = instance_obj.supports_live_migration(
        )
        instance.elapsed_time_in_state = instance_obj.elapsed_time_in_state
        instance.elapsed_time_on_host = instance_obj.elapsed_time_on_host
        instance.action_data = json.dumps(instance_obj.action_data.as_dict())
        instance.last_action_data \
            = json.dumps(instance_obj.last_action_data.as_dict())
        instance.guest_services \
            = json.dumps(instance_obj.guest_services.as_dict())
        instance.recoverable = instance_obj.recoverable
        instance.unlock_to_recover = instance_obj.unlock_to_recover
        instance.nfvi_instance_data \
            = json.dumps(instance_obj.nfvi_instance.as_dict())
        session.add(instance)
    else:
        instance.name = instance_obj.name
        instance.admin_state = instance_obj.admin_state
        instance.oper_state = instance_obj.oper_state
        instance.avail_status = json.dumps(instance_obj.avail_status)
        instance.action = instance_obj.action
        instance.host_name = instance_obj.host_name
        instance.image_uuid = instance_obj.image_uuid
        instance.live_migration_support = instance_obj.supports_live_migration(
        )
        instance.elapsed_time_in_state = instance_obj.elapsed_time_in_state
        instance.elapsed_time_on_host = instance_obj.elapsed_time_on_host
        instance.action_data = json.dumps(instance_obj.action_data.as_dict())
        instance.last_action_data \
            = json.dumps(instance_obj.last_action_data.as_dict())
        instance.guest_services \
            = json.dumps(instance_obj.guest_services.as_dict())
        instance.recoverable = instance_obj.recoverable
        instance.unlock_to_recover = instance_obj.unlock_to_recover
        instance.nfvi_instance_data \
            = json.dumps(instance_obj.nfvi_instance.as_dict())
    db.commit()
def database_system_get_list():
    """
    Fetch all the system objects from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.System)

    system_objs = list()
    for system in query.all():
        system_obj = objects.System(system.name, system.description)
        system_objs.append(system_obj)
    return system_objs
def database_tenant_get_list():
    """
    Fetch all the tenant objects from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Tenant)

    tenant_objs = list()
    for tenant in query.all():
        tenant_obj = objects.Tenant(tenant.uuid, tenant.name,
                                    tenant.description, tenant.enabled)
        tenant_objs.append(tenant_obj)
    return tenant_objs
Beispiel #24
0
def database_service_host_get_list():
    """
    Fetch all the service host objects from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.ServiceHost)

    service_host_objs = list()
    for service_host in query.all():
        service_host_obj = objects.ServiceHost(service_host.name,
                                               service_host.service,
                                               service_host.zone)
        service_host_objs.append(service_host_obj)
    return service_host_objs
def database_instance_type_add(instance_type_obj):
    """
    Add an instance type object to the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.InstanceType)
    query = query.filter(model.InstanceType.uuid == instance_type_obj.uuid)
    instance_type = query.first()
    if not instance_type:
        instance_type = model.InstanceType()
        instance_type.uuid = instance_type_obj.uuid
        instance_type.name = instance_type_obj.name
        if instance_type_obj.have_details():
            instance_type.have_details = True
            instance_type.vcpus = instance_type_obj.vcpus
            instance_type.mem_mb = instance_type_obj.mem_mb
            instance_type.disk_gb = instance_type_obj.disk_gb
            instance_type.ephemeral_gb = instance_type_obj.ephemeral_gb
            instance_type.swap_gb = instance_type_obj.swap_gb
            instance_type.guest_services \
                = json.dumps(instance_type_obj.guest_services)
            if instance_type_obj.auto_recovery is not None:
                instance_type.auto_recovery = instance_type_obj.auto_recovery
            instance_type.live_migration_timeout \
                = instance_type_obj.live_migration_timeout
            instance_type.live_migration_max_downtime \
                = instance_type_obj.live_migration_max_downtime
            instance_type.storage_type = instance_type_obj.storage_type
        session.add(instance_type)
    else:
        if instance_type_obj.have_details():
            instance_type.have_details = True
            instance_type.vcpus = instance_type_obj.vcpus
            instance_type.mem_mb = instance_type_obj.mem_mb
            instance_type.disk_gb = instance_type_obj.disk_gb
            instance_type.ephemeral_gb = instance_type_obj.ephemeral_gb
            instance_type.swap_gb = instance_type_obj.swap_gb
            instance_type.guest_services \
                = json.dumps(instance_type_obj.guest_services)
            if instance_type_obj.auto_recovery is not None:
                instance_type.auto_recovery = instance_type_obj.auto_recovery
            instance_type.live_migration_timeout \
                = instance_type_obj.live_migration_timeout
            instance_type.live_migration_max_downtime \
                = instance_type_obj.live_migration_max_downtime
            instance_type.storage_type = instance_type_obj.storage_type
    db.commit()
Beispiel #26
0
def database_service_host_add(service_host_obj):
    """
    Add a service-host object to the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.ServiceHost)
    query = query.filter(model.ServiceHost.name == service_host_obj.name)
    service_host = query.first()
    if not service_host:
        service_host = model.ServiceHost()
        service_host.name = service_host_obj.name
        service_host.service = service_host_obj.service
        service_host.zone = service_host_obj.zone
        session.add(service_host)
        db.commit()
Beispiel #27
0
def database_instance_group_get_list():
    """
    Fetch all the instance group objects from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.InstanceGroup)

    instance_group_objs = list()
    for instance_group in query.all():
        nfvi_data = json.loads(instance_group.nfvi_instance_group_data)
        nfvi_instance_group = nfvi.objects.v1.InstanceGroup(
            nfvi_data['uuid'], nfvi_data['name'], nfvi_data['member_uuids'],
            nfvi_data['policies'])
        instance_group_obj = objects.InstanceGroup(nfvi_instance_group)
        instance_group_objs.append(instance_group_obj)
    return instance_group_objs
def database_host_group_get_list():
    """
    Fetch all the host group objects from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.HostGroup)

    host_group_objs = list()
    for host_group in query.all():
        nfvi_data = json.loads(host_group.nfvi_host_group_data)
        nfvi_host_group = nfvi.objects.v1.HostGroup(
            nfvi_data['name'], nfvi_data['member_names'],
            nfvi_data['policies'])
        host_group_obj = objects.HostGroup(nfvi_host_group)
        host_group_objs.append(host_group_obj)
    return host_group_objs
Beispiel #29
0
def database_host_aggregate_get_list():
    """
    Fetch all the host aggregate objects from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.HostAggregate)

    host_aggregate_objs = list()
    for host_aggregate in query.all():
        nfvi_data = json.loads(host_aggregate.nfvi_host_aggregate_data)
        nfvi_host_aggregate = nfvi.objects.v1.HostAggregate(
            nfvi_data['name'], nfvi_data['host_names'],
            nfvi_data['availability_zone'])
        host_aggregate_obj = objects.HostAggregate(nfvi_host_aggregate)
        host_aggregate_objs.append(host_aggregate_obj)
    return host_aggregate_objs
Beispiel #30
0
def database_subnet_get_list():
    """
    Fetch all the subnet objects from the database
    """
    db = database_get()
    session = db.session()
    query = session.query(model.Subnet)

    subnet_objs = list()
    for subnet in query.all():
        subnet_obj = objects.Subnet(subnet.uuid, subnet.name,
                                    subnet.ip_version, subnet.subnet_ip,
                                    subnet.subnet_prefix, subnet.gateway_ip,
                                    subnet.network_uuid,
                                    subnet.is_dhcp_enabled)
        subnet_objs.append(subnet_obj)
    return subnet_objs