How to use asynchronously subnet id in pulumi which is know after 'VirtualNetwork' object created? - pulumi

How to correctly use 'apply' in order to build 'ip_configurations' list using subnet id known after virtual network created ? Below gives AttributeError: 'VirtualNetwork' object has no attribute 'subnet_id'
virtual_network = azure.network.VirtualNetwork(vnet_name, name=vnet_name, resource_group_name=resource_group.name,
address_spaces=test_vnet['addr'], subnets=test_vnet['subnets'], location=resource_group.location)
ip_configurations = [{ "name": "ip-cfg", "subnet_id": virtual_network.subnet_id.apply(lambda subnet_id: virtual_network.subnets[0].id),
"privateIpAddressAllocation": "Dynamic" }]

First of all, I recommend you using a separate Subnet resource, e.g
vnet = network.VirtualNetwork(
vnet_name,
resource_group_name=resource_group.name,
address_spaces=["10.0.0.0/16"])
subnet = network.Subnet(
"subnet",
resource_group_name=resource_group.name,
address_prefix="10.0.2.0/24",
virtual_network_name=vnet.name,
enforce_private_link_endpoint_network_policies="false")
# subnet.id
You can find an example here.
If you define subnets inside VirtualNetwork, you can access ID by looking at the id property of the first item in subnets output (virtual_network.subnets[0].id).

Related

AnyLogic: cast OptionList into AgentType with List

At model startup I manually instantiate each instance of my resource with parameters. Parameters are name, capacities, required number of employees and ResourceType. The ResourceType of each Resource is taken from an OptionList.
At the end of the simulation I want to retrieve data for each resource for a data extract. Since I don't want to query all resources manually and individually, I want to iterate through the different resources.
Should look like:
for (ResourceType rt : Resources) {
// export in excel
}
But for that I would have to create a list with all resources filled with ResourceType (OptionList). Is there a way to cast an OptionList to an AgentType within a List? The end product should be something like: Resources.listOfAllResources filled with the enums.
You need to loop through your OptionList entries and find all resources of that type:
for (int i=0; i<myOptionList.values().length; i++) {
myOptionList currentEntry = myOptionList.values()[i];
findAll(myResourcesInAList, r->r.getType().equals(currentEntry));
}

cdk: Importing the output of an unrelated different stack

Context:
I am making a new stack using cdk. This stack will use a vpc id that is an Output from a different stack in the same account, one which is not generated by cdk.
I am looking for the cdk equivalent of
Fn::ImportValue: ExportedName
in order to create a VPC in cdk which can then have resources attached to it.
I will then use that output to look up the VPC:
Vpc.fromVpcAttributes(this, "MyImportedVPC", VpcAttributes.builder()
.withVpcId(importedValue).build());
All the references I can find to importing values with cdk are about importing (or rather, not having to manually import) values defined in a stack which is also created by cdk. Am I missing something?
I was looking for Fn.importValue:
Fn.importValue("ExportedName")
List<String> availabilityZones = java.util.stream.Stream
.of("us-west-2a", "us-west-2b", "us-west-2c")
.collect(toList());
String privateSubnet1 = Fn.importValue("PrivateSubnet01");
String privateSubnet2 = Fn.importValue("PrivateSubnet02");
String privateSubnet3 = Fn.importValue("PrivateSubnet03");
List<String> privateSubnets = java.util.stream.Stream
.of(privateSubnet1, privateSubnet2, privateSubnet3)
.collect(toList());
VpcAttributes byId = VpcAttributes.builder()
.withVpcId(vpcId)
.withAvailabilityZones(availabilityZones)
.withPrivateSubnetIds(privateSubnets)
.build();
return Vpc.fromVpcAttributes(this, "ImportedVpc", byId);

Drupal 8 - how to get exposed filters value in preprocess_views_view

I'm using preprocess_views_view to define some new variables and pass them to a twig template.
In order to define these variables I need to access the exposed filters input values, but I can't seem to figure out how:
function my_modules_preprocess_views_view(&$variables) {
$view = $variables['view'];
// Here I would need to access the exposed filters value
$exposed_filter_value = "the_value";
$variables["foo"] = "Something based on the exposed filters value";
}
I would be very grateful for any clues - cheers!
In a hook_preprocess_views_view() implementation in your theme or module:
$values = $view->getExposedInput();
// for example $values["color"];
Or, you can access the values directly from the views-view.html.twig template:
// Assuming `color` is configured to be the Filter identifier in the
// view's Filter Criteria exposed filter.
{{ view.getExposedInput.color }}
I had problems with #Hubert's solution and managed to get it to work with:
$variables["searchInputValue"] = $view->exposed_raw_input['query'];

Fetch all the values of specific property in aem using queryBuilder

I am having scenario in which i want to fetch all the values of a property under a specific path in AEM using QueryBuilder api.
This property can have single or multivalued.
Any help will be appreciated!!
Example that can help you. is below as it is just for illustration written in simple JSP scriptlets
<%
Iterator<Resource> iter = resourceResolver.findResources("/jcr:root/content/geometrixx-outdoors//element(*, nt:unstructured)[(#imageRotate = '0' or #imageRotate = '1')]","xpath");
while (iter.hasNext()) {
Resource child = iter.next();
out.println("</br>"+child.getPath());
Node node = child.adaptTo(Node.class);
Property nProp = node.getProperty("imageRotate");
if(nProp.isMultiple()) // This condition checks for properties whose type is String[](String array)
{
Value[] values = nProp.getValues();
out.println(" :: This is a multi valued property ::");
for (Value v : values) {
out.println("</br>"+"Property Name = "+nProp.getName()+" ; Property Value= "+v.getString());
}
}
else if(!nProp.getDefinition().isMultiple()){
out.println("</br>"+"Property Name = "+nProp.getName()+" ; Property Value= "+nProp.getString());
}
}
%>
Here i have used the Iterator<Resource> iter = resourceResolver.findResources(query,"xpath"); which can give you the query results which matches the imageRotate property under /content/geometrixx-outdoors/ path which consists combination of single and multivalued as shown in below screenshot.
There is no direct way to fetch the properties using query builder api. I would suggest you to create a servlet resource, which requires a path and property name.
Fetch the jcr node using the given path via QueryBuilder. Then, you need to loop through the results to check the property of the nodes. You can access the multiple property values, once you have a node.

Create OpportunityProduct using REST

I'm trying to create a new OpportunityProduct using this rest call:
XRMServices/2011/OrganizationData.svc/OpportunityProductSet
{"ProductId":"ef71ce8e-1ef3-e211-b252-984be17c47e4","Quantity":123,"ProductDescription":"Added from code - TEST123","OpportunityId":"8bdb3525-7274-e311-a90b-6c3be5be5f78"}
The call returns:
The request should be a valid top-level resource object.
This indicates that my arguments is not correct. I see to possible reasons for this:
I'm missing some required properties (How can I figure out which is required?)
It is not possible to do using rest
(both guids are returned via other call and should be correct)
Any help would be great!
Thanks
Larsi
For lookup references to other entities you need to specify both the GUID and the type. You also need to include the UOM when creating an Opportunity Product based on an existing Product. Your object should look something like this:
var entity = {};
entity.Quantity = parseFloat(4).toFixed(2);
entity.OpportunityId = {
Id: '69BB2236-B57F-E311-BB6D-6C3BE5A881A4',
LogicalName: 'opportunity'
};
entity.ProductId = {
Id: 'C8138483-DF81-E311-B542-6C3BE5A8362C',
LogicalName: 'product'
};
entity.UoMId = {
Id: 'BE0FB859-7E90-4B3E-B501-3AB3CD4DC8FC',
LogicalName: 'uom'
};