Ejemplo n.º 1
0
def listener_get(listener_id, region_name=None):
    client = get_neutronclient(region_name)
    try:
        listener = client.show_listener(listener_id).get('listener')
    except exceptions.NotFound:
        return None
    except exceptions.NeutronException as e:
        if e.status_code == 404:
            return None
        raise e

    is_last_up = _is_last_up_listener(
        client, listener['loadbalancer_id'], listener_id)
    status = utils.transform_status(listener['status'])
    admin_state = (const.STATE_RUNNING
                   if listener['admin_state_up']
                   else const.STATE_STOPPED)

    return Listener(id=listener['id'],
                    name=listener['name'],
                    resource_type=const.RESOURCE_LISTENER,
                    status=status,
                    admin_state=admin_state,
                    is_last_up=is_last_up,
                    original_status=listener['status'])
Ejemplo n.º 2
0
def snapshot_list(project_id,
                  region_name=None,
                  detailed=True,
                  project_name=None):
    """To see all snapshots in the cloud as admin
    """
    c_client = get_cinderclient(region_name)
    search_opts = {'all_tenants': 1, 'project_id': project_id}
    if c_client is None:
        return []
    snapshots = c_client.volume_snapshots.list(detailed,
                                               search_opts=search_opts)
    formatted_snap = []
    for sp in snapshots:
        created_at = utils.format_datetime(sp.created_at)
        status = utils.transform_status(sp.status)
        formatted_snap.append(
            Snapshot(id=sp.id,
                     name=sp.display_name,
                     size=sp.size,
                     status=status,
                     original_status=sp.status,
                     resource_type=const.RESOURCE_SNAPSHOT,
                     user_id=None,
                     project_id=project_id,
                     project_name=project_name,
                     created_at=created_at,
                     volume_id=sp.volume_id))
    return formatted_snap
Ejemplo n.º 3
0
def snapshot_list(project_id, region_name=None, detailed=True, project_name=None):
    """To see all snapshots in the cloud as admin
    """
    c_client = get_cinderclient(region_name)
    search_opts = {'all_tenants': 1,
                   'project_id': project_id}
    if c_client is None:
        return []
    snapshots = c_client.volume_snapshots.list(detailed, search_opts=search_opts)
    formatted_snap = []
    for sp in snapshots:
        created_at = utils.format_datetime(sp.created_at)
        status = utils.transform_status(sp.status)
        formatted_snap.append(Snapshot(id=sp.id,
                                       name=sp.display_name,
                                       size=sp.size,
                                       status=status,
                                       original_status=sp.status,
                                       resource_type=const.RESOURCE_SNAPSHOT,
                                       user_id=None,
                                       project_id=project_id,
                                       project_name=project_name,
                                       created_at=created_at,
                                       volume_id=sp.volume_id))
    return formatted_snap
Ejemplo n.º 4
0
def floatingip_list(project_id, region_name=None, project_name=None):
    client = get_neutronclient(region_name)
    if project_id:
        fips = client.list_floatingips(tenant_id=project_id).get('floatingips')
    else:
        fips = client.list_floatingips().get('floatingips')
    formatted_fips = []
    for fip in fips:
        created_at = utils.format_datetime(fip['created_at'])
        status = utils.transform_status(fip['status'])
        is_bill = False if fip.get('floatingipset_id') else True
        formatted_fips.append(
            FloatingIp(id=fip['id'],
                       name=fip['uos:name'],
                       is_bill=is_bill,
                       size=fip['rate_limit'],
                       providers=fip['uos:service_provider'],
                       project_id=fip['tenant_id'],
                       project_name=project_name,
                       resource_type=const.RESOURCE_FLOATINGIP,
                       status=status,
                       original_status=fip['status'],
                       created_at=created_at))

    return formatted_fips
Ejemplo n.º 5
0
def volume_list(project_id, region_name=None, detailed=True, project_name=None):
    """To see all volumes in the cloud as admin.
    """
    c_client = get_cinderclient(region_name)
    search_opts = {'all_tenants': 1,
                   'project_id': project_id}
    if c_client is None:
        return []
    volumes = c_client.volumes.list(detailed, search_opts=search_opts)
    formatted_volumes = []
    for volume in volumes:
        created_at = utils.format_datetime(volume.created_at)
        status = utils.transform_status(volume.status)
        formatted_volumes.append(Volume(id=volume.id,
                                        name=volume.display_name,
                                        size=volume.size,
                                        status=status,
                                        type=volume.volume_type,
                                        original_status=volume.status,
                                        resource_type=const.RESOURCE_VOLUME,
                                        user_id = None,
                                        project_id = project_id,
                                        project_name=project_name,
                                        attachments=volume.attachments,
                                        created_at=created_at))
    return formatted_volumes
Ejemplo n.º 6
0
def floatingipset_list(project_id, region_name=None, project_name=None):
    client = get_neutronclient(region_name)
    if project_id:
        _fipsets = client.list_floatingipsets(
            tenant_id=project_id).get('floatingipsets')
        fipsets = [fip for fip in _fipsets if fip['tenant_id'] == project_id]

    else:
        fipsets = client.list_floatingipsets().get('floatingipsets')

    formatted_fipsets = []
    for fipset in fipsets:
        created_at = utils.format_datetime(fipset['created_at'])
        status = utils.transform_status(fipset['status'])
        formatted_fipsets.append(
            FloatingIpSet(id=fipset['id'],
                          name=fipset['uos:name'],
                          size=fipset['rate_limit'],
                          providers=fipset['uos:service_provider'],
                          project_id=fipset['tenant_id'],
                          project_name=project_name,
                          resource_type=const.RESOURCE_FLOATINGIPSET,
                          status=status,
                          original_status=fipset['status'],
                          created_at=created_at))

    return formatted_fipsets
Ejemplo n.º 7
0
def floatingipset_list(project_id, region_name=None, project_name=None):
    client = get_neutronclient(region_name)
    if project_id:
        _fipsets = client.list_floatingipsets(tenant_id=project_id).get("floatingipsets")
        fipsets = [fip for fip in _fipsets if fip["tenant_id"] == project_id]

    else:
        fipsets = client.list_floatingipsets().get("floatingipsets")

    formatted_fipsets = []
    for fipset in fipsets:
        created_at = utils.format_datetime(fipset["created_at"])
        status = utils.transform_status(fipset["status"])
        formatted_fipsets.append(
            FloatingIpSet(
                id=fipset["id"],
                name=fipset["uos:name"],
                size=fipset["rate_limit"],
                providers=fipset["uos:service_provider"],
                project_id=fipset["tenant_id"],
                project_name=project_name,
                resource_type=const.RESOURCE_FLOATINGIPSET,
                status=status,
                original_status=fipset["status"],
                created_at=created_at,
            )
        )

    return formatted_fipsets
Ejemplo n.º 8
0
def listener_list(project_id, region_name=None, project_name=None):
    client = get_neutronclient(region_name)
    if project_id:
        listeners = client.list_listeners(
            tenant_id=project_id).get('listeners')
    else:
        listeners = client.list_listeners().get('listeners')

    formatted_listeners = []
    for listener in listeners:
        status = utils.transform_status(listener['status'])
        admin_state = (const.STATE_RUNNING
                       if listener['admin_state_up'] else const.STATE_STOPPED)
        created_at = utils.format_datetime(
            listener.get('created_at', timeutils.strtime()))
        formatted_listeners.append(
            Listener(id=listener['id'],
                     name=listener['name'],
                     admin_state_up=listener['admin_state_up'],
                     admin_state=admin_state,
                     connection_limit=listener['connection_limit'],
                     project_id=listener['tenant_id'],
                     project_name=project_name,
                     resource_type=const.RESOURCE_LISTENER,
                     status=status,
                     original_status=listener['status'],
                     created_at=created_at))

    return formatted_listeners
Ejemplo n.º 9
0
def server_list(project_id, region_name=None, detailed=True, project_name=None):
    search_opts = {'all_tenants': 1,
                   'project_id': project_id}
    servers = get_novaclient(region_name).servers.list(detailed, search_opts)
    formatted_servers = []
    for server in servers:
        flavor = flavor_get(region_name, server.flavor['id'])
        image = image_get(region_name, server.image['id'])
        created_at = utils.format_datetime(server.created)
        status = utils.transform_status(server.status)
        formatted_servers.append(Server(id=server.id,
                                        name=server.name,
                                        flavor_name=flavor.name,
                                        flavor_id=flavor.id,
                                        disk_gb=getattr(image, "OS-EXT-IMG-SIZE:size") / (1024 * 1024 * 1024),
                                        image_name=image.name,
                                        image_id=image.id,
                                        status=status,
                                        original_status=server.status,
                                        resource_type=const.RESOURCE_INSTANCE,
                                        user_id=server.user_id,
                                        project_id=server.tenant_id,
                                        project_name=project_name,
                                        created_at=created_at))
    return formatted_servers
Ejemplo n.º 10
0
def listener_list(project_id, region_name=None, project_name=None):
    client = get_neutronclient(region_name)
    if project_id:
        listeners = client.list_listeners(tenant_id=project_id).get("listeners")
    else:
        listeners = client.list_listeners().get("listeners")

    formatted_listeners = []
    for listener in listeners:
        status = utils.transform_status(listener["status"])
        admin_state = const.STATE_RUNNING if listener["admin_state_up"] else const.STATE_STOPPED
        created_at = utils.format_datetime(listener.get("created_at", timeutils.strtime()))
        formatted_listeners.append(
            Listener(
                id=listener["id"],
                name=listener["name"],
                admin_state_up=listener["admin_state_up"],
                admin_state=admin_state,
                connection_limit=listener["connection_limit"],
                project_id=listener["tenant_id"],
                project_name=project_name,
                resource_type=const.RESOURCE_LISTENER,
                status=status,
                original_status=listener["status"],
                created_at=created_at,
            )
        )

    return formatted_listeners
Ejemplo n.º 11
0
def volume_list(project_id,
                region_name=None,
                detailed=True,
                project_name=None):
    """To see all volumes in the cloud as admin.
    """
    c_client = get_cinderclient(region_name)
    search_opts = {'all_tenants': 1, 'project_id': project_id}
    if c_client is None:
        return []
    volumes = c_client.volumes.list(detailed, search_opts=search_opts)
    formatted_volumes = []
    for volume in volumes:
        created_at = utils.format_datetime(volume.created_at)
        status = utils.transform_status(volume.status)
        formatted_volumes.append(
            Volume(id=volume.id,
                   name=volume.display_name,
                   size=volume.size,
                   status=status,
                   type=volume.volume_type,
                   original_status=volume.status,
                   resource_type=const.RESOURCE_VOLUME,
                   user_id=None,
                   project_id=project_id,
                   project_name=project_name,
                   attachments=volume.attachments,
                   created_at=created_at))
    return formatted_volumes
Ejemplo n.º 12
0
def listener_list(project_id, region_name=None, project_name=None):
    client = get_neutronclient(region_name)
    if project_id:
        listeners = client.list_listeners(
            tenant_id=project_id).get('listeners')
    else:
        listeners = client.list_listeners().get('listeners')

    formatted_listeners = []
    for listener in listeners:
        status = utils.transform_status(listener['status'])
        admin_state = (const.STATE_RUNNING
                       if listener['admin_state_up']
                       else const.STATE_STOPPED)
        created_at = utils.format_datetime(
            listener.get('created_at', timeutils.strtime()))
        formatted_listeners.append(
            Listener(id=listener['id'],
                     name=listener['name'],
                     admin_state_up=listener['admin_state_up'],
                     admin_state=admin_state,
                     connection_limit=listener['connection_limit'],
                     project_id=listener['tenant_id'],
                     project_name=project_name,
                     resource_type=const.RESOURCE_LISTENER,
                     status=status,
                     original_status=listener['status'],
                     created_at=created_at))

    return formatted_listeners
Ejemplo n.º 13
0
def server_get(instance_id, region_name=None):
    try:
        server = get_novaclient(region_name).servers.get(instance_id)
    except NotFound:
        return None
    status = utils.transform_status(server.status)
    return Server(id=server.id,
                  name=server.name,
                  status=status,
                  original_status=server.status,
                  resource_type=const.RESOURCE_INSTANCE)
Ejemplo n.º 14
0
def share_get(share_id, region_name=None):
    m_client = get_manilaclient(region_name)
    try:
        share = m_client.shares.get(share_id)
    except NotFound:
        return None
    status = utils.transform_status(share.status)
    return Share(id=share.id,
                 name=share.name,
                 status=status,
                 original_status=share.status,
                 resource_type=const.RESOURCE_SHARE)
Ejemplo n.º 15
0
def snapshot_get(snapshot_id, region_name=None):
    c_client = get_cinderclient(region_name)
    try:
        sp = c_client.volume_snapshots.get(snapshot_id)
    except NotFound:
        return None
    status = utils.transform_status(sp.status)
    return Snapshot(id=sp.id,
                    name=sp.display_name,
                    status=status,
                    original_status=sp.status,
                    resource_type=const.RESOURCE_SNAPSHOT)
Ejemplo n.º 16
0
def server_get(instance_id, region_name=None):
    try:
        server = get_novaclient(region_name).servers.get(instance_id)
    except NotFound:
        return None
    status = utils.transform_status(server.status)
    return Server(id=server.id,
                  name=server.name,
                  status=status,
                  original_status=server.status,
                  resource_type=const.RESOURCE_INSTANCE,
                  flavor=server.flavor)
Ejemplo n.º 17
0
def share_get(share_id, region_name=None):
    m_client = get_manilaclient(region_name)
    try:
        share = m_client.shares.get(share_id)
    except NotFound:
        return None
    status = utils.transform_status(share.status)
    return Share(id=share.id,
                 name=share.name,
                 status=status,
                 original_status=share.status,
                 resource_type=const.RESOURCE_SHARE)
Ejemplo n.º 18
0
def volume_get(volume_id, region_name=None):
    c_client = get_cinderclient(region_name)
    try:
        volume = c_client.volumes.get(volume_id)
    except NotFound:
        return None
    status = utils.transform_status(volume.status)
    return Volume(id=volume.id,
                  name=volume.display_name,
                  status=status,
                  original_status=volume.status,
                  resource_type=const.RESOURCE_VOLUME,
                  attachments=volume.attachments)
Ejemplo n.º 19
0
def snapshot_get(snapshot_id, region_name=None):
    c_client = get_cinderclient(region_name)
    try:
        sp = c_client.volume_snapshots.get(snapshot_id)
    except NotFound:
        return None
    status = utils.transform_status(sp.status)
    return Snapshot(id=sp.id,
                    name=sp.display_name,
                    size=sp.size,
                    status=status,
                    original_status=sp.status,
                    resource_type=const.RESOURCE_SNAPSHOT)
Ejemplo n.º 20
0
def image_get(image_id, region_name=None):
    try:
        image = get_glanceclient(region_name).images.get(image_id)
    except HTTPNotFound:
        return None
    except NotFound:
        return None
    status = utils.transform_status(image.status)
    return Image(id=image.id,
                 name=image.name,
                 image_label=image.get('image_label', 'default').lower(),
                 status=status,
                 original_status=image.status,
                 resource_type=const.RESOURCE_IMAGE)
Ejemplo n.º 21
0
def volume_get(volume_id, region_name=None):
    c_client = get_cinderclient(region_name)
    try:
        volume = c_client.volumes.get(volume_id)
    except NotFound:
        return None
    status = utils.transform_status(volume.status)
    return Volume(id=volume.id,
                  name=volume.display_name,
                  status=status,
                  original_status=volume.status,
                  resource_type=const.RESOURCE_VOLUME,
                  attachments=volume.attachments,
                  size=volume.size)
Ejemplo n.º 22
0
def network_list(project_id, region_name=None, project_name=None):
    client = get_neutronclient(region_name)
    networks = client.list_networks(tenant_id=project_id).get('networks')
    formatted_networks = []
    for network in networks:
        status = utils.transform_status(network['status'])
        formatted_networks.append(Network(id=network['id'],
                                          name=network['name'],
                                          is_bill=False,
                                          resource_type='network',
                                          status=status,
                                          project_id=network['tenant_id'],
                                          project_name=project_name,
                                          original_status=network['status']))
    return formatted_networks
Ejemplo n.º 23
0
def image_get(image_id, region_name=None):
    try:
        image = get_glanceclient(region_name).images.get(image_id)
    except HTTPNotFound:
        return None
    except NotFound:
        return None
    status = utils.transform_status(image.status)
    return Image(id=image.id,
                 name=image.name,
                 image_label=image.get('image_label', 'default').lower(),
                 status=status,
                 original_status=image.status,
                 resource_type=const.RESOURCE_IMAGE,
                 size=image.size)
Ejemplo n.º 24
0
def alarm_get(alarm_id, region_name=None):
    try:
        alarm = get_cmclient(region_name).alarms.get(alarm_id)
    except NotFound:
        return None

    # ceilometerclient will also return None if alarm doesn't exists
    if not alarm:
        return None

    status = utils.transform_status(str(alarm.enabled))
    return Alarm(id=alarm.alarm_id,
                 name=alarm.name,
                 status=status,
                 original_status=str(alarm.enabled),
                 resource_type=const.RESOURCE_ALARM)
Ejemplo n.º 25
0
def router_get(router_id, region_name=None):
    try:
        router = get_neutronclient(
            region_name).show_router(router_id).get('router')
    except exceptions.NotFound:
        return None
    except exceptions.NeutronException as e:
        if e.status_code == 404:
            return None
        raise e
    status = utils.transform_status(router['status'])
    return Router(id=router['id'],
                  name=router['name'],
                  resource_type=const.RESOURCE_ROUTER,
                  status=status,
                  original_status=router['status'])
Ejemplo n.º 26
0
def alarm_get(alarm_id, region_name=None):
    try:
        alarm = get_cmclient(region_name).alarms.get(alarm_id)
    except NotFound:
        return None

    # ceilometerclient will also return None if alarm doesn't exists
    if not alarm:
        return None

    status = utils.transform_status(str(alarm.enabled))
    return Alarm(id=alarm.alarm_id,
                 name=alarm.name,
                 status=status,
                 original_status=str(alarm.enabled),
                 resource_type=const.RESOURCE_ALARM)
Ejemplo n.º 27
0
def router_get(router_id, region_name=None):
    try:
        router = get_neutronclient(region_name).show_router(router_id).get(
            'router')
    except exceptions.NotFound:
        return None
    except exceptions.NeutronException as e:
        if e.status_code == 404:
            return None
        raise e
    status = utils.transform_status(router['status'])
    return Router(id=router['id'],
                  name=router['name'],
                  resource_type=const.RESOURCE_ROUTER,
                  status=status,
                  original_status=router['status'])
Ejemplo n.º 28
0
def network_list(project_id, region_name=None, project_name=None):
    client = get_neutronclient(region_name)
    networks = client.list_networks(tenant_id=project_id).get('networks')
    formatted_networks = []
    for network in networks:
        status = utils.transform_status(network['status'])
        formatted_networks.append(
            Network(id=network['id'],
                    name=network['name'],
                    is_bill=False,
                    resource_type='network',
                    status=status,
                    project_id=network['tenant_id'],
                    project_name=project_name,
                    original_status=network['status']))
    return formatted_networks
Ejemplo n.º 29
0
def image_list(project_id, region_name=None, project_name=None):
    filters = {'owner': project_id}
    images = get_glanceclient(region_name).images.list(filters=filters)
    formatted_images = []
    for image in images:
        created_at = utils.format_datetime(image.created_at)
        status = utils.transform_status(image.status)
        formatted_images.append(Image(id=image.id,
                                      name=getattr(image, 'name', None),
                                      size=getattr(image, 'size', 0),
                                      status=status,
                                      original_status=image.status,
                                      resource_type=const.RESOURCE_IMAGE,
                                      project_id=project_id,
                                      project_name=project_name,
                                      created_at=created_at))
    return formatted_images
Ejemplo n.º 30
0
def alarm_list(project_id, region_name=None, project_name=None):
    alarms = get_cmclient(region_name).alarms.list(q=[{'field': 'project_id',
                                                       'value': project_id}])
    formatted_alarms = []
    for alarm in alarms:
        created_at = utils.format_datetime(alarm.created_at)
        status = utils.transform_status(str(alarm.enabled))
        formatted_alarms.append(Alarm(id=alarm.alarm_id,
                                      name=alarm.name,
                                      status=status,
                                      original_status=str(alarm.enabled),
                                      resource_type=const.RESOURCE_ALARM,
                                      user_id=alarm.user_id,
                                      project_id=project_id,
                                      project_name=project_name,
                                      created_at=created_at))
    return formatted_alarms
Ejemplo n.º 31
0
def floatingip_get(fip_id, region_name=None):
    try:
        fip = get_neutronclient(region_name).show_floatingip(fip_id).get(
            'floatingip')
    except exceptions.NotFound:
        return None
    except exceptions.NeutronException as e:
        if e.status_code == 404:
            return None
        raise e
    status = utils.transform_status(fip['status'])
    return FloatingIp(id=fip['id'],
                      name=fip['uos:name'],
                      providers=fip['uos:service_provider'],
                      resource_type=const.RESOURCE_FLOATINGIP,
                      status=status,
                      original_status=fip['status'],
                      is_reserved=True)
Ejemplo n.º 32
0
def floatingip_get(fip_id, region_name=None):
    try:
        fip = get_neutronclient(
            region_name).show_floatingip(fip_id).get('floatingip')
    except exceptions.NotFound:
        return None
    except exceptions.NeutronException as e:
        if e.status_code == 404:
            return None
        raise e
    status = utils.transform_status(fip['status'])
    return FloatingIp(id=fip['id'],
                      name=fip['uos:name'],
                      providers=fip['uos:service_provider'],
                      resource_type=const.RESOURCE_FLOATINGIP,
                      status=status,
                      original_status=fip['status'],
                      is_reserved=True)
Ejemplo n.º 33
0
def router_list(project_id, region_name=None, project_name=None):
    client = get_neutronclient(region_name)
    if project_id:
        routers = client.list_routers(tenant_id=project_id).get('routers')
    else:
        routers = client.list_routers().get('routers')
    formatted_routers = []
    for router in routers:
        created_at = utils.format_datetime(router['created_at'])
        status = utils.transform_status(router['status'])
        formatted_routers.append(Router(id=router['id'],
                                        name=router['name'],
                                        project_id=router['tenant_id'],
                                        project_name=project_name,
                                        resource_type=const.RESOURCE_ROUTER,
                                        status=status,
                                        original_status=router['status'],
                                        created_at=created_at))
    return formatted_routers
Ejemplo n.º 34
0
def network_list(project_id, region_name=None, project_name=None):
    client = get_neutronclient(region_name)
    networks = client.list_networks(tenant_id=project_id).get("networks")
    formatted_networks = []
    for network in networks:
        status = utils.transform_status(network["status"])
        formatted_networks.append(
            Network(
                id=network["id"],
                name=network["name"],
                is_bill=False,
                resource_type="network",
                status=status,
                project_id=network["tenant_id"],
                project_name=project_name,
                original_status=network["status"],
            )
        )
    return formatted_networks
Ejemplo n.º 35
0
def alarm_list(project_id, region_name=None, project_name=None):
    alarms = get_cmclient(region_name).alarms.list(q=[{
        'field': 'project_id',
        'value': project_id
    }])
    formatted_alarms = []
    for alarm in alarms:
        created_at = utils.format_datetime(alarm.created_at)
        status = utils.transform_status(str(alarm.enabled))
        formatted_alarms.append(
            Alarm(id=alarm.alarm_id,
                  name=alarm.name,
                  status=status,
                  original_status=str(alarm.enabled),
                  resource_type=const.RESOURCE_ALARM,
                  user_id=alarm.user_id,
                  project_id=project_id,
                  project_name=project_name,
                  created_at=created_at))
    return formatted_alarms
Ejemplo n.º 36
0
def router_list(project_id, region_name=None, project_name=None):
    client = get_neutronclient(region_name)
    if project_id:
        routers = client.list_routers(tenant_id=project_id).get('routers')
    else:
        routers = client.list_routers().get('routers')
    formatted_routers = []
    for router in routers:
        created_at = utils.format_datetime(router['created_at'])
        status = utils.transform_status(router['status'])
        formatted_routers.append(
            Router(id=router['id'],
                   name=router['name'],
                   project_id=router['tenant_id'],
                   project_name=project_name,
                   resource_type=const.RESOURCE_ROUTER,
                   status=status,
                   original_status=router['status'],
                   created_at=created_at))
    return formatted_routers
Ejemplo n.º 37
0
def floatingipset_get(fipset_id, region_name=None):
    try:
        client = get_neutronclient(region_name)
        fipset = client.show_floatingipset(fipset_id).get("floatingipset")
    except (exceptions.NotFound):
        return None
    except (exceptions.NeutronException) as e:
        if e.status_code == 404:
            return None
        raise e

    status = utils.transform_status(fipset["status"])
    return FloatingIpSet(
        id=fipset["id"],
        name=fipset["uos:name"],
        providers=fipset["uos:service_provider"],
        resource_type=const.RESOURCE_FLOATINGIPSET,
        status=status,
        original_status=fipset["status"],
        is_reserved=True,
    )
Ejemplo n.º 38
0
def port_list(project_id, region_name=None, device_id=None, project_name=None):
    client = get_neutronclient(region_name)
    if device_id:
        ports = client.list_ports(tenant_id=project_id,
                                  device_id=device_id).get('ports')
    else:
        ports = client.list_ports(tenant_id=project_id).get('ports')

    formatted_ports = []
    for port in ports:
        status = utils.transform_status(port['status'])
        formatted_ports.append(Port(id=port['id'],
                                    name=port['name'],
                                    is_bill=False,
                                    resource_type='port',
                                    status=status,
                                    project_id=port['tenant_id'],
                                    project_name=project_name,
                                    original_status=port['status']))

    return formatted_ports
Ejemplo n.º 39
0
def port_list(project_id, region_name=None, device_id=None, project_name=None):
    client = get_neutronclient(region_name)
    if device_id:
        ports = client.list_ports(tenant_id=project_id,
                                  device_id=device_id).get('ports')
    else:
        ports = client.list_ports(tenant_id=project_id).get('ports')

    formatted_ports = []
    for port in ports:
        status = utils.transform_status(port['status'])
        formatted_ports.append(
            Port(id=port['id'],
                 name=port['name'],
                 is_bill=False,
                 resource_type='port',
                 status=status,
                 project_id=port['tenant_id'],
                 project_name=project_name,
                 original_status=port['status']))

    return formatted_ports
Ejemplo n.º 40
0
def share_list(project_id, region_name=None, detailed=True, project_name=None):
    """To see all shares in the cloud as admin.
    """
    m_client = get_manilaclient(region_name)
    search_opts = {'all_tenants': 1, 'project_id': project_id}
    shares = m_client.shares.list(detailed, search_opts=search_opts)
    formatted_shares = []
    for share in shares:
        created_at = utils.format_datetime(share.created_at)
        status = utils.transform_status(share.status)
        formatted_shares.append(
            Share(id=share.id,
                  name=share.name,
                  size=share.size,
                  volume_type=share.volume_type,
                  status=status,
                  original_status=share.status,
                  resource_type=const.RESOURCE_SHARE,
                  user_id=None,
                  project_id=project_id,
                  project_name=project_name,
                  created_at=created_at))
    return formatted_shares
Ejemplo n.º 41
0
def share_list(project_id, region_name=None, detailed=True, project_name=None):
    """To see all shares in the cloud as admin.
    """
    m_client = get_manilaclient(region_name)
    search_opts = {'all_tenants': 1,
                   'project_id': project_id}
    shares = m_client.shares.list(detailed, search_opts=search_opts)
    formatted_shares = []
    for share in shares:
        created_at = utils.format_datetime(share.created_at)
        status = utils.transform_status(share.status)
        formatted_shares.append(Share(id=share.id,
                                      name=share.name,
                                      size=share.size,
                                      volume_type=share.volume_type,
                                      status=status,
                                      original_status=share.status,
                                      resource_type=const.RESOURCE_SHARE,
                                      user_id = None,
                                      project_id = project_id,
                                      project_name=project_name,
                                      created_at=created_at))
    return formatted_shares
Ejemplo n.º 42
0
def port_list(project_id, region_name=None, device_id=None, project_name=None):
    client = get_neutronclient(region_name)
    if device_id:
        ports = client.list_ports(tenant_id=project_id, device_id=device_id).get("ports")
    else:
        ports = client.list_ports(tenant_id=project_id).get("ports")

    formatted_ports = []
    for port in ports:
        status = utils.transform_status(port["status"])
        formatted_ports.append(
            Port(
                id=port["id"],
                name=port["name"],
                is_bill=False,
                resource_type="port",
                status=status,
                project_id=port["tenant_id"],
                project_name=project_name,
                original_status=port["status"],
            )
        )

    return formatted_ports
Ejemplo n.º 43
0
def listener_get(listener_id, region_name=None):
    client = get_neutronclient(region_name)
    try:
        listener = client.show_listener(listener_id).get('listener')
    except exceptions.NotFound:
        return None
    except exceptions.NeutronException as e:
        if e.status_code == 404:
            return None
        raise e

    is_last_up = _is_last_up_listener(client, listener['loadbalancer_id'],
                                      listener_id)
    status = utils.transform_status(listener['status'])
    admin_state = (const.STATE_RUNNING
                   if listener['admin_state_up'] else const.STATE_STOPPED)

    return Listener(id=listener['id'],
                    name=listener['name'],
                    resource_type=const.RESOURCE_LISTENER,
                    status=status,
                    admin_state=admin_state,
                    is_last_up=is_last_up,
                    original_status=listener['status'])