MCPcopy Create free account
hub / github.com/crc-org/crc-cloud / runFunc

Method runFunc

pkg/provider/openstack/create-instance.go:62–172  ·  view source on GitHub ↗
(ctx *pulumi.Context)

Source from the content-addressed store, hash-verified

60}
61
62func (r createRequest) runFunc(ctx *pulumi.Context) error {
63 privateKey, err := crctls.CreateKey(ctx)
64 if err != nil {
65 return err
66 }
67
68 // Check if provided network exists
69 _, err = networking.LookupNetwork(ctx, &networking.LookupNetworkArgs{
70 Name: pulumi.StringRef(r.networkName)}, nil)
71 if err != nil {
72 return fmt.Errorf("provided %s network does not exist. Err: %v", r.networkName, err)
73 }
74
75 // Create the security group for the instance
76 secGroup, err := networking.NewSecGroup(ctx, r.projectName, &networking.SecGroupArgs{
77 Description: pulumi.String("My neutron security group"),
78 })
79 if err != nil {
80 return err
81 }
82
83 // Define an array of the ports to allow
84 ports := []int{constants.HTTPPort, constants.HTTPSPort, constants.APIPort, constants.SSHPort}
85
86 // Iterate over the ports and create a security group rule for each
87 for _, port := range ports {
88 _, err := networking.NewSecGroupRule(ctx, fmt.Sprintf("secgroupRule%d", port), &networking.SecGroupRuleArgs{
89 Direction: pulumi.String("ingress"),
90 Ethertype: pulumi.String("IPv4"),
91 SecurityGroupId: secGroup.ID(),
92 PortRangeMin: pulumi.Int(port),
93 PortRangeMax: pulumi.Int(port),
94 Protocol: pulumi.String("tcp"),
95 RemoteIpPrefix: pulumi.String("0.0.0.0/0"),
96 })
97 if err != nil {
98 return err
99 }
100 }
101
102 imageRef, err := images.LookupImage(ctx, &images.LookupImageArgs{Name: pulumi.StringRef(r.imageID)}, nil)
103 if err != nil {
104 return err
105 }
106
107 vol, err := blockstorage.NewVolume(ctx, "myVolume", &blockstorage.VolumeArgs{
108 Size: pulumi.Int(r.diskSize), // Size of the volume in GB
109 AvailabilityZone: pulumi.String("nova"), // The Availability Zone in which to create the volume
110 ImageId: pulumi.String(imageRef.Id),
111 })
112 if err != nil {
113 return err
114 }
115
116 args := compute.InstanceArgs{
117 FlavorName: pulumi.String(r.instanceType),
118 //ImageName: pulumi.String(r.imageID),
119 SecurityGroups: pulumi.StringArray{

Callers

nothing calls this directly

Calls 3

CreatePasswordFunction · 0.92
SwapKeysFunction · 0.92
SetupFunction · 0.92

Tested by

no test coverage detected