Extract Returned values from 'VirtualNetworkPeering object - azure-sdk-python

How Can I extract the atrribute values returned from list of peered virtual networks.
I executed this command and I need to extract the Network ID
list_all = network_client.virtual_network_peerings.list(
GROUP_NAME,
VNET_NAME
)
for peer in list_all:
print(peer)
and I get this value for from the print above:
{'additional_properties': {'type': 'Microsoft.Network/virtualNetworks/virtualNetworkPeerings'},
'id': '/subscriptions/c70b9b-efd6-497d-98d8-e1e1d497425/resourceGroups/azure-sample-group-virtual-machines/providers/Microsoft.Network/virtualNetworks/azure-sample-vnet/virtualNetworkPeerings/sample-vnetpeer',
'allow_virtual_network_access': True,
'allow_forwarded_traffic': True,
'allow_gateway_transit': False,
'use_remote_gateways': False,
'remote_virtual_network': <azure.mgmt.network.v2018_08_01.models.sub_resource_py3.SubResource object at 0x048D6950>,
'remote_address_space': <azure.mgmt.network.v2018_08_01.models.address_space_py3.AddressSpace object at 0x048D68D0>,
'peering_state': 'Initiated',
'provisioning_state': 'Succeeded',
'name': 'sample-vnetpeer',
'etag': 'W/"653f7f94-3c4e-4275-bfdf-0bbbd9beb6e4"'}
How can I get this value "remote_virtual_network"?

My feeling is that your question is actually more a Python question than an Azure question. Assuming in your application this field is set with values, then remote_virtual_network is a SubResource meaning it only has one attribute: id
for peer in list_all:
remote_virtual_network_id = peer.remote_virtual_network.id
This guy is an actual virtual network, so if you want details about it you need to get it with network_client.virtual_networks.get:
https://learn.microsoft.com/en-us/python/api/azure-mgmt-network/azure.mgmt.network.v2018_08_01.operations.virtualnetworksoperations?view=azure-python#get
The tricky part is you get an ID, but VNet get asks for a RG name and VNet name, you can use the ARM ID parser for that:
https://learn.microsoft.com/en-us/python/api/msrestazure/msrestazure.tools?view=azure-python#parse-resource-id

'remote_virtual_network': ,
'remote_address_space':
I will try this out and get back:
This command is analogous to "get-azurermvirtualnetworkpeering -ResourceGroupName -VirtualNetworkName -Name" on Azure PowerShell.
remote_virtual_network you don't have one. You will only get this if you have Remote Gateway enabled and the Peer will learn the IP address of the Remote (On-premise site) that you are trying to connect.
To get this value, deploy a gateway in the Vnet and connect it to Say "Vnet-S2S-test" with a gateway deployed there as well.
Once, the Site-to-site between the Vnets are up. You can execute the command and you should see those fields populated with the local network gateway details.

Related

Configure subnetwork for vertex ai pipeline component

I have a vertex ai pipeline component that needs to connect to a database. This database exists in a VPC network. Currently my component is failing because it is not able to connect to the database, but I believe I can get it to work if I can configure the component to use the subnetwork.
How do I configure the workerPoolSpecs of the component to use the subnetwork?
I was hoping I could do something like that:
preprocess_data_op = component_store.load_component('org/ml_engine/preprocess')
#dsl.pipeline(name="test-pipeline-vertex-ai")
def pipeline(project_id: str, some_param: str):
preprocess_data_op(
project_id=project_id,
my_param=some_param,
subnetwork_uri="projects/xxxxxxxxx/global/networks/data",
).set_display_name("Preprocess data")
However the param is not there, and i get
TypeError: Preprocess() got an unexpected keyword argument 'subnetwork_uri'
How do I define the subnetwork for the component?
From Google docs, There is no mention of how you can run a specific component on a subnetwork.
However, it is possible to run the entire pipeline in a subnetwork by passing in the subnetwork as part of the job submit api.
job.submit(service_account=SERVICE_ACCOUNT, network=NETWORK)

Error creating ElasticSearch domain using Terraform - Exactly one subnet needed

I may have come across some conflicting docs today.
When creating an Elastic Search domain with vpc options, the HashiCorp Terraform official docs (https://www.terraform.io/docs/providers/aws/r/elasticsearch_domain.html) say that the subnets is a list and even specify 2 subnets in their example. However when I specify 2 subnets I get an error (I tried 2 different ways of specifying the subnets list) -
vpc_options {
subnet_ids = "${var.private_subnet_ids}"
OR
subnet_ids = [
"${var.private_subnet_ids[0]}",
"${var.private_subnet_ids[1]}"
]
Both of them give me the same error -
Error: Error creating ElasticSearch domain: ValidationException: You must specify exactly one subnet.
status code: 400, request id: 98b49b34-2da8-11ea-8114-e9488cc7cb63
on modules/es/main.tf line 51, in resource "aws_elasticsearch_domain" "es":
51: resource "aws_elasticsearch_domain" "es" {
If I specify a single subnet, it works fine.
subnet_ids = ["${var.private_subnet_ids[0]}"]
I do however want to be able to specify both of my private subnets for the ES cluster.
Is there a way to do that ? I noticed a couple issues on github for this but the resolution was what was in the Terraform docs and that does not work for me. I am using v0.12.17 in case it matters.
variable private_subnet_ids is a list
variable "private_subnet_ids" {
type = "list"
description = "The list of private subnets to place the instances in"
}
The original AWS documentation (https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-vpc.html) explains the structure behind the Terraform behavior. Each ES Domain can only connect to one subnet if it resides in a single Availability Zone. If you have Multi_AZ mode enabled in ES, you can supply a second subnet, which then must be in the other AZ that the ES cluster spans as well.

how to get an aws instance given I have the instance's ip

Given I have an aws instance IP, how can I get the EC2 instance collection object via the ruby aws-sdk's filter option. For example
#ec2.instances.filter(valid_filter_name, ec2_instance_ip)
I've tried 'public_ip_address' and 'public_ip' as the filter name but those didn't work. I'm using this API doc http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/FilteredCollection.html#filter-instance_method, but it's does not mentioned what the valid parameters are.
It turns out the correct parameter to use (by trial & error) is 'ip-address'. Here's an example:
#ec2.instances.filter('ip-address', ec2_instance_ip)

C# Active Directory Query sAMAccountname returning array of numbers instead of String

I have a really strange thing happening on my site and I cant figure it out.
I have an auto complete box that queries an LDAP connection. The connection works fine and I get responses from the LDAP Query. BUT, here is where the problems start.
On my local machine, I get the response:
[{"label":"TestUser, Bill","value":"Testuesr, Bill","AdLogon":"bill.testuser"}]
but on my server I get the response:
[{"label":"TestUser, Bill","value":"Testuesr, Bill","AdLogon":[67,111,108,109,95,67]}]
Does anyone have any ideas what could be starting this?
Update
If I change the AppPool from AppPoolIdentity to NetworkService then it returns the proper values.
"67,111,108,109,95,67" is the integer array for "Colm_C", It's so becaise of the special catacter '_' . If think that an underlying layer need to transform sAMAccountName in a B64 string and it's then given back as an array.

Ruby calling AWS ELB functions

I'm writing some Ruby scripts to wrap AWS ELB command line calls, mostly so that I can act on several ELB instances simultaneously. One task is to use the elb-describe-instance-health call to see what instance IDs are attached to this ELB.
I want to match the Instance ID to a nickname we have set up for those instances, so that I can see at a glance what machines area connected to the ELB, without having to look up the instance names.
So I am issuing:
cmd = "elb-describe-instance-health #{elbName}"
value = `#{cmd}`
Passing the elb name into the call. This returns output such as:
INSTANCE_ID i-jfjtktykg InService N/A N/A
INSTANCE_ID i-ujelforos InService N/A N/A
One line appear for each instance in the ELB. There are two spaces between each field.
What I need to get is the second field, which is the actual instance ID. Basically I'm trying to get each line returned, turn it into an array, get the 2nd field, which I can then use to lookup our server nickname.
Not sure if this is the right approach, but any suggestions on how to get this done are very welcome.
The newly released aws-sdk gem supports Elastic Load Balancing (AWS::ELB). If you want to get a list of instance ids attached to your load balancer you can do the following:
AWS.config(:access_key_id => '...', :secret_access_key => '...')
elb = AWS::ELB.new
intsance_ids = elb.load_balancers['LOAD_BALANCER_NAME'].instances.collect(&:id)
You could also use EC2 to store your instance nicknames.
ec2 = AWS::EC2.new
ec2.instances['INSTANCE_ID'].tags['nickname'] = 'NICKNAME'
Assuming your instances are tagged with their nicknames, you could collect them like so:
elb = AWS::ELB.new
elb.load_balancers['LOAD_BALANCER_NAME'].instances.collect{|i| i.tags['nickname'] }
A simple way to extract the second column would be something like this:
ids = value.split("\n").collect { |line| line.split(/\s+/)[1] }
This will leave the second column values in the Array ids. All this does is breaks the value into lines, breaks each line into whitespace delimited columns, and then extracts the second column.
There's probably no need to try to be too clever for something like this, a simple and straight forward solution should be sufficient.
References:
collect
split

Resources