class AssociateIPForm(forms.Form): """ the form for creating a SecurityGroup """ floating_ip_id = forms.CharField(widget=forms.HiddenInput()) floating_ip = forms.CharField(label=_("Floating IP"), widget=forms.TextInput( attrs={'readonly': 'readonly'})) instance_id = forms.ChoiceField(label=_("Instance ID")) def __init__(self, request, ip_id, *args, **kwargs): self.request = request self.ip_id = ip_id super(AssociateIPForm, self).__init__(*args, **kwargs) # ip_id = int(ip_id) try: ip_obj = api.tenant_floating_ip_get(self.request, ip_id) except Exception, ex: msg = 'Unable to associate floating IP. The error is %s' % ex LOG.error(msg) self.fields['floating_ip_id'].initial = ip_id self.fields['floating_ip'].initial = ip_obj.ip try: servers = api.server_list(self.request) except Unauthorized: raise except Exception, ex: msg = 'Unable to retrieve instance list. The error is %s' % ex LOG.error(msg)
def attach_volume_form(request, tenant_id, volume_id): instances = [] try: if switch_tenants(request, tenant_id): instance_list = api.server_list(request) for instance in instance_list: if instance.status in ACTIVE_STATES: instances.append((instance.id, '%s' % instance.name)) except Unauthorized: raise except Exception, ex: instances = [] LOG.error("Can not get instance list %s" % ex)
def get_floating_ips_list(request , tenant_id): """ :param request:request object,tenant_id :return:view<'virtual_address_manage/floatingIpsIndex.html'>::list of floatingIp """ args = {} floating_ips = [] floating_pool = {} floatingips = [] try: if None != switch_tenants(request , tenant_id): floating_ips = api.network.tenant_floating_ip_list(request) floating_pools = api.network.floating_ip_pools_list(request) floating_pool = SortedDict([(pool.id , pool.name) for pool in floating_pools]) for floating_ip in floating_ips: if tenant_id == floating_ip.tenant_id : floating_ip._apidict['pool'] = floating_pool.get(floating_ip.pool, get_text("invalid ip pool")) floatingips.append(floating_ip) instances = [] tenant_quota = api.nova.nova_tenant_quota_get(request , tenant_id) for item in tenant_quota: if item.name == "floating_ips": ip_num = item.limit servers = api.server_list(request) for server in servers: # to be removed when nova can support unique names server_name = server.name if any(s.id != server.id and s.name == server.name for s in servers): # duplicate instance name server_name = "%s [%s]" % (server.name, server.id) instances.append((server.id , server_name)) except Unauthorized: raise except Exception , exe: LOG.exception("ClientException in floating ip index,the error is %s " % exe.message)
def get_floating_ips_list(request, tenant_id): """ :param request:request object,tenant_id :return:view<'virtual_address_manage/floatingIpsIndex.html'>::list of floatingIp """ args = {} floating_ips = [] floating_pool = {} floatingips = [] try: if None != switch_tenants(request, tenant_id): floating_ips = api.network.tenant_floating_ip_list(request) floating_pools = api.network.floating_ip_pools_list(request) floating_pool = SortedDict([(pool.id, pool.name) for pool in floating_pools]) for floating_ip in floating_ips: if tenant_id == floating_ip.tenant_id: floating_ip._apidict['pool'] = floating_pool.get( floating_ip.pool, get_text("invalid ip pool")) floatingips.append(floating_ip) instances = [] tenant_quota = api.nova.nova_tenant_quota_get(request, tenant_id) for item in tenant_quota: if item.name == "floating_ips": ip_num = item.limit servers = api.server_list(request) for server in servers: # to be removed when nova can support unique names server_name = server.name if any(s.id != server.id and s.name == server.name for s in servers): # duplicate instance name server_name = "%s [%s]" % (server.name, server.id) instances.append((server.id, server_name)) except Unauthorized: raise except Exception, exe: LOG.exception("ClientException in floating ip index,the error is %s " % exe.message)
def get_project_summary(request): project_summary = {} INSTANCE_ON_STATUS = ('active', ) try: projects = api.tenant_list(request, admin=True) for project in projects: if not project.enabled: continue users = api.user_list(request, project.id) networks = api.network_list_for_tenant(request, project.id) instance_on_cnt = 0 instance_off_cnt = 0 instances = [] if switch_tenants(request, project.id): instances = api.server_list(request) for instance in instances: if instance.status.lower() in INSTANCE_ON_STATUS: instance_on_cnt += 1 else: instance_off_cnt += 1 summary = { 'project_name': project.name, 'user_cnt': len(users), 'network_cnt': len(networks), 'instance_on_cnt': instance_on_cnt, 'instance_off_cnt': instance_off_cnt } project_summary[project.id] = summary except Unauthorized: raise except Exception, e: LOG.error(e)
if floating.ip == floating_ip: floating_ips = floating break if floating_pool: floating_ips._apidict['pool'] = floating_pool.get(floating_ips.pool, get_text("invalid ip pool")) except Unauthorized: raise except Exception , exe: LOG.exception("ClientException in floating ip index,the error is %s" % exe.message) instances = [] servers = [] try: servers = api.server_list(request) except Unauthorized: raise except Exception , exe: LOG.error('Unable to retrieve instance list.the error is %s ' % exe.message) for server in servers: # to be removed when nova can support unique names server_name = server.name if any(s.id != server.id and s.name == server.name for s in servers): # duplicate instance name server_name = "%s [%s]" % (server.name, server.id) instances.append((server.id , server_name)) return shortcuts.render(request, 'virtual_address_manage/floatingIpsIndex_ip.html', {"floatingIp":floating_ips, "tenant_id":tenant_id, "instances":instances})
floating_ips = floating break if floating_pool: floating_ips._apidict['pool'] = floating_pool.get( floating_ips.pool, get_text("invalid ip pool")) except Unauthorized: raise except Exception, exe: LOG.exception("ClientException in floating ip index,the error is %s" % exe.message) instances = [] servers = [] try: servers = api.server_list(request) except Unauthorized: raise except Exception, exe: LOG.error('Unable to retrieve instance list.the error is %s ' % exe.message) for server in servers: # to be removed when nova can support unique names server_name = server.name if any(s.id != server.id and s.name == server.name for s in servers): # duplicate instance name server_name = "%s [%s]" % (server.name, server.id) instances.append((server.id, server_name)) return shortcuts.render(request, 'virtual_address_manage/floatingIpsIndex_ip.html',
def get_authorized_instances(request, tenant_id): instances = None if switch_tenants(request, tenant_id): instances = server_list(request) return instances