Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request update/250114 #518

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion insider/insider_api/controllers/flavor.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ def get_azure_prices(self, region, instance_family, currency='USD',

def get_azure_locations(self):
location_map = self.azure.location_map
return {v: k for k, v in location_map.items()}
result = {v: k for k, v in location_map.items()}
result.update(self.azure.alias_location_map())
return result

def get_azure_flavors(self):
return self.azure.get_flavors_info()
Expand Down Expand Up @@ -221,6 +223,8 @@ def find_azure_flavor(self, region, family_specs, mode,
flavor = flavors_info.get(p['armSkuName'])
if not flavor:
continue
if mode != "current" and "Promo" in flavor:
continue
product_name = p['productName']
# according to azure pricing api we have 'windows'
# in productName as os type, and don't have it for others
Expand Down
22 changes: 14 additions & 8 deletions ngui/ui/src/components/PoolLabel/PoolLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
import Link from "@mui/material/Link";
import { FormattedMessage } from "react-intl";
import { useNavigate } from "react-router-dom";
import IconLabel from "components/IconLabel";
import PoolTypeIcon from "components/PoolTypeIcon";
import SlicedText from "components/SlicedText";
import { useUpdateScope } from "hooks/useUpdateScope";
import { getPoolUrl, isPoolIdWithSubPools } from "urls";
import { formQueryString } from "utils/network";

const SLICED_POOL_NAME_LENGTH = 35;

const getUrl = (poolId: string, organizationId: string) => {
const getUrl = (poolId: string) => {
// TODO: remove this after https://datatrendstech.atlassian.net/browse/OS-4157
const poolIdWithoutSubPoolMark = isPoolIdWithSubPools(poolId) ? poolId.slice(0, poolId.length - 1) : poolId;
const baseUrl = getPoolUrl(poolIdWithoutSubPoolMark);
return organizationId ? `${baseUrl}&${formQueryString({ organizationId })}` : baseUrl;

return getPoolUrl(poolIdWithoutSubPoolMark);
};

const SlicedPoolName = ({ name }) => <SlicedText limit={SLICED_POOL_NAME_LENGTH} text={name} />;

const PoolLink = ({ id, name, dataTestId, organizationId }) => {
const updateScope = useUpdateScope();
const navigate = useNavigate();

return (
<Link
component="button"
onClick={() => {
updateScope({
newScopeId: organizationId,
redirectTo: getUrl(id, organizationId)
});
const url = getUrl(id);
if (organizationId) {
updateScope({
newScopeId: organizationId,
redirectTo: url
});
} else {
navigate(url);
}
}}
data-test-id={dataTestId}
>
Expand Down
5 changes: 3 additions & 2 deletions ngui/ui/src/hooks/coreData/useCurrentEmployee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { useOrganizationInfo } from "../useOrganizationInfo";
export const useCurrentEmployee = () => {
const { organizationId } = useOrganizationInfo();

const { data: { currentEmployee = {} } = {} } = useQuery(GET_CURRENT_EMPLOYEE, {
const { data } = useQuery(GET_CURRENT_EMPLOYEE, {
variables: {
organizationId
},
fetchPolicy: "cache-only"
});

return currentEmployee;
// The current user is not always returned by the API in some corner test cases
return data?.currentEmployee ?? {};
};
83 changes: 30 additions & 53 deletions tools/cloud_adapter/clouds/azure.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timezone, timedelta
import enum
import logging
import re
import time
from requests.models import Request
from urllib.parse import urlencode
Expand Down Expand Up @@ -367,22 +368,6 @@ def _get_vm_status(self, server_id):
return None
return self._extract_server_status(server.instance_view)

def _extract_public_ip_ids(self, nic_object):
public_ip_ids = [conf.public_ip_address.id
for conf in nic_object.ip_configurations
if conf.public_ip_address]
return public_ip_ids

def _extract_server_ips(self, server_object):
public_ip_ids = []
for nic in server_object.network_profile.network_interfaces:
nic_info = self._parse_azure_id(nic.id)
nic = self.network.network_interfaces.get(
nic_info['group_name'], nic_info['name'],
expand='ipConfigurations/publicIPAddress')
public_ip_ids.extend(self._extract_public_ip_ids(nic))
return public_ip_ids

def _parse_azure_id(self, azure_id):
azure_id_parts = azure_id.split('/')
return {
Expand Down Expand Up @@ -757,48 +742,35 @@ def bucket_discovery_calls(self):
return [(self.discover_bucket_resources, ())]

def discover_ip_address_resources(self):
vms = {}
vm_ids = [vm.id for vm in
list(self.compute.virtual_machines.list_all())]
for vm_id in vm_ids:
try:
vm_parsed_id = self._parse_azure_id(vm_id)
vm = self.compute.virtual_machines.get(
vm_parsed_id['group_name'], vm_parsed_id['name'],
expand=InstanceViewTypes.instance_view)
ip_address_ids = self._extract_server_ips(vm)
for ip_address_id in ip_address_ids:
vms[ip_address_id] = {}
vms[ip_address_id]['status'] = self._extract_server_status(
vm.instance_view)
vms[ip_address_id]['vm_id'] = vm_id
except ResourceNotFound:
continue
lbs = {}
load_balancers = self.network.load_balancers.list_all()
for lb in load_balancers:
for ip_cfg in lb.frontend_ip_configurations:
if not ip_cfg.public_ip_address:
continue
lbs[ip_cfg.public_ip_address.id] = lb.id
gateways = {}
app_gateways = self.network.application_gateways.list_all()
for app_gateway in app_gateways:
for ip_cfg in app_gateway.frontend_ip_configurations:
if not ip_cfg.public_ip_address:
continue
gateways[ip_cfg.public_ip_address.id] = app_gateway.id
all_ip_addresses = list(self.network.public_ip_addresses.list_all())
for public_ip_address in all_ip_addresses:
tags = public_ip_address.tags or {}
public_ip_id = public_ip_address.id
cloud_console_link = self._generate_cloud_link(public_ip_id)
vm = vms.get(public_ip_id, {})
lb = lbs.get(public_ip_id)
gateway = gateways.get(public_ip_id)
vm_id = vm.get('vm_id') or lb or gateway
available = (vm.get('status') is None and lb is None and
gateway is None)
ip_config = public_ip_address.ip_configuration
available = True
vm_id = None
if ip_config:
available = False
attached_id = public_ip_address.ip_configuration.id
pattern = r"[A-Za-z0-9.\/_\-]*\/[A-Za-z0-9.\/_\-]*ipconfigurations"
id_ = re.match(pattern, attached_id, re.IGNORECASE)
if id_:
info = self._parse_azure_id(id_[0].rsplit('/', 1)[0])
vm_id = info.get('azure_id')
# get vm by nic
if 'networkinterfaces' in vm_id.lower():
nic = self.network.network_interfaces.get(
info['group_name'], info['name'],
expand='ipConfigurations/publicIPAddress')
if nic and nic.virtual_machine:
vm_id = self._parse_azure_id(
nic.virtual_machine.id).get('azure_id')
else:
# ip is attached to nic that is not attached to
# any instance
available = True

resource = IpAddressResource(
cloud_account_id=self.cloud_account_id,
organization_id=self.organization_id,
Expand Down Expand Up @@ -1173,6 +1145,11 @@ def _get_coordinates_map(self):
'longitude': -112.074036, 'latitude': 33.448376},
}

def alias_location_map(self):
coord_map = self._get_coordinates_map()
return {v['alias']: k for k, v in coord_map.items()
if 'alias' in v}

def get_regions_coordinates(self):
def to_coord(coordinate):
if isinstance(coordinate, str):
Expand Down
Loading